diff --git a/src/main/java/com/tiki/server/timeblock/controller/TimeBlockController.java b/src/main/java/com/tiki/server/timeblock/controller/TimeBlockController.java index 83eae518..61cfafb1 100644 --- a/src/main/java/com/tiki/server/timeblock/controller/TimeBlockController.java +++ b/src/main/java/com/tiki/server/timeblock/controller/TimeBlockController.java @@ -5,7 +5,9 @@ import static com.tiki.server.timeblock.message.SuccessMessage.SUCCESS_GET_ALL_TIME_BLOCK; import static com.tiki.server.timeblock.message.SuccessMessage.SUCCESS_GET_TIMELINE; import static com.tiki.server.timeblock.message.SuccessMessage.SUCCESS_GET_TIME_BLOCK_DETAIL; +import static com.tiki.server.timeblock.message.SuccessMessage.SUCCESS_UPDATE_TIME_BLOCK; +import com.tiki.server.timeblock.dto.request.TimeBlockUpdateRequest; import com.tiki.server.timeblock.service.dto.response.AllTimeBlockServiceResponse; import java.security.Principal; import java.util.List; @@ -13,6 +15,7 @@ import org.springframework.http.HttpStatus; import org.springframework.web.bind.annotation.DeleteMapping; import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.PatchMapping; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.PostMapping; import org.springframework.web.bind.annotation.RequestBody; @@ -91,6 +94,20 @@ public SuccessResponse getTimeBlockDetail( return SuccessResponse.success(SUCCESS_GET_TIME_BLOCK_DETAIL.getMessage(), response); } + @Override + @ResponseStatus(HttpStatus.OK) + @PatchMapping("/teams/{teamId}/time-block/{timeBlockId}") + public SuccessResponse updateTimeBlock( + final Principal principal, + @PathVariable final long teamId, + @PathVariable final long timeBlockId, + @RequestBody final TimeBlockUpdateRequest request + ) { + long memberId = Long.parseLong(principal.getName()); + timeBlockService.updateTimeBlock(memberId, teamId, timeBlockId, request); + return SuccessResponse.success(SUCCESS_UPDATE_TIME_BLOCK.getMessage()); + } + @Override @ResponseStatus(HttpStatus.NO_CONTENT) @DeleteMapping("/teams/{teamId}/time-block/{timeBlockId}") diff --git a/src/main/java/com/tiki/server/timeblock/controller/docs/TimeBlockControllerDocs.java b/src/main/java/com/tiki/server/timeblock/controller/docs/TimeBlockControllerDocs.java index 01ea743b..66547316 100644 --- a/src/main/java/com/tiki/server/timeblock/controller/docs/TimeBlockControllerDocs.java +++ b/src/main/java/com/tiki/server/timeblock/controller/docs/TimeBlockControllerDocs.java @@ -1,5 +1,6 @@ package com.tiki.server.timeblock.controller.docs; +import com.tiki.server.timeblock.dto.request.TimeBlockUpdateRequest; import com.tiki.server.timeblock.service.dto.response.AllTimeBlockServiceResponse; import java.security.Principal; import java.util.List; @@ -195,6 +196,48 @@ SuccessResponse getTimeBlockDetail( @PathVariable final long timeBlockId ); + @Operation( + summary = "타임 블록 정보 수정", + description = "타임 블록 정보를 수정한다.", + responses = { + @ApiResponse(responseCode = "200", description = "성공"), + @ApiResponse( + responseCode = "403", + description = "접근 권한 없음", + content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + @ApiResponse( + responseCode = "404", + description = "팀에 존재하지 않는 회원, 유효하지 않은 타임 블록", + content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + @ApiResponse( + responseCode = "4xx", + description = "클라이언트(요청) 오류", + content = @Content(schema = @Schema(implementation = ErrorResponse.class))), + @ApiResponse( + responseCode = "500", + description = "서버 내부 오류", + content = @Content(schema = @Schema(implementation = ErrorResponse.class)))} + ) + SuccessResponse updateTimeBlock( + @Parameter(hidden = true) final Principal principal, + @Parameter( + name = "teamId", + description = "팀 id", + in = ParameterIn.PATH, + example = "1" + ) + @PathVariable final long teamId, + @Parameter( + name = "timeBlockId", + description = "타임 블록 id", + in = ParameterIn.PATH, + example = "1" + ) + @PathVariable final long timeBlockId, + @RequestBody final TimeBlockUpdateRequest request + + ); + @Operation( summary = "타임 블록 삭제", description = "타임 블록을 삭제한다.", diff --git a/src/main/java/com/tiki/server/timeblock/dto/request/TimeBlockUpdateRequest.java b/src/main/java/com/tiki/server/timeblock/dto/request/TimeBlockUpdateRequest.java new file mode 100644 index 00000000..761ca742 --- /dev/null +++ b/src/main/java/com/tiki/server/timeblock/dto/request/TimeBlockUpdateRequest.java @@ -0,0 +1,12 @@ +package com.tiki.server.timeblock.dto.request; + +import java.time.LocalDate; + +import jakarta.validation.constraints.NotNull; + +public record TimeBlockUpdateRequest( + @NotNull String name, + @NotNull LocalDate startDate, + @NotNull LocalDate endDate +) { +} diff --git a/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java b/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java index e4ed1b63..cd54d010 100644 --- a/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java +++ b/src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java @@ -11,6 +11,7 @@ import com.tiki.server.common.entity.Position; import com.tiki.server.team.entity.Team; import com.tiki.server.timeblock.dto.request.TimeBlockCreateRequest; +import com.tiki.server.timeblock.dto.request.TimeBlockUpdateRequest; import jakarta.persistence.Column; import jakarta.persistence.Entity; @@ -69,4 +70,10 @@ public static TimeBlock of(final Team team, final Position accessiblePosition, .type(request.blockType()) .build(); } + + public void updateNameAndDate(final TimeBlockUpdateRequest request) { + this.name = request.name(); + this.startDate = request.startDate(); + this.endDate = request.endDate(); + } } diff --git a/src/main/java/com/tiki/server/timeblock/message/SuccessMessage.java b/src/main/java/com/tiki/server/timeblock/message/SuccessMessage.java index 2e7b01b7..2eadc1b1 100644 --- a/src/main/java/com/tiki/server/timeblock/message/SuccessMessage.java +++ b/src/main/java/com/tiki/server/timeblock/message/SuccessMessage.java @@ -11,6 +11,7 @@ public enum SuccessMessage { SUCCESS_GET_TIMELINE("타임라인 조회 성공"), SUCCESS_GET_ALL_TIME_BLOCK("전체 타임블록 조회 성공"), SUCCESS_GET_TIME_BLOCK_DETAIL("타임 블록 상세 정보 조회 성공"), + SUCCESS_UPDATE_TIME_BLOCK("타임 블록 정보 수정 성공"), SUCCESS_CREATE_DOCUMENT_TAG("파일 태그 성공"); private final String message; diff --git a/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java b/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java index 60d03ab4..a5d1082a 100644 --- a/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java +++ b/src/main/java/com/tiki/server/timeblock/service/TimeBlockService.java @@ -1,5 +1,6 @@ package com.tiki.server.timeblock.service; +import com.tiki.server.timeblock.dto.request.TimeBlockUpdateRequest; import com.tiki.server.timeblock.service.dto.response.AllTimeBlockServiceResponse; import java.util.List; @@ -101,6 +102,19 @@ public TimeBlockDetailGetResponse getTimeBlockDetail( return TimeBlockDetailGetResponse.from(documents, notes); } + @Transactional + public void updateTimeBlock( + final long memberId, + final long teamId, + final long timeBlockId, + final TimeBlockUpdateRequest request + ) { + MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId); + TimeBlock timeBlock = timeBlockFinder.findByIdAndTeamId(timeBlockId, teamId); + memberTeamManager.checkMemberAccessible(timeBlock.getAccessiblePosition()); + timeBlock.updateNameAndDate(request); + } + @Transactional public void deleteTimeBlock(final long memberId, final long teamId, final long timeBlockId) { MemberTeamManager memberTeamManager = memberTeamManagerFinder.findByMemberIdAndTeamId(memberId, teamId);