Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#43 [feat] 중간회고 가져오기 #44

Merged
merged 2 commits into from
Sep 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public enum ErrorCode {
//404
NOT_FOUND_RESOURCE_EXCEPTION(HttpStatus.NOT_FOUND, "해당 자원을 찾을 수 없습니다."),
USER_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 유저는 존재하지 않습니다."),
KEYWORD_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 키워드는 존재하지 않습니다."),
MID_REVIEW_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 중간회고는 존재하지 않습니다."),
CAREER_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 커리어는 존재하지 않습니다."),
TODO_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 투두는 존재하지 않습니다"),
SCHEDULE_NOT_FOUND_EXCEPTION(HttpStatus.NOT_FOUND, "해당 ID의 지원 일정을 찾을 수 없습니다."),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ public enum SuccessCode {
TODO_TOGGLE_SUCCESS(HttpStatus.OK, "투두 토글 변경 성공입니다"),
SAVE_CAREER_SUCCESS(HttpStatus.CREATED, "커리어 등록 성공"),
GET_CAREER_DETAIL_SUCCESS(HttpStatus.OK, "커리어 상세 조회 성공"),
MID_REVIEW_GET_SUCCESS(HttpStatus.CREATED, "중간 전형 회고 가져오기 성공"),
MID_REVIEW_SAVE_SUCCESS(HttpStatus.CREATED, "중간 전형 회고 추가 성공"),
INT_REVIEW_SAVE_SUCCESS(HttpStatus.CREATED, "면접 회고 추가 성공"),
SELF_INTRO_SAVE_SUCCESS(HttpStatus.CREATED, "자기소개 추가 성공"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,12 @@
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.mid_review.dto.request.PostMidReviewRequest;
import com.example.letscareer.mid_review.dto.response.MidReviewDetailResponse;
import com.example.letscareer.mid_review.service.MidReviewService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;
Expand All @@ -16,6 +18,21 @@
public class MidReviewController {

private final MidReviewService midReviewService;
@GetMapping("/review/mid")
public ApiResponse getMidReview(
@RequestHeader("userId") Long userId,
@RequestParam Long scheduleId,
@RequestParam Long stageId,
@RequestParam Long midReviewId
){
try {
MidReviewDetailResponse midReviewDetailResponse = midReviewService.getMidReview(userId, scheduleId, stageId, midReviewId);
return SuccessResponse.success(SuccessCode.MID_REVIEW_GET_SUCCESS, midReviewDetailResponse);
} catch (NotFoundException | BadRequestException e) {
return ErrorResponse.error(e.getErrorCode());
}
}


@PostMapping("/schedules/{scheduleId}/stages/{stageId}/reviews/mid")
public ApiResponse postMidReview(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.example.letscareer.mid_review.dto.response;

import jakarta.persistence.Lob;

import java.time.LocalDate;

public record MidReviewDetailResponse(
String company,
String department,
String type,
LocalDate deadline,
@Lob
String freeReview,

@Lob
String goal
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface MidReviewRepository extends JpaRepository<MidReview, Long> {
Boolean existsByStage(Stage stage);
@Query("SELECT mr.midReviewId FROM MidReview mr WHERE mr.stage = :stage AND mr.user = :user")
Optional<Long> findMidReviewIdByStageAndUser(Stage stage, User user);

Optional<MidReview> findByMidReviewIdAndUser(Long midReviewId, User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.example.letscareer.int_review.repository.IntReviewRepository;
import com.example.letscareer.mid_review.domain.MidReview;
import com.example.letscareer.mid_review.dto.request.PostMidReviewRequest;
import com.example.letscareer.mid_review.dto.response.MidReviewDetailResponse;
import com.example.letscareer.mid_review.repository.MidReviewRepository;
import com.example.letscareer.schedule.domain.Schedule;
import com.example.letscareer.schedule.repository.ScheduleRepository;
Expand All @@ -28,6 +29,25 @@ public class MidReviewService {
private final StageRepository stageRepository;
private final UserRepository userRepository;

public MidReviewDetailResponse getMidReview(Long userId, Long scheduleId,Long stageId, Long midReviewId){
User user = userRepository.findByUserId(userId)
.orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION));
MidReview midReview = midReviewRepository.findByMidReviewIdAndUser(midReviewId, user)
.orElseThrow(()-> new NotFoundException(MID_REVIEW_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));
return new MidReviewDetailResponse(
schedule.getCompany(),
schedule.getDepartment(),
stage.getType().getValue(),
stage.getDate(),
midReview.getFreeReview(),
midReview.getGoal()
);
}

@Transactional
public void postMidReview(Long userId, Long scheduleId, Long stageId, PostMidReviewRequest request) {
User user = userRepository.findById(userId)
Expand Down
Loading