Skip to content

Commit

Permalink
✨ Feat : 우편함 수정 API (#83)
Browse files Browse the repository at this point in the history
  • Loading branch information
euunrud authored Jan 29, 2024
1 parent 3d785e9 commit 48b7294
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,32 @@ public LetterboxResponse getLetterboxById(Long letterboxId) {
return null;
}
}

@Transactional
public LetterboxResponse updateLetterbox(Long letterboxId, LetterboxRequest request) {
Letterbox letterbox = letterboxRepository.findById(letterboxId).orElse(null);

if (letterbox != null) {
if (request.getName() != null) {
letterbox.setName(request.getName());
}
if (request.getColor() != null) {
letterbox.setColor(request.getColor());
}
if (request.getEndDt() != null) {
letterbox.setEndDt(request.getEndDt());
}
if (request.getActivate() != null) {
letterbox.setActivate(request.getActivate());
}
if (request.getSender() != null) {
letterbox.setSender(request.getSender());
}

letterboxRepository.save(letterbox);
return letterbox.toResponse(letterbox);
} else {
return null;
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,4 +33,15 @@ public ApiResponse<LetterboxResponse> getLetterboxById(@PathVariable Long letter
return ApiResponse.onFailure(HttpStatus.INTERNAL_SERVER_ERROR.toString(), e.getMessage(), null);
}
}

@PatchMapping("/{letterboxId}")
@ApiOperation(value = "우편함 수정")
public ApiResponse<LetterboxResponse> updateLetterbox( @PathVariable Long letterboxId, @RequestBody LetterboxRequest request) {
LetterboxResponse updatedLbResponse = letterboxService.updateLetterbox(letterboxId, request);
try {
return ApiResponse.onSuccess(updatedLbResponse);
} catch (Exception e){
return ApiResponse.onFailure(HttpStatus.INTERNAL_SERVER_ERROR.toString(), e.getMessage(), null);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,14 @@

import java.time.LocalDateTime;

@Getter
public class LetterboxRequest {
private String name;
private String color;
private LocalDateTime endDt;
private Boolean activate;
private Boolean sender;

@Getter
private Long member_id;
public Letterbox toEntity() {
Letterbox letterbox = Letterbox.builder()
Expand Down

0 comments on commit 48b7294

Please sign in to comment.