diff --git a/src/main/java/com/example/letscareer/common/exception/enums/SuccessCode.java b/src/main/java/com/example/letscareer/common/exception/enums/SuccessCode.java index 46584c7..1fca655 100644 --- a/src/main/java/com/example/letscareer/common/exception/enums/SuccessCode.java +++ b/src/main/java/com/example/letscareer/common/exception/enums/SuccessCode.java @@ -25,7 +25,8 @@ public enum SuccessCode { INT_REVIEW_SAVE_SUCCESS(HttpStatus.CREATED, "면접 회고 추가 성공"), SELF_INTRO_SAVE_SUCCESS(HttpStatus.CREATED, "자기소개 추가 성공"), APPEAL_CAREERS_ADD_SUCCESS(HttpStatus.CREATED, "어필할 커리어 추가 성공"), - STAGE_ADD_SUCCESS(HttpStatus.CREATED, "전형 단계 추가 성공"); + STAGE_ADD_SUCCESS(HttpStatus.CREATED, "전형 단계 추가 성공"), + STAGE_UPDATE_SUCCESS(HttpStatus.OK, "전형 단계 상태 변경 성공"); private final HttpStatus httpStatus; private final String message; diff --git a/src/main/java/com/example/letscareer/stage/controller/StageController.java b/src/main/java/com/example/letscareer/stage/controller/StageController.java index f3c6102..3326034 100644 --- a/src/main/java/com/example/letscareer/stage/controller/StageController.java +++ b/src/main/java/com/example/letscareer/stage/controller/StageController.java @@ -2,11 +2,14 @@ import com.example.letscareer.common.dto.ApiResponse; import com.example.letscareer.common.dto.ErrorResponse; +import com.example.letscareer.common.dto.SuccessNonDataResponse; import com.example.letscareer.common.dto.SuccessResponse; import com.example.letscareer.common.exception.enums.SuccessCode; import com.example.letscareer.common.exception.model.BadRequestException; import com.example.letscareer.common.exception.model.NotFoundException; +import com.example.letscareer.common.exception.model.ValidationException; import com.example.letscareer.stage.dto.request.AddStageRequest; +import com.example.letscareer.stage.dto.request.UpdateStageStatusRequest; import com.example.letscareer.stage.dto.response.AddStageResponse; import com.example.letscareer.stage.service.StageService; import lombok.RequiredArgsConstructor; @@ -32,4 +35,19 @@ public ApiResponse addStage( return ErrorResponse.error(e.getErrorCode()); } } + + @PutMapping("/schedules/{scheduleId}/stages/{stageId}") + public ApiResponse updateStageStatus( + @RequestHeader("userId") Long userId, + @PathVariable Long scheduleId, + @PathVariable Long stageId, + @RequestBody UpdateStageStatusRequest request + ) { + try { + stageService.updateStageStatus(userId, scheduleId, stageId, request); + return SuccessNonDataResponse.success(SuccessCode.STAGE_UPDATE_SUCCESS); + } catch (NotFoundException | BadRequestException e) { + return ErrorResponse.error(e.getErrorCode()); + } + } } diff --git a/src/main/java/com/example/letscareer/stage/dto/request/UpdateStageStatusRequest.java b/src/main/java/com/example/letscareer/stage/dto/request/UpdateStageStatusRequest.java new file mode 100644 index 0000000..ae722b2 --- /dev/null +++ b/src/main/java/com/example/letscareer/stage/dto/request/UpdateStageStatusRequest.java @@ -0,0 +1,11 @@ +package com.example.letscareer.stage.dto.request; + +import com.example.letscareer.stage.domain.Status; +import jakarta.persistence.EnumType; +import jakarta.persistence.Enumerated; + +public record UpdateStageStatusRequest( + @Enumerated(EnumType.STRING) + Status status +) { +} diff --git a/src/main/java/com/example/letscareer/stage/service/StageService.java b/src/main/java/com/example/letscareer/stage/service/StageService.java index 9fca88c..a6ba234 100644 --- a/src/main/java/com/example/letscareer/stage/service/StageService.java +++ b/src/main/java/com/example/letscareer/stage/service/StageService.java @@ -6,8 +6,11 @@ import com.example.letscareer.stage.domain.Stage; import com.example.letscareer.stage.domain.Status; import com.example.letscareer.stage.dto.request.AddStageRequest; +import com.example.letscareer.stage.dto.request.UpdateStageStatusRequest; import com.example.letscareer.stage.dto.response.AddStageResponse; import com.example.letscareer.stage.repository.StageRepository; +import com.example.letscareer.user.domain.User; +import com.example.letscareer.user.repository.UserRepository; import jakarta.transaction.Transactional; import lombok.RequiredArgsConstructor; import org.springframework.beans.factory.annotation.Autowired; @@ -16,7 +19,7 @@ import java.time.LocalDate; import java.time.Period; -import static com.example.letscareer.common.exception.enums.ErrorCode.SCHEDULE_NOT_FOUND_EXCEPTION; +import static com.example.letscareer.common.exception.enums.ErrorCode.*; @Service @RequiredArgsConstructor @@ -25,10 +28,13 @@ public class StageService { @Autowired private final StageRepository stageRepository; private final ScheduleRepository scheduleRepository; + private final UserRepository userRepository; @Transactional public AddStageResponse addStage(Long userId, Long scheduleId, AddStageRequest request) { - Schedule schedule = scheduleRepository.findById(scheduleId) + User user = userRepository.findById(userId) + .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); + Schedule schedule = scheduleRepository.findByUserAndScheduleId(user, scheduleId) .orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION)); Stage stage = Stage.builder() @@ -54,9 +60,21 @@ public AddStageResponse addStage(Long userId, Long scheduleId, AddStageRequest r dday); } + @Transactional + public void updateStageStatus(Long userId, Long scheduleId, Long stageId, UpdateStageStatusRequest request) { + User user = userRepository.findById(userId) + .orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION)); + Schedule schedule = scheduleRepository.findByUserAndScheduleId(user, scheduleId) + .orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION)); + Stage stage = stageRepository.findByStageIdAndSchedule(stageId, schedule) + .orElseThrow(() -> new NotFoundException(STAGE_NOT_FOUND_EXCEPTION)); + + stage.setStatus(request.status()); + stageRepository.save(stage); + } + private int calculateDday(LocalDate deadline) { int dday = Period.between(LocalDate.now(), deadline).getDays(); return dday; } - }