Skip to content

Commit

Permalink
Merge pull request #42 from LetsCareer-A/feat/#31
Browse files Browse the repository at this point in the history
  • Loading branch information
oosedus authored Sep 2, 2024
2 parents e25c155 + 8150690 commit 97a4448
Show file tree
Hide file tree
Showing 9 changed files with 141 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ public enum SuccessCode {
SCHEDULE_SUCCESS(HttpStatus.OK, "일정 찾기 성공입니다."),
POST_SCHEDULE_SUCCESS(HttpStatus.OK, "새 일정 추가 성공입니다."),
FAST_REVIEW_LIST_SUCEESS(HttpStatus.OK, "빠른 회고 리스트 찾기 성공입니다"),
REVIEW_LIST_SUCCESS(HttpStatus.OK,"회고 리스트 찾기 성공입니다"),
TODO_SUCCESS(HttpStatus.OK, "투두 찾기 성공입니다."),
TODO_SAVE_SUCCESS(HttpStatus.OK, "투두 저장 성공입니다"),
TODO_DELETE_SUCCESS(HttpStatus.OK, "투두 삭제 성공입니다"),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

import com.example.letscareer.int_review.domain.IntReview;
import com.example.letscareer.stage.domain.Stage;
import com.example.letscareer.user.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
public interface IntReviewRepository extends JpaRepository<IntReview, Long> {
Boolean existsByStage(Stage stage);
@Query("SELECT ir.intReviewId FROM IntReview ir WHERE ir.stage = :stage AND ir.user = :user")
Optional<Long> findIntReviewIdByStageAndUser(Stage stage, User user);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,16 @@

import com.example.letscareer.mid_review.domain.MidReview;
import com.example.letscareer.stage.domain.Stage;
import com.example.letscareer.user.domain.User;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.Optional;

@Repository
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);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,7 @@
import com.example.letscareer.common.exception.model.BadRequestException;
import com.example.letscareer.common.exception.model.NotFoundException;
import com.example.letscareer.schedule.dto.request.SchedulePostRequest;
import com.example.letscareer.schedule.dto.response.AlwaysResponse;
import com.example.letscareer.schedule.dto.response.DateClickScheduleResponse;
import com.example.letscareer.schedule.dto.response.FastReviewListResponse;
import com.example.letscareer.schedule.dto.response.ScheduleResponse;
import com.example.letscareer.schedule.dto.response.*;
import com.example.letscareer.schedule.service.ScheduleService;
import lombok.RequiredArgsConstructor;
import org.springframework.format.annotation.DateTimeFormat;
Expand Down Expand Up @@ -77,6 +74,19 @@ public ApiResponse getFastReviews(
return ErrorResponse.error(e.getErrorCode());
}
}
@GetMapping("/reviews/company")
public ApiResponse getCompanyReviews(
@RequestHeader("userId") Long userId,
@RequestParam("page") int page,
@RequestParam("size") int size) {

try {
CompanyReviewListResponse companyReviewListResponse = scheduleService.getCompanyReviewList(userId, page, size);
return SuccessResponse.success(SuccessCode.REVIEW_LIST_SUCCESS, companyReviewListResponse);
}catch (NotFoundException | BadRequestException e) {
return ErrorResponse.error(e.getErrorCode());
}
}

@PostMapping
public ApiResponse postNewSchedule(
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.example.letscareer.schedule.dto;

import java.util.List;
import java.util.Map;

public record CompanyReviewDTO(
String company,
List<CompanyReviewDetailDTO> interviewReviews, // 면접 리뷰
List<CompanyReviewDetailDTO> midtermReviews // 중간 리뷰
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.example.letscareer.schedule.dto;

import java.time.LocalDate;

public record CompanyReviewDetailDTO(
Long scheduleId,
Long stageId,
Long reviewId,
String department,
LocalDate deadline,
boolean isReviewed
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.example.letscareer.schedule.dto.response;

import com.example.letscareer.schedule.dto.CompanyReviewDTO;

import java.util.List;

public record CompanyReviewListResponse(
Integer page,
Integer size,
List<CompanyReviewDTO> companies
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,15 +5,9 @@
import com.example.letscareer.mid_review.repository.MidReviewRepository;
import com.example.letscareer.schedule.domain.Progress;
import com.example.letscareer.schedule.domain.Schedule;
import com.example.letscareer.schedule.dto.AlwaysDTO;
import com.example.letscareer.schedule.dto.DateScheduleDTO;
import com.example.letscareer.schedule.dto.FastDTO;
import com.example.letscareer.schedule.dto.StageDTO;
import com.example.letscareer.schedule.dto.*;
import com.example.letscareer.schedule.dto.request.SchedulePostRequest;
import com.example.letscareer.schedule.dto.response.AlwaysResponse;
import com.example.letscareer.schedule.dto.response.DateClickScheduleResponse;
import com.example.letscareer.schedule.dto.response.FastReviewListResponse;
import com.example.letscareer.schedule.dto.response.ScheduleResponse;
import com.example.letscareer.schedule.dto.response.*;
import com.example.letscareer.schedule.repository.ScheduleRepository;
import com.example.letscareer.stage.domain.Stage;
import com.example.letscareer.stage.domain.Status;
Expand All @@ -29,10 +23,7 @@

import java.time.LocalDate;
import java.time.Period;
import java.util.ArrayList;
import java.util.Comparator;
import java.util.List;
import java.util.Optional;
import java.util.*;

import static com.example.letscareer.common.exception.enums.ErrorCode.USER_NOT_FOUND_EXCEPTION;

Expand Down Expand Up @@ -234,6 +225,80 @@ public FastReviewListResponse getFastReviews(final Long userId, final int page,
fastReviews
);
}
public CompanyReviewListResponse getCompanyReviewList(final Long userId, final int page, final int size) {
Pageable pageable = PageRequest.of(page - 1, size); // JPA는 페이지 인덱스가 0부터 시작
User user = userRepository.findById(userId)
.orElseThrow(() -> new NotFoundException(USER_NOT_FOUND_EXCEPTION));
// 사용자 ID로 모든 Schedule 조회
Page<Schedule> schedulePage = scheduleRepository.findAllByUserUserId(userId, pageable);

// 기업별로 리뷰를 분류하기 위한 List
List<CompanyReviewDTO> companies = new ArrayList<>();

// 스케줄을 순회하면서 관련 스테이지와 회고 여부를 확인
for (Schedule schedule : schedulePage) {
String company = schedule.getCompany();

// 각 회사별 면접과 중간 리뷰 리스트 초기화
List<CompanyReviewDetailDTO> interviewReviews = new ArrayList<>();
List<CompanyReviewDetailDTO> midtermReviews = new ArrayList<>();

// 모든 Stage를 조회
List<Stage> stages = stageRepository.findAllBySchedule(schedule);

for (Stage stage : stages) {
String type = stage.getType().getValue(); // Stage의 type 필드
boolean isReviewed = false;
Long reviewId = null; // 리뷰 ID 초기화

if (type.equals("면접")) {
// INT 타입의 스테이지인 경우 IntReview만 확인
isReviewed = intReviewRepository.existsByStage(stage);
if (isReviewed) {
reviewId = intReviewRepository.findIntReviewIdByStageAndUser(stage, user).orElse(null); // 리뷰 ID 가져오기
}

// 면접 리뷰를 추가
CompanyReviewDetailDTO reviewDetail = new CompanyReviewDetailDTO(
schedule.getScheduleId(),
stage.getStageId(),
reviewId,
schedule.getDepartment(),
stage.getDate(),
isReviewed
);
interviewReviews.add(reviewDetail);

} else if (type.equals("중간")) {
// MID 타입의 스테이지인 경우 MidReview만 확인
isReviewed = midReviewRepository.existsByStage(stage);
if (isReviewed) {
reviewId = midReviewRepository.findMidReviewIdByStageAndUser(stage, user).orElse(null); // 리뷰 ID 가져오기
}

// 중간 리뷰를 추가
CompanyReviewDetailDTO reviewDetail = new CompanyReviewDetailDTO(
schedule.getScheduleId(),
stage.getStageId(),
reviewId,
schedule.getDepartment(),
stage.getDate(),
isReviewed
);
midtermReviews.add(reviewDetail);
}
}

// 기업별 리뷰 DTO 추가
companies.add(new CompanyReviewDTO(company, interviewReviews, midtermReviews));
}

return new CompanyReviewListResponse(
page,
size,
companies
);
}
@Transactional
public void postSchedule(Long userId,SchedulePostRequest request){
Optional<User> userOptional = userRepository.findByUserId(userId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,5 @@ public interface StageRepository extends JpaRepository<Stage, Long> {
Optional<Stage> findTopByScheduleScheduleIdOrderByOrderDesc(Long scheudleId);
List<Stage> findAllByScheduleAndDateBetween(Schedule schedule, LocalDate today, LocalDate threeDaysLater);
Optional<Stage> findByStageIdAndSchedule(Long stageId, Schedule schedule);
List<Stage> findAllBySchedule(Schedule schedule);
}

0 comments on commit 97a4448

Please sign in to comment.