Skip to content

Commit

Permalink
Merge pull request #52 from LetsCareer-A/feat/#51
Browse files Browse the repository at this point in the history
#51 [feat] 4.6 전형 단계별 상태 수정
  • Loading branch information
pkl0912 authored Sep 3, 2024
2 parents 6a92178 + 4c7b846 commit 9311270
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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());
}
}
}
Original file line number Diff line number Diff line change
@@ -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
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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
Expand All @@ -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()
Expand All @@ -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;
}

}

0 comments on commit 9311270

Please sign in to comment.