diff --git a/src/main/java/aromanticcat/umcproject/service/letterbox/LetterboxService.java b/src/main/java/aromanticcat/umcproject/service/letterbox/LetterboxService.java index f15e10f..c9a09ff 100644 --- a/src/main/java/aromanticcat/umcproject/service/letterbox/LetterboxService.java +++ b/src/main/java/aromanticcat/umcproject/service/letterbox/LetterboxService.java @@ -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; + } + } } diff --git a/src/main/java/aromanticcat/umcproject/web/controller/LetterboxController.java b/src/main/java/aromanticcat/umcproject/web/controller/LetterboxController.java index ed17304..1a55b55 100644 --- a/src/main/java/aromanticcat/umcproject/web/controller/LetterboxController.java +++ b/src/main/java/aromanticcat/umcproject/web/controller/LetterboxController.java @@ -33,4 +33,15 @@ public ApiResponse getLetterboxById(@PathVariable Long letter return ApiResponse.onFailure(HttpStatus.INTERNAL_SERVER_ERROR.toString(), e.getMessage(), null); } } + + @PatchMapping("/{letterboxId}") + @ApiOperation(value = "우편함 수정") + public ApiResponse 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); + } + } } \ No newline at end of file diff --git a/src/main/java/aromanticcat/umcproject/web/dto/LetterboxRequest.java b/src/main/java/aromanticcat/umcproject/web/dto/LetterboxRequest.java index 85f9715..002b186 100644 --- a/src/main/java/aromanticcat/umcproject/web/dto/LetterboxRequest.java +++ b/src/main/java/aromanticcat/umcproject/web/dto/LetterboxRequest.java @@ -6,6 +6,7 @@ import java.time.LocalDateTime; +@Getter public class LetterboxRequest { private String name; private String color; @@ -13,7 +14,6 @@ public class LetterboxRequest { private Boolean activate; private Boolean sender; - @Getter private Long member_id; public Letterbox toEntity() { Letterbox letterbox = Letterbox.builder()