Skip to content

Commit

Permalink
Merge pull request kahluaband#42 from woogieon8on/apply
Browse files Browse the repository at this point in the history
kahluaband#1 Refactor apply api
  • Loading branch information
woogieon8on authored Jul 28, 2024
2 parents a846ea2 + 3f713b8 commit 0295ddc
Show file tree
Hide file tree
Showing 6 changed files with 30 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,11 @@ public enum ErrorStatus implements BaseCode {
SESSION_UNAUTHORIZED(HttpStatus.UNAUTHORIZED, "UNAUTHORIZED", "유효하지 않은 세션입니다."),

// 티켓 에러
TICKET_NOT_FOUND(HttpStatus.NOT_FOUND, "TICKET NOT FOUND", "티켓을 찾을 수 없습니다.");
TICKET_NOT_FOUND(HttpStatus.NOT_FOUND, "TICKET NOT FOUND", "티켓을 찾을 수 없습니다."),

//지원하기 에러
ALREADY_EXIST_APPLICANT(HttpStatus.BAD_REQUEST, "ALREADY EXIST APPLICANT", "이미 존재하는 지원자입니다"),
APPLICANT_NOT_FOUND(HttpStatus.NOT_FOUND, "APPLICANT NOT FOUND", "존지해지 않는 지원자입니다.");

private final HttpStatus httpStatus;
private final String code;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package kahlua.KahluaProject.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import kahlua.KahluaProject.apipayload.ApiResponse;
import kahlua.KahluaProject.dto.apply.request.ApplyCreateRequest;
import kahlua.KahluaProject.dto.apply.response.ApplyCreateResponse;
Expand All @@ -8,6 +10,7 @@
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@Tag(name = "지원하기", description = "지원하기 관련 API")
@RestController
@RequiredArgsConstructor
@RequestMapping("/v1/apply")
Expand All @@ -16,14 +19,14 @@ public class ApplyController {
private final ApplyService applyService;

@PostMapping
public ApiResponse<ApplyCreateResponse> createApplyFrom(@RequestBody ApplyCreateRequest applyCreateRequest) {
ApplyCreateResponse applyCreateResponse = applyService.createApply(applyCreateRequest);
return ApiResponse.onSuccess(applyCreateResponse);
@Operation(summary = "지원자 생성", description = "지원서 양식에 맞추어 지원자를 생성합니다")
public ApiResponse<ApplyCreateResponse> createApplicant(@RequestBody ApplyCreateRequest applyCreateRequest) {
return ApiResponse.onSuccess(applyService.createApply(applyCreateRequest));
}

@GetMapping("/{applyId}")
public ApiResponse<ApplyGetResponse> viewApplyForm(@PathVariable Long applyId) {
ApplyGetResponse applyGetResponse = applyService.getApply(applyId);
return ApiResponse.onSuccess(applyGetResponse);
@Operation(summary = "지원자 조회", description = "지원 폼 아이디를 통해 지원자를 조회합니다")
public ApiResponse<ApplyGetResponse> getApplicant(@PathVariable Long applyId) {
return ApiResponse.onSuccess(applyService.getApply(applyId));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ApplyConverter {
public static Apply toApply(ApplyCreateRequest applyCreateRequest) {
return Apply.builder()
.name(applyCreateRequest.getName())
.phone_num(applyCreateRequest.getPhone_num())
.phoneNum(applyCreateRequest.getPhone_num())
.birth_date(applyCreateRequest.getBirth_date())
.gender(applyCreateRequest.getGender())
.address(applyCreateRequest.getAddress())
Expand All @@ -30,7 +30,7 @@ public static ApplyCreateResponse toApplyCreateResponse(Apply apply) {
return ApplyCreateResponse.builder()
.id(apply.getId())
.name(apply.getName())
.phone_num(apply.getPhone_num())
.phone_num(apply.getPhoneNum())
.birth_date(apply.getBirth_date())
.gender(apply.getGender())
.address(apply.getAddress())
Expand All @@ -50,7 +50,7 @@ public static ApplyGetResponse toApplyGetResponse(Apply apply) {
return ApplyGetResponse.builder()
.id(apply.getId())
.name(apply.getName())
.phone_num(apply.getPhone_num())
.phone_num(apply.getPhoneNum())
.birth_date(apply.getBirth_date())
.gender(apply.getGender())
.address(apply.getAddress())
Expand Down
5 changes: 4 additions & 1 deletion src/main/java/kahlua/KahluaProject/domain/apply/Apply.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ public class Apply extends BaseEntity{

private String name;

private String phone_num;
@Column(name = "phone_num")
private String phoneNum;

private String birth_date;

Expand All @@ -34,9 +35,11 @@ public class Apply extends BaseEntity{
private Major major;

@Enumerated(EnumType.STRING)
@Column(name = "first_preference")
private Preference firstPreference;

@Enumerated(EnumType.STRING)
@Column(name = "second_preference")
private Preference secondPreference;

private String experience_and_reason;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,5 @@ public interface ApplyRepository extends JpaRepository<Apply, Long> {

List<Apply> findAllByFirstPreference(Preference first_preference);
List<Apply> findAllBySecondPreference(Preference second_preference);
Boolean existsByPhoneNum(String phone_num);
}
12 changes: 8 additions & 4 deletions src/main/java/kahlua/KahluaProject/service/ApplyService.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public class ApplyService {
@Transactional
public ApplyCreateResponse createApply(ApplyCreateRequest applyCreateRequest) {

if(applyRepository.existsByPhoneNum(applyCreateRequest.getPhone_num())) {
throw new GeneralException(ErrorStatus.ALREADY_EXIST_APPLICANT);
}

Apply apply = ApplyConverter.toApply(applyCreateRequest);
applyRepository.save(apply);

Expand All @@ -39,7 +43,7 @@ public ApplyCreateResponse createApply(ApplyCreateRequest applyCreateRequest) {
public ApplyGetResponse getApply(Long applyId) {

Apply apply = applyRepository.findById(applyId)
.orElseThrow(() -> new GeneralException(ErrorStatus.SESSION_UNAUTHORIZED));
.orElseThrow(() -> new GeneralException(ErrorStatus.APPLICANT_NOT_FOUND));

ApplyGetResponse applyGetResponse = ApplyConverter.toApplyGetResponse(apply);
return applyGetResponse;
Expand All @@ -59,7 +63,7 @@ public ApplyListResponse getApplyList(User user) {
ApplyItemResponse applyItemResponse = ApplyItemResponse.builder()
.id(apply.getId())
.name(apply.getName())
.phone_num(apply.getPhone_num())
.phone_num(apply.getPhoneNum())
.birth_date(apply.getBirth_date())
.gender(apply.getGender())
.address(apply.getAddress())
Expand Down Expand Up @@ -94,7 +98,7 @@ public ApplyListResponse getApplyListByPreference(User user, Preference preferen
ApplyItemResponse applyItemResponse = ApplyItemResponse.builder()
.id(apply.getId())
.name(apply.getName())
.phone_num(apply.getPhone_num())
.phone_num(apply.getPhoneNum())
.birth_date(apply.getBirth_date())
.gender(apply.getGender())
.address(apply.getAddress())
Expand All @@ -110,7 +114,7 @@ public ApplyListResponse getApplyListByPreference(User user, Preference preferen
ApplyItemResponse applyItemResponse = ApplyItemResponse.builder()
.id(apply.getId())
.name(apply.getName())
.phone_num(apply.getPhone_num())
.phone_num(apply.getPhoneNum())
.birth_date(apply.getBirth_date())
.gender(apply.getGender())
.address(apply.getAddress())
Expand Down

0 comments on commit 0295ddc

Please sign in to comment.