Skip to content

Commit

Permalink
지원서 저장, 수정, 제출 API 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
unanchoi committed Jan 12, 2024
1 parent 1fbae0e commit 206c0a9
Show file tree
Hide file tree
Showing 4 changed files with 111 additions and 29 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -21,17 +22,27 @@
@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<ApplicationPage1Response> createApplication(
@RequestBody ApplicationPage1Request request,
Principal principal);


@Operation(summary = "지원서 저장하기 1페이지")
@Operation(summary = "지원서 업데이트 1페이지")
@ApiResponses(
value = {
@ApiResponse(responseCode = "200", description = "지원서 저장하기 성공"),
@ApiResponse(responseCode = "403", description = "권한 없음"),
@ApiResponse(responseCode = "404", description = "지원서 정보 없음")
}
)
ResponseEntity<ApplicationIdResponse> createApplication(
ResponseEntity<Void> updateApplicationPage1(
@PathVariable @Parameter(description = "지원서 ID") Long applicationId,
@RequestBody ApplicationPage1Request request,
Principal principal);
Expand All @@ -43,7 +54,7 @@ ResponseEntity<ApplicationIdResponse> createApplication(
@ApiResponse(responseCode = "404", description = "지원서 정보 없음")
}
)
@Operation(summary = "지원서 저장하기 2페이지")
@Operation(summary = "지원서 업데이트 2페이지")
ResponseEntity<Void> updateApplicationPage2(@PathVariable @Parameter(description = "지원서 ID") Long applicationId, @RequestBody ApplicationPage2Request request, Principal principal);

@ApiResponses(
Expand All @@ -53,7 +64,7 @@ ResponseEntity<ApplicationIdResponse> createApplication(
@ApiResponse(responseCode = "404", description = "지원서 정보 없음")
}
)
@Operation(summary = "지원서 저장하기 3페이지")
@Operation(summary = "지원서 업데이트 3페이지")
ResponseEntity<Void> updateApplicationPage3(@PathVariable @Parameter(description = "지원서 ID") Long applicationId, @RequestBody ApplicationPage3Request request, Principal principal);

@ApiResponses(
Expand All @@ -64,7 +75,7 @@ ResponseEntity<ApplicationIdResponse> createApplication(
}
)

@Operation(summary = "지원서 저장하기 4페이지 -> 제출")
@Operation(summary = "지원서 업데이트 4페이지")
ResponseEntity<Void> updateApplicationPage4(@PathVariable @Parameter(description = "지원서 ID") Long applicationId,
@RequestBody ApplicationPage4Request request,
Principal principal);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -23,28 +21,35 @@
@RequiredArgsConstructor
public class ApplicationController implements ApplicationApi {

private final ApplicationQueryService applicationQueryService;
private final ApplicationCommandService applicationCommandService;

@Override
@PostMapping
public ResponseEntity<ApplicationPage1Response> createApplication(
@RequestBody ApplicationPage1Request request,
Principal principal) {
val response = applicationCommandService.createApplication(request, UserUtil.getUserId(principal));
return ResponseEntity.ok(response);
}

@Override
@PutMapping("{applicationId}")
public ResponseEntity<ApplicationIdResponse> createApplication(
@PatchMapping("{applicationId}")
public ResponseEntity<Void> 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<Void> 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();
}
Expand All @@ -53,7 +58,7 @@ public ResponseEntity<Void> updateApplicationPage2(
@PatchMapping("/{applicationId}/page3")
public ResponseEntity<Void> 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();
}
Expand All @@ -63,7 +68,7 @@ public ResponseEntity<Void> updateApplicationPage3(
public ResponseEntity<Void> 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();
}
Expand All @@ -72,7 +77,7 @@ public ResponseEntity<Void> updateApplicationPage4(
@PatchMapping("/{applicationId}/submit")
public ResponseEntity<Void> submitApplication(
@PathVariable @Parameter(description = "지원서 ID") Long applicationId,
Principal principal){
Principal principal) {
applicationCommandService.submitApplication(applicationId, UserUtil.getUserId(principal));
return ResponseEntity.noContent().build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.springframework.util.Assert;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED) @Getter
Expand All @@ -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")
Expand Down Expand Up @@ -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, "지원 파트가 입력되지 않았습니다.");
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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()
Expand All @@ -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) {
Expand Down

0 comments on commit 206c0a9

Please sign in to comment.