Skip to content

Commit

Permalink
[Refactor] 전체적인 코드 리팩토링 (#44) (#45)
Browse files Browse the repository at this point in the history
* refactor: api 재활용을 위한 코드 수정 (#44)

* refactor: api 재활용을 위한 코드 수정 (#44)

* feat: userService test (#44)

* test: 검증이 빠진 부분 검증 (#44)

* test: 이메일로 지원 시작 알림 테스트 (#44)

* test: 사진 업로드 테스트 (#44)

* test: 사진 업로드 테스트 (#44)

* test: 사진 업로드 테스트 (#44)

* test: 이메일 테스트 (#44)

* refactor: cors 설정 변경 (#44)

* refactor: cors 설정 변경 (#44)

* test: cors test (#44)

* test: user error test (#44)

* test: apply period test (#44)

* test: apply period test (#44)

* test: apply service test (#44)

* test: user test (#44)

* test: test code (#44)

* refactor: delete unused class (#44)

* test: exception handler test (#44)

* refactor: 지원서 리팩토링 (#44)

* refactor: config 리팩토링 (#44)

* refactor: email 리팩토링 (#44)

* refactor: user 리팩토링 (#44)

* refactor: response 리팩토링 (#44)

* refactor: controller 제네릭 명시 (#44)
  • Loading branch information
birdieHyun authored Nov 1, 2023
1 parent 879e7c0 commit 907708d
Show file tree
Hide file tree
Showing 36 changed files with 1,394 additions and 442 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -98,3 +98,5 @@ out
daemon
bin
.jqwik-database

lombok.config
2 changes: 0 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -53,8 +53,6 @@ dependencies {
testImplementation 'org.springframework.restdocs:spring-restdocs-mockmvc'

// aws service
implementation 'com.amazonaws:aws-java-sdk-core:1.12.429'
implementation 'com.amazonaws:aws-java-sdk-s3:1.12.429'
implementation 'software.amazon.awssdk:s3:2.16.83'

// querydsl 추가
Expand Down
18 changes: 3 additions & 15 deletions src/docs/asciidoc/api/application/application.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -56,19 +56,7 @@ include::{snippets}/admin-application-updateDocumentPass-doc/request-fields.adoc
include::{snippets}/admin-application-updateInterviewTime-doc/http-request.adoc[]
include::{snippets}/admin-application-updateInterviewTime-doc/request-fields.adoc[]


=== 서류 합격 메일
==== HTTP Request
include::{snippets}/admin-application-sendDocumentPassEmail-doc/http-request.adoc[]

=== 서류 불합격 메일
==== HTTP Request
include::{snippets}/admin-application-sendDocumentFailEmail-doc/http-request.adoc[]

=== 최종 합격 메일
==== HTTP Request
include::{snippets}/admin-application-sendFinalPassEmail-doc/http-request.adoc[]

=== 최종 불합격 메일
=== 지원 결과 이메일 전송
==== HTTP Request
include::{snippets}/admin-application-sendFinalFailEmail-doc/http-request.adoc[]
include::{snippets}/admin-application-sendResult-doc/http-request.adoc[]
include::{snippets}/admin-application-sendResult-doc/request-fields.adoc[]
3 changes: 3 additions & 0 deletions src/docs/asciidoc/api/email/email.adoc
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
=== 지원 기간 시작 시 이메일 전송
==== HTTP Request
include::{snippets}/email-apply-start-email/http-request.adoc[]
4 changes: 4 additions & 0 deletions src/docs/asciidoc/index.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,3 +22,7 @@ include::api/application/application.adoc[]
== User API

include::api/users/users.adoc[]

[[Email-API]]
== Email API
include::api/email/email.adoc[]
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import yonseigolf.server.apply.dto.request.*;
import yonseigolf.server.apply.dto.response.ApplicationResponse;
import yonseigolf.server.apply.dto.response.ImageResponse;
import yonseigolf.server.apply.dto.response.RecruitPeriodResponse;
import yonseigolf.server.apply.dto.response.SingleApplicationResult;
import yonseigolf.server.apply.image.ImageService;
import yonseigolf.server.apply.service.ApplyPeriodService;
Expand All @@ -35,199 +36,120 @@ public ApplicationController(ApplyService applicationService, ApplyPeriodService
}

@PostMapping("/application")
public ResponseEntity<CustomResponse> apply(@RequestBody ApplicationRequest request) {
public ResponseEntity<CustomResponse<Void>> apply(@RequestBody ApplicationRequest request) {

applicationService.apply(request);

return ResponseEntity
.ok()
.body(new CustomResponse(
"success",
200,
"연세골프 지원서 제출 성공"
));
.body(CustomResponse.successResponse("연세골프 지원서 제출 성공"));
}

@PostMapping("/application/emailAlarm")
public ResponseEntity<CustomResponse> emailAlarm(@RequestBody EmailAlertRequest request) {
public ResponseEntity<CustomResponse<Void>> emailAlarm(@RequestBody EmailAlertRequest request) {

applicationService.emailAlarm(request);

return ResponseEntity
.ok()
.body(new CustomResponse(
"success",
200,
"연세골프 이메일 알림 신청 성공"
));
.body(CustomResponse.successResponse("연세골프 지원서 이메일 알림 설정 성공"));
}

@GetMapping("/application/recruit")
public ResponseEntity<CustomResponse> getApplicationPeriod() {
public ResponseEntity<CustomResponse<RecruitPeriodResponse>> getApplicationPeriod() {

final long defaultId = 1L;

RecruitPeriodResponse applicationPeriod = applyPeriodService.getApplicationPeriod(defaultId);
return ResponseEntity
.ok()
.body(new CustomResponse(
"success",
200,
"연세골프 지원 기간 조회 성공",
applyPeriodService.getApplicationPeriod()
));
.body(CustomResponse.successResponse("연세골프 지원 기간 조회 성공", applicationPeriod));
}

@GetMapping("/application/availability")
public ResponseEntity<CustomResponse<Boolean>> getApplicationAvaliability() {

final long defaultId = 1L;

return ResponseEntity
.ok()
.body(new CustomResponse<>(
"success",
200,
.body(CustomResponse.successResponse(
"연세골프 지원 가능 여부 조회 성공",
applyPeriodService.getApplicationAvailability(LocalDate.now())
));
applyPeriodService.getApplicationAvailability(LocalDate.now(), defaultId)));
}

@GetMapping("/admin/forms")
public ResponseEntity<CustomResponse<Page<SingleApplicationResult>>> getApplicationResults(@RequestParam(required = false) Boolean documentPass,
@RequestParam(required = false) Boolean finalPass,
Pageable pageable) {

System.out.println("documentPass = " + documentPass);
System.out.println("finalPass = " + finalPass);
public ResponseEntity<CustomResponse<Page<SingleApplicationResult>>> getApplicationResults(
@RequestParam(required = false) Boolean documentPass,
@RequestParam(required = false) Boolean finalPass,
Pageable pageable) {

return ResponseEntity
.ok()
.body(new CustomResponse(
"success",
200,
.body(CustomResponse.successResponse(
"연세골프 지원서 조회 성공",
applicationService.getApplicationResults(documentPass, finalPass, pageable)
));
applicationService.getApplicationResults(documentPass, finalPass, pageable)));
}

@GetMapping("/admin/forms/{id}")
public ResponseEntity<CustomResponse<ApplicationResponse>> getApplication(@PathVariable Long id) {

return ResponseEntity
.ok()
.body(new CustomResponse(
"success",
200,
.body(CustomResponse.successResponse(
"연세골프 지원서 조회 성공",
applicationService.getApplication(id)
));
applicationService.getApplication(id)));
}

@PatchMapping("/admin/forms/{id}/documentPass")
public ResponseEntity<CustomResponse> updateDocumentPass(@PathVariable Long id, @RequestBody DocumentPassRequest documentPass) {
public ResponseEntity<CustomResponse<Void>> updateDocumentPass(@PathVariable Long id, @RequestBody DocumentPassRequest documentPass) {

applicationService.updateDocumentPass(id, documentPass.isDocumentPass());

return ResponseEntity
.ok()
.body(new CustomResponse(
"success",
200,
"연세골프 지원서 서류 합격 수정 성공"
));
.body(CustomResponse.successResponse("연세골프 지원서 서류 합격 수정 성공"));
}

@PatchMapping("/admin/forms/{id}/finalPass")
public ResponseEntity<CustomResponse> updateFinalPass(@PathVariable Long id, @RequestBody FinalPassRequest finalPass) {
public ResponseEntity<CustomResponse<Void>> updateFinalPass(@PathVariable Long id, @RequestBody FinalPassRequest finalPass) {

applicationService.updateFinalPass(id, finalPass.isFinalPass());

return ResponseEntity
.ok()
.body(new CustomResponse(
"success",
200,
"연세골프 지원서 최종 합격 수정 성공"
));
.body(CustomResponse.successResponse("연세골프 지원서 최종 합격 수정 성공"));
}

@PatchMapping("/admin/forms/{id}/interviewTime")
public ResponseEntity<CustomResponse> updateInterviewTime(@PathVariable Long id, @RequestBody UpdateInterviewTimeRequest time) {
public ResponseEntity<CustomResponse<Void>> updateInterviewTime(@PathVariable Long id, @RequestBody UpdateInterviewTimeRequest time) {

applicationService.updateInterviewTime(id, time.getTime());

return ResponseEntity
.ok()
.body(new CustomResponse(
"success",
200,
"연세골프 지원서 면접 시간 수정 성공"
));
}

@PostMapping("/admin/forms/documentPassEmail")
public ResponseEntity<CustomResponse> sendDocumentPassEmail() {

applicationService.sendDocumentPassEmail();

return ResponseEntity
.ok()
.body(new CustomResponse(
"success",
200,
"연세골프 지원서 서류 합격자 이메일 전송 성공"
));
.body(CustomResponse.successResponse("연세골프 지원서 면접 시간 수정 성공"));
}

@PostMapping("/admin/forms/finalPassEmail")
public ResponseEntity<CustomResponse> sendFinalPassEmail() {
@PostMapping("/admin/forms/results")
public ResponseEntity<CustomResponse<Void>> sendEmailNotification(@RequestBody ResultNotification request) {

applicationService.sendFinalPassEmail();
applicationService.sendEmailNotification(request.isDocumentPass(), request.getFinalPass());

return ResponseEntity
.ok()
.body(new CustomResponse(
"success",
200,
"연세골프 지원서 최종 합격자 이메일 전송 성공"
));
}

@PostMapping("/admin/forms/documentFailEmail")
public ResponseEntity<CustomResponse> sendDocumentFailEmail() {

applicationService.sendDocumentFailEmail();

return ResponseEntity
.ok()
.body(new CustomResponse(
"success",
200,
"연세골프 지원서 서류 불합격자 이메일 전송 성공"
));
}

@PostMapping("/admin/forms/finalFailEmail")
public ResponseEntity<CustomResponse> sendFinalFailEmail() {

applicationService.sendFinalFailEmail();

return ResponseEntity
.ok()
.body(new CustomResponse(
"success",
200,
"연세골프 지원서 최종 불합격자 이메일 전송 성공"
));
.body(CustomResponse.successResponse("연세골프 지원서 결과 이메일 발송 성공"));
}

@PostMapping("/apply/forms/image")
public ResponseEntity<CustomResponse<ImageResponse>> uploadImage(@RequestPart("image") MultipartFile image) {

String imageUrl = imageService.uploadImage(image, RandomString.make(10));

return ResponseEntity
.ok()
.body(new CustomResponse(
"success",
200,
"연세골프 지원서 이미지 업로드 성공",
imageUrl
));
.ok()
.body(CustomResponse.successResponse(
"연세골프 지원서 사진 업로드 성공",
new ImageResponse(imageUrl)));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package yonseigolf.server.apply.dto.request;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ResultNotification {

private boolean documentPass;
private Boolean finalPass;
}

Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import yonseigolf.server.apply.entity.Application;

import java.time.LocalDateTime;

Expand All @@ -32,16 +31,4 @@ public SingleApplicationResult(long id, String photo, String name, LocalDateTime
this.documentPass = documentPass;
this.finalPass = finalPass;
}

public SingleApplicationResult fromApplication(Application Application) {

return SingleApplicationResult.builder()
.id(Application.getId())
.photo(Application.getPhoto())
.name(Application.getName())
.interviewTime(Application.getInterviewTime())
.documentPass(Application.getDocumentPass())
.finalPass(Application.getFinalPass())
.build();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,22 +18,30 @@ public ApplyPeriodService(ApplyPeriodRepository repository) {
this.repository = repository;
}

public RecruitPeriodResponse getApplicationPeriod() {
public RecruitPeriodResponse getApplicationPeriod(long id) {

RecruitmentPeriod recruitmentPeriod = findById(id);

return RecruitPeriodResponse.builder()
.startDate(repository.getOne(1L).getStartDate())
.endDate(repository.getOne(1L).getEndDate())
.firstResultDate(repository.getOne(1L).getFirstResultDate())
.interviewStartDate(repository.getOne(1L).getInterviewStartDate())
.interviewEndDate(repository.getOne(1L).getInterviewEndDate())
.finalResultDate(repository.getOne(1L).getFinalResultDate())
.orientationDate(repository.getOne(1L).getOrientationDate())
.startDate(recruitmentPeriod.getStartDate())
.endDate(recruitmentPeriod.getEndDate())
.firstResultDate(recruitmentPeriod.getFirstResultDate())
.interviewStartDate(recruitmentPeriod.getInterviewStartDate())
.interviewEndDate(recruitmentPeriod.getInterviewEndDate())
.finalResultDate(recruitmentPeriod.getFinalResultDate())
.orientationDate(recruitmentPeriod.getOrientationDate())
.build();
}

public boolean getApplicationAvailability(LocalDate today) {
RecruitmentPeriod period = repository.getOne(1L);
public boolean getApplicationAvailability(LocalDate today, long periodId) {
RecruitmentPeriod period = findById(periodId);

return !today.isBefore(period.getStartDate()) && !today.isAfter(period.getEndDate());
}

private RecruitmentPeriod findById(long periodId) {

return repository.findById(periodId).orElseThrow(
() -> new IllegalArgumentException("해당 모집기간이 존재하지 않습니다."));
}
}
Loading

0 comments on commit 907708d

Please sign in to comment.