diff --git a/src/main/java/com/startlion/startlionserver/controller/ApplicationApi.java b/src/main/java/com/startlion/startlionserver/controller/ApplicationApi.java index 07a62ea..6632d32 100644 --- a/src/main/java/com/startlion/startlionserver/controller/ApplicationApi.java +++ b/src/main/java/com/startlion/startlionserver/controller/ApplicationApi.java @@ -6,6 +6,7 @@ import com.startlion.startlionserver.dto.request.application.ApplicationPage4Request; import com.startlion.startlionserver.dto.response.application.ApplicationGetResponse; import com.startlion.startlionserver.dto.response.application.ApplicationIdResponse; +import com.startlion.startlionserver.dto.response.application.ApplicationPage1Response; import com.startlion.startlionserver.dto.response.application.ApplicationsGetResponse; import io.swagger.v3.oas.annotations.Operation; import io.swagger.v3.oas.annotations.Parameter; @@ -21,9 +22,19 @@ @Tag(name = "[Application] 지원서 관련 API") public interface ApplicationApi { + @Operation(summary = "지원서 저장 API") + @ApiResponses( + value = { + @ApiResponse(responseCode = "200", description = "지원서 저장 성공"), + @ApiResponse(responseCode = "403", description = "권한 없음"), + @ApiResponse(responseCode = "404", description = "지원서 정보 없음") + } + ) + ResponseEntity createApplication( + @RequestBody ApplicationPage1Request request, + Principal principal); - - @Operation(summary = "지원서 저장하기 1페이지") + @Operation(summary = "지원서 업데이트 1페이지") @ApiResponses( value = { @ApiResponse(responseCode = "200", description = "지원서 저장하기 성공"), @@ -31,7 +42,7 @@ public interface ApplicationApi { @ApiResponse(responseCode = "404", description = "지원서 정보 없음") } ) - ResponseEntity createApplication( + ResponseEntity updateApplicationPage1( @PathVariable @Parameter(description = "지원서 ID") Long applicationId, @RequestBody ApplicationPage1Request request, Principal principal); @@ -43,7 +54,7 @@ ResponseEntity createApplication( @ApiResponse(responseCode = "404", description = "지원서 정보 없음") } ) - @Operation(summary = "지원서 저장하기 2페이지") + @Operation(summary = "지원서 업데이트 2페이지") ResponseEntity updateApplicationPage2(@PathVariable @Parameter(description = "지원서 ID") Long applicationId, @RequestBody ApplicationPage2Request request, Principal principal); @ApiResponses( @@ -53,7 +64,7 @@ ResponseEntity createApplication( @ApiResponse(responseCode = "404", description = "지원서 정보 없음") } ) - @Operation(summary = "지원서 저장하기 3페이지") + @Operation(summary = "지원서 업데이트 3페이지") ResponseEntity updateApplicationPage3(@PathVariable @Parameter(description = "지원서 ID") Long applicationId, @RequestBody ApplicationPage3Request request, Principal principal); @ApiResponses( @@ -64,7 +75,7 @@ ResponseEntity createApplication( } ) - @Operation(summary = "지원서 저장하기 4페이지 -> 제출") + @Operation(summary = "지원서 업데이트 4페이지") ResponseEntity updateApplicationPage4(@PathVariable @Parameter(description = "지원서 ID") Long applicationId, @RequestBody ApplicationPage4Request request, Principal principal); diff --git a/src/main/java/com/startlion/startlionserver/controller/ApplicationController.java b/src/main/java/com/startlion/startlionserver/controller/ApplicationController.java index 28c7280..53b69a5 100644 --- a/src/main/java/com/startlion/startlionserver/controller/ApplicationController.java +++ b/src/main/java/com/startlion/startlionserver/controller/ApplicationController.java @@ -4,9 +4,7 @@ import com.startlion.startlionserver.dto.request.application.ApplicationPage2Request; import com.startlion.startlionserver.dto.request.application.ApplicationPage3Request; import com.startlion.startlionserver.dto.request.application.ApplicationPage4Request; -import com.startlion.startlionserver.dto.response.application.ApplicationGetResponse; -import com.startlion.startlionserver.dto.response.application.ApplicationIdResponse; -import com.startlion.startlionserver.dto.response.application.ApplicationsGetResponse; +import com.startlion.startlionserver.dto.response.application.ApplicationPage1Response; import com.startlion.startlionserver.service.ApplicationCommandService; import com.startlion.startlionserver.service.ApplicationQueryService; import com.startlion.startlionserver.util.UserUtil; @@ -23,28 +21,35 @@ @RequiredArgsConstructor public class ApplicationController implements ApplicationApi { - private final ApplicationQueryService applicationQueryService; private final ApplicationCommandService applicationCommandService; + @Override + @PostMapping + public ResponseEntity createApplication( + @RequestBody ApplicationPage1Request request, + Principal principal) { + val response = applicationCommandService.createApplication(request, UserUtil.getUserId(principal)); + return ResponseEntity.ok(response); + } @Override - @PutMapping("{applicationId}") - public ResponseEntity createApplication( + @PatchMapping("{applicationId}") + public ResponseEntity updateApplicationPage1( @PathVariable @Parameter(description = "지원서 ID") Long applicationId, @RequestBody ApplicationPage1Request request, - Principal principal){ - val id = applicationCommandService.createApplication(request, UserUtil.getUserId(principal), applicationId); - ApplicationIdResponse response = new ApplicationIdResponse(id); - return ResponseEntity.ok(response); + Principal principal) { + applicationCommandService.updateApplicationPage1(applicationId, request, UserUtil.getUserId(principal)); + return ResponseEntity.noContent().build(); } + @Override @PatchMapping("/{applicationId}/page2") public ResponseEntity updateApplicationPage2( @PathVariable @Parameter(description = "지원서 ID") Long applicationId, @RequestBody ApplicationPage2Request request, - Principal principal){ + Principal principal) { applicationCommandService.updateApplicationPage2(applicationId, request, UserUtil.getUserId(principal)); return ResponseEntity.noContent().build(); } @@ -53,7 +58,7 @@ public ResponseEntity updateApplicationPage2( @PatchMapping("/{applicationId}/page3") public ResponseEntity updateApplicationPage3( @PathVariable @Parameter(description = "지원서 ID") Long applicationId, - @RequestBody ApplicationPage3Request request, Principal principal){ + @RequestBody ApplicationPage3Request request, Principal principal) { applicationCommandService.updateApplicationPage3(applicationId, request, UserUtil.getUserId(principal)); return ResponseEntity.noContent().build(); } @@ -63,7 +68,7 @@ public ResponseEntity updateApplicationPage3( public ResponseEntity updateApplicationPage4( @PathVariable @Parameter(description = "지원서 ID") Long applicationId, @RequestBody ApplicationPage4Request request, - Principal principal){ + Principal principal) { applicationCommandService.updateApplicationPage4(applicationId, request, UserUtil.getUserId(principal)); return ResponseEntity.noContent().build(); } @@ -72,7 +77,7 @@ public ResponseEntity updateApplicationPage4( @PatchMapping("/{applicationId}/submit") public ResponseEntity submitApplication( @PathVariable @Parameter(description = "지원서 ID") Long applicationId, - Principal principal){ + Principal principal) { applicationCommandService.submitApplication(applicationId, UserUtil.getUserId(principal)); return ResponseEntity.noContent().build(); } diff --git a/src/main/java/com/startlion/startlionserver/domain/entity/Application.java b/src/main/java/com/startlion/startlionserver/domain/entity/Application.java index e24e7ef..6af6a98 100644 --- a/src/main/java/com/startlion/startlionserver/domain/entity/Application.java +++ b/src/main/java/com/startlion/startlionserver/domain/entity/Application.java @@ -14,6 +14,7 @@ import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import org.springframework.util.Assert; @Entity @NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter @@ -30,25 +31,77 @@ public class Application extends BaseTimeEntity { @ManyToOne(fetch = FetchType.LAZY) @JoinColumn(name = "user_id") private User user; + + /* + 이름 (필수) + */ @Column(length = 30) private String name; + + /* + 성별 (필수) + */ @Enumerated(EnumType.STRING) private Gender gender; + + /* + 기수 (필수) + */ private int generation; + + /* + 학번 (필수) + */ private String studentNumber; + + /* + 전공 (필수) + */ @Column(length = 30) private String major; + + /* + 다중 전공 (선택) + */ @Column(length = 30) private String multiMajor; + + /* + 학기 (필수) + */ @Enumerated(EnumType.STRING) private Semester semester; + + /* + 휴대폰 번호 (필수) + */ private String phone; + + /* + 이메일 (필수) + */ private String email; + + /* + 지원파트 (필수) + */ @Enumerated(EnumType.STRING) private ApplyPart part; + + /* + 포트폴리오 Url (선택) + */ @Column(columnDefinition = "TEXT") private String portfolioUrl; + + /* + 제출 상태 + */ private SubmitStatus status; + + /* + 인터뷰 가능 시간 + */ private String availableInterviewTime; @Column(columnDefinition = "TEXT") @@ -149,8 +202,19 @@ public void updateApplicationPage4(ApplicationPage4Request request) { } public void completeApplication() { + isCompleteAnswer(); this.status = SubmitStatus.Y; } + private void isCompleteAnswer() { + Assert.notNull(this.name, "이름이 입력되지 않았습니다."); + Assert.notNull(this.gender, "성별이 입력되지 않았습니다."); + Assert.notNull(this.email, "성별이 입력되지 않았습니다."); + Assert.notNull(this.major, "전공이 입력되지 않았습니다."); + Assert.notNull(this.studentNumber, "학번이 입력되지 않았습니다."); + Assert.notNull(this.phone, "전화번호가 입력되지 않았습니다."); + Assert.notNull(this.semester, "학기가 입력되지 않았습니다."); + Assert.notNull(this.part, "지원 파트가 입력되지 않았습니다."); + } } diff --git a/src/main/java/com/startlion/startlionserver/service/ApplicationCommandService.java b/src/main/java/com/startlion/startlionserver/service/ApplicationCommandService.java index 1b68baa..709f88f 100644 --- a/src/main/java/com/startlion/startlionserver/service/ApplicationCommandService.java +++ b/src/main/java/com/startlion/startlionserver/service/ApplicationCommandService.java @@ -7,6 +7,7 @@ import com.startlion.startlionserver.dto.request.application.ApplicationPage2Request; import com.startlion.startlionserver.dto.request.application.ApplicationPage3Request; import com.startlion.startlionserver.dto.request.application.ApplicationPage4Request; +import com.startlion.startlionserver.dto.response.application.ApplicationPage1Response; import com.startlion.startlionserver.global.exception.AccessDeniedException; import com.startlion.startlionserver.repository.ApplicationJpaRepository; import com.startlion.startlionserver.repository.CurrentGenerationRepository; @@ -30,7 +31,7 @@ public class ApplicationCommandService { private final PathToKnowJpaRepository pathToKnowJpaRepository; // method 변수가 되는 것이 아니라 전역 변수가 되어버림. - public Long createApplication(ApplicationPage1Request request, Long userId, Long applicationId) { + public ApplicationPage1Response createApplication(ApplicationPage1Request request, Long userId) { val currentGeneration = currentGenerationRepository.findAll() .stream() @@ -42,18 +43,19 @@ public Long createApplication(ApplicationPage1Request request, Long userId, Long throw new IllegalArgumentException("개인정보 수집 및 이용에 동의해주세요."); } - if (applicationId == 0) { - val user = userJpaRepository.findByIdOrThrow(userId); - val application = Application.create(request, user, currentGeneration); - applicationJpaRepository.save(application); - savePathToKnows(request.pathToKnows(), application.getApplicationId(), request.etcDetail()); - return application.getApplicationId(); - } + val user = userJpaRepository.findByIdOrThrow(userId); + val application = Application.create(request, user, currentGeneration); + applicationJpaRepository.save(application); + savePathToKnows(request.pathToKnows(), application.getApplicationId(), request.etcDetail()); + return ApplicationPage1Response.of(application, request.pathToKnows()); + } + public void updateApplicationPage1(Long applicationId, ApplicationPage1Request request, Long userId) { val application = applicationJpaRepository.findByIdOrThrow(applicationId); + checkApplicationOwner(application, userId); application.updateApplicationPage1(request); pathToKnowJpaRepository.deleteAllByApplicationId(applicationId); - return application.getApplicationId(); + savePathToKnows(request.pathToKnows(), applicationId, request.etcDetail()); } public void updateApplicationPage2(Long applicationId, ApplicationPage2Request request, Long userId) {