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

#39 [feat] 4.11 어필할 커리어 등록 #41

Merged
merged 4 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
@@ -0,0 +1,34 @@
package com.example.letscareer.appealCareer.controller;

import com.example.letscareer.appealCareer.dto.request.AddAppealCareersRequest;
import com.example.letscareer.appealCareer.service.AppealCareerService;
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.exception.enums.SuccessCode;
import com.example.letscareer.common.exception.model.BadRequestException;
import com.example.letscareer.common.exception.model.NotFoundException;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
public class AppealCareerController {

private final AppealCareerService appealCareerService;

@PostMapping("/schedules/{scheduleId}/stages/{stageId}/career")
public ApiResponse addAppealCareers(
@RequestHeader("userId") Long userId,
@PathVariable Long scheduleId,
@PathVariable Long stageId,
@RequestBody AddAppealCareersRequest request
) {
try {
appealCareerService.addAppealCareer(userId, scheduleId, stageId, request);
return SuccessNonDataResponse.success(SuccessCode.APPEAL_CAREERS_ADD_SUCCESS);
} catch (NotFoundException | BadRequestException e) {
return ErrorResponse.error(e.getErrorCode());
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@ public class AppealCareer {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long appealCareerId;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "stageIdd")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "stageId")
private Stage stage;

@OneToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "careeId")
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "careerId")
private Career career;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.letscareer.appealCareer.dto.request;

import java.util.List;

public record AddAppealCareersRequest(
List<Long> careers
) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.example.letscareer.appealCareer.repository;

import com.example.letscareer.appealCareer.domain.AppealCareer;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface AppealCareerRepository extends JpaRepository<AppealCareer, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
package com.example.letscareer.appealCareer.service;

import com.example.letscareer.appealCareer.domain.AppealCareer;
import com.example.letscareer.appealCareer.dto.request.AddAppealCareersRequest;
import com.example.letscareer.appealCareer.repository.AppealCareerRepository;
import com.example.letscareer.career.repository.CareerRepository;
import com.example.letscareer.common.exception.model.NotFoundException;
import com.example.letscareer.schedule.domain.Schedule;
import com.example.letscareer.schedule.repository.ScheduleRepository;
import com.example.letscareer.stage.domain.Stage;
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;
import org.springframework.stereotype.Service;

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

@Service
@RequiredArgsConstructor
public class AppealCareerService {

@Autowired
private final AppealCareerRepository appealCareerRepository;
private final ScheduleRepository scheduleRepository;
private final StageRepository stageRepository;
private final UserRepository userRepository;
private final CareerRepository careerRepository;

@Transactional
public void addAppealCareer(Long userId, Long scheduleId, Long stageId, AddAppealCareersRequest 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));

request.careers().forEach(careerId -> {
careerRepository.findById(careerId).ifPresent(career -> {
appealCareerRepository.save(AppealCareer.builder()
.career(career)
.stage(stage)
.build());
});
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,8 @@ public enum SuccessCode {
GET_CAREER_DETAIL_SUCCESS(HttpStatus.OK, "커리어 상세 조회 성공"),
MID_REVIEW_SAVE_SUCCESS(HttpStatus.CREATED, "중간 전형 회고 추가 성공"),
INT_REVIEW_SAVE_SUCCESS(HttpStatus.CREATED, "면접 회고 추가 성공"),
SELF_INTRO_SAVE_SUCCESS(HttpStatus.CREATED, "자기소개 추가 성공");
SELF_INTRO_SAVE_SUCCESS(HttpStatus.CREATED, "자기소개 추가 성공"),
APPEAL_CAREERS_ADD_SUCCESS(HttpStatus.CREATED, "어필할 커리어 추가 성공");

private final HttpStatus httpStatus;
private final String message;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
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;
import org.springframework.stereotype.Service;
Expand All @@ -26,6 +27,7 @@ public class SelfIntroService {
private final StageRepository stageRepository;
private final UserRepository userRepository;

@Transactional
public void saveSelfIntro(Long userId, Long scheduleId, Long stageId, SaveSelfIntroRequest request) {
Schedule schedule = scheduleRepository.findById(scheduleId)
.orElseThrow(() -> new NotFoundException(SCHEDULE_NOT_FOUND_EXCEPTION));
Expand Down
Loading