-
Notifications
You must be signed in to change notification settings - Fork 6
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Co-authored-by: github-actions[bot] <41898282+github-actions[bot]@users.noreply.github.com> Co-authored-by: Do Yeop Kim <113661364+Dobby-Kim@users.noreply.github.com> Co-authored-by: Kwoun Ki Ho <fingercut3822@gmail.com>
- Loading branch information
1 parent
c55d4de
commit f21fb03
Showing
27 changed files
with
746 additions
and
56 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
16 changes: 16 additions & 0 deletions
16
backend/src/main/java/com/cruru/applicant/controller/dto/ApplicantCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
package com.cruru.applicant.controller.dto; | ||
|
||
import jakarta.validation.constraints.NotBlank; | ||
|
||
public record ApplicantCreateRequest( | ||
@NotBlank(message = "이름은 필수 값입니다.") | ||
String name, | ||
|
||
@NotBlank(message = "이메일은 필수 값입니다.") | ||
String email, | ||
|
||
@NotBlank(message = "전화번호는 필수 값입니다.") | ||
String phone | ||
) { | ||
|
||
} |
30 changes: 30 additions & 0 deletions
30
backend/src/main/java/com/cruru/applyform/controller/ApplyFormController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package com.cruru.applyform.controller; | ||
|
||
import com.cruru.applyform.controller.dto.ApplyFormSubmitRequest; | ||
import com.cruru.applyform.service.ApplyFormService; | ||
import jakarta.validation.Valid; | ||
import java.net.URI; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/v1/applyform") | ||
@RequiredArgsConstructor | ||
public class ApplyFormController { | ||
|
||
private final ApplyFormService applyFormService; | ||
|
||
@PostMapping("/{applyform_id}/submit") | ||
public ResponseEntity<Void> submit( | ||
@RequestBody @Valid ApplyFormSubmitRequest request, | ||
@PathVariable(name = "applyform_id") long applyFormId | ||
) { | ||
applyFormService.submit(request, applyFormId); | ||
return ResponseEntity.created(URI.create("/v1/applyform/" + applyFormId)).build(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/com/cruru/applyform/controller/dto/AnswerCreateRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.cruru.applyform.controller.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.PositiveOrZero; | ||
import java.util.List; | ||
|
||
public record AnswerCreateRequest( | ||
@NotNull(message = "질문 식별자는 필수 값입니다.") | ||
@PositiveOrZero(message = "질문 식별자는 0 이상의 정수입니다.") | ||
@JsonProperty("question_id") | ||
Long questionId, | ||
|
||
@NotNull(message = "응답은 필수 값입니다.") | ||
List<String> replies | ||
) { | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
backend/src/main/java/com/cruru/applyform/controller/dto/ApplyFormSubmitRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.cruru.applyform.controller.dto; | ||
|
||
import com.cruru.applicant.controller.dto.ApplicantCreateRequest; | ||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import jakarta.validation.constraints.NotNull; | ||
import java.util.List; | ||
|
||
public record ApplyFormSubmitRequest( | ||
@JsonProperty("applicant") | ||
ApplicantCreateRequest applicantCreateRequest, | ||
|
||
@JsonProperty("answers") | ||
List<AnswerCreateRequest> answerCreateRequest, | ||
|
||
@NotNull(message = "개인정보 활용 동의는 필수 값입니다.") | ||
@JsonProperty("personal_data_collection") | ||
Boolean personalDataCollection | ||
) { | ||
|
||
} |
89 changes: 89 additions & 0 deletions
89
backend/src/main/java/com/cruru/applyform/domain/ApplyForm.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
package com.cruru.applyform.domain; | ||
|
||
import com.cruru.BaseEntity; | ||
import com.cruru.dashboard.domain.Dashboard; | ||
import jakarta.persistence.Column; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.OneToOne; | ||
import java.time.LocalDateTime; | ||
import java.util.Objects; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Entity | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
@Getter | ||
public class ApplyForm extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "apply_form_id") | ||
private Long id; | ||
|
||
private String title; | ||
|
||
private String description; | ||
|
||
private String url; | ||
|
||
@Column(name = "start_date") | ||
private LocalDateTime startDate; | ||
|
||
@Column(name = "due_date") | ||
private LocalDateTime dueDate; | ||
|
||
@OneToOne | ||
@JoinColumn(name = "dashboard_id") | ||
private Dashboard dashboard; | ||
|
||
public ApplyForm( | ||
String title, | ||
String description, | ||
String url, | ||
LocalDateTime startDate, | ||
LocalDateTime dueDate, | ||
Dashboard dashboard | ||
) { | ||
this.title = title; | ||
this.description = description; | ||
this.url = url; | ||
this.startDate = startDate; | ||
this.dueDate = dueDate; | ||
this.dashboard = dashboard; | ||
} | ||
|
||
@Override | ||
public boolean equals(Object o) { | ||
if (this == o) { | ||
return true; | ||
} | ||
if (!(o instanceof ApplyForm applyForm)) { | ||
return false; | ||
} | ||
return Objects.equals(id, applyForm.id); | ||
} | ||
|
||
@Override | ||
public int hashCode() { | ||
return Objects.hashCode(id); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return "ApplyForm{" + | ||
"id=" + id + | ||
", title='" + title + '\'' + | ||
", url='" + url + '\'' + | ||
", dashboard=" + dashboard + | ||
", startDate=" + startDate + | ||
", dueDate=" + dueDate + | ||
", description='" + description + '\'' + | ||
'}'; | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
backend/src/main/java/com/cruru/applyform/domain/repository/ApplyFormRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.cruru.applyform.domain.repository; | ||
|
||
import com.cruru.applyform.domain.ApplyForm; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ApplyFormRepository extends JpaRepository<ApplyForm, Long> { | ||
|
||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/com/cruru/applyform/exception/ApplyFormNotFoundException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.cruru.applyform.exception; | ||
|
||
import com.cruru.advice.NotFoundException; | ||
|
||
public class ApplyFormNotFoundException extends NotFoundException { | ||
|
||
private static final String TEXT = "지원서 폼"; | ||
|
||
public ApplyFormNotFoundException() { | ||
super(TEXT); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/com/cruru/applyform/exception/PersonalDataProcessingException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package com.cruru.applyform.exception; | ||
|
||
import com.cruru.advice.badrequest.BadRequestException; | ||
|
||
public class PersonalDataProcessingException extends BadRequestException { | ||
|
||
private static final String TEXT = "개인 정보 수집에 동의하지 않았습니다."; | ||
|
||
public PersonalDataProcessingException() { | ||
super(TEXT); | ||
} | ||
} |
80 changes: 80 additions & 0 deletions
80
backend/src/main/java/com/cruru/applyform/service/ApplyFormService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
package com.cruru.applyform.service; | ||
|
||
|
||
import com.cruru.advice.InternalServerException; | ||
import com.cruru.answer.domain.Answer; | ||
import com.cruru.answer.domain.repository.AnswerRepository; | ||
import com.cruru.applicant.domain.Applicant; | ||
import com.cruru.applicant.domain.repository.ApplicantRepository; | ||
import com.cruru.applyform.controller.dto.AnswerCreateRequest; | ||
import com.cruru.applyform.controller.dto.ApplyFormSubmitRequest; | ||
import com.cruru.applyform.domain.ApplyForm; | ||
import com.cruru.applyform.domain.repository.ApplyFormRepository; | ||
import com.cruru.applyform.exception.ApplyFormNotFoundException; | ||
import com.cruru.applyform.exception.PersonalDataProcessingException; | ||
import com.cruru.process.domain.Process; | ||
import com.cruru.process.domain.repository.ProcessRepository; | ||
import com.cruru.question.domain.Question; | ||
import com.cruru.question.domain.repository.QuestionRepository; | ||
import com.cruru.question.exception.QuestionNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class ApplyFormService { | ||
|
||
private final ApplicantRepository applicantRepository; | ||
private final AnswerRepository answerRepository; | ||
private final QuestionRepository questionRepository; | ||
private final ApplyFormRepository applyFormRepository; | ||
private final ProcessRepository processRepository; | ||
|
||
@Transactional | ||
public void submit(ApplyFormSubmitRequest request, long applyFormId) { | ||
validatePersonalDataCollection(request); | ||
|
||
ApplyForm applyForm = applyFormRepository.findById(applyFormId) | ||
.orElseThrow(ApplyFormNotFoundException::new); | ||
|
||
Process firstProcess = processRepository.findFirstByDashboardIdOrderBySequenceAsc( | ||
applyForm.getDashboard().getId() | ||
) | ||
.orElseThrow(InternalServerException::new); | ||
|
||
Applicant applicant = applicantRepository.save( | ||
new Applicant( | ||
request.applicantCreateRequest().name(), | ||
request.applicantCreateRequest().email(), | ||
request.applicantCreateRequest().phone(), | ||
firstProcess, | ||
false | ||
) | ||
); | ||
|
||
for (AnswerCreateRequest answerCreateRequest : request.answerCreateRequest()) { | ||
saveAnswerReplies(answerCreateRequest, applicant); | ||
} | ||
} | ||
|
||
private void validatePersonalDataCollection(ApplyFormSubmitRequest request) { | ||
if (!request.personalDataCollection()) { | ||
throw new PersonalDataProcessingException(); | ||
} | ||
} | ||
|
||
private void saveAnswerReplies(AnswerCreateRequest answerCreateRequest, Applicant applicant) { | ||
for (String reply : answerCreateRequest.replies()) { | ||
Question question = getQuestionById(answerCreateRequest.questionId()); | ||
Answer answer = new Answer(reply, question, applicant); | ||
answerRepository.save(answer); | ||
} | ||
} | ||
|
||
private Question getQuestionById(long questionId) { | ||
return questionRepository.findById(questionId) | ||
.orElseThrow(QuestionNotFoundException::new); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.