Skip to content

Commit

Permalink
Merge pull request #232 from Team-Tiki/feat/#231-timeblock
Browse files Browse the repository at this point in the history
[FEAT] 타임블록 수정
  • Loading branch information
paragon0107 authored Jan 12, 2025
2 parents a6a6f78 + 0bd03af commit bf6cfef
Show file tree
Hide file tree
Showing 6 changed files with 94 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,17 @@
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;

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;
Expand Down Expand Up @@ -91,6 +94,20 @@ public SuccessResponse<TimeBlockDetailGetResponse> 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}")
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -195,6 +196,48 @@ SuccessResponse<TimeBlockDetailGetResponse> 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 = "타임 블록을 삭제한다.",
Expand Down
Original file line number Diff line number Diff line change
@@ -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
) {
}
7 changes: 7 additions & 0 deletions src/main/java/com/tiki/server/timeblock/entity/TimeBlock.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
@@ -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;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit bf6cfef

Please sign in to comment.