Skip to content

Commit

Permalink
πŸ”— :: (#471) μž¬μ§€μ› api
Browse files Browse the repository at this point in the history
πŸ”— :: (#471) μž¬μ§€μ› api
  • Loading branch information
geunoo authored Dec 3, 2023
2 parents 86c90d7 + fbb1dd8 commit 7593458
Show file tree
Hide file tree
Showing 6 changed files with 112 additions and 11 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package team.retum.jobis.domain.application.dto.response;

import lombok.AllArgsConstructor;
import lombok.Getter;

@Getter
@AllArgsConstructor
public class QueryRejectionReasonResponse {

private final String rejectionReason;
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,13 @@ public Application rejectApplication(String reason) {
.build();
}

public Application reapply(List<ApplicationAttachment> attachments) {
return this.toBuilder()
.attachments(attachments)
.applicationStatus(ApplicationStatus.REQUESTED)
.build();
}

public void checkReviewAuthority() {
if (this.applicationStatus == ApplicationStatus.REQUESTED
|| this.applicationStatus == ApplicationStatus.APPROVED
Expand All @@ -58,8 +65,8 @@ public void checkReviewAuthority() {
}
}

public void checkApplicationStatus(ApplicationStatus status1, ApplicationStatus status2) {
if (status1 != status2) {
public void checkApplicationStatus(ApplicationStatus requestedStatus, ApplicationStatus...baseStatuses) {
if (!List.of(baseStatuses).contains(requestedStatus)) {
throw ApplicationStatusCannotChangeException.EXCEPTION;
}
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package team.retum.jobis.domain.application.usecase;

import lombok.RequiredArgsConstructor;
import team.retum.jobis.common.annotation.ReadOnlyUseCase;
import team.retum.jobis.domain.application.dto.response.QueryRejectionReasonResponse;
import team.retum.jobis.domain.application.exception.ApplicationNotFoundException;
import team.retum.jobis.domain.application.model.Application;
import team.retum.jobis.domain.application.model.ApplicationStatus;
import team.retum.jobis.domain.application.spi.QueryApplicationPort;

@RequiredArgsConstructor
@ReadOnlyUseCase
public class QueryRejectionReasonUseCase {

private final QueryApplicationPort queryApplicationPort;

public QueryRejectionReasonResponse execute(Long applicationId) {
Application application = queryApplicationPort.queryApplicationById(applicationId)
.orElseThrow(() -> ApplicationNotFoundException.EXCEPTION);

if (application.getApplicationStatus() != ApplicationStatus.REJECTED) {
throw ApplicationNotFoundException.EXCEPTION;
}

return new QueryRejectionReasonResponse(application.getRejectionReason());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package team.retum.jobis.domain.application.usecase;

import lombok.RequiredArgsConstructor;
import team.retum.jobis.common.annotation.UseCase;
import team.retum.jobis.domain.application.dto.request.CreateApplicationRequest;
import team.retum.jobis.domain.application.exception.ApplicationNotFoundException;
import team.retum.jobis.domain.application.model.Application;
import team.retum.jobis.domain.application.model.ApplicationAttachment;
import team.retum.jobis.domain.application.model.ApplicationStatus;
import team.retum.jobis.domain.application.spi.CommandApplicationPort;
import team.retum.jobis.domain.application.spi.QueryApplicationPort;

@RequiredArgsConstructor
@UseCase
public class ReapplyUseCase {

private final QueryApplicationPort queryApplicationPort;
private final CommandApplicationPort commandApplicationPort;

public void execute(Long applicationId, CreateApplicationRequest request) {
Application application = queryApplicationPort.queryApplicationById(applicationId)
.orElseThrow(() -> ApplicationNotFoundException.EXCEPTION);

application.checkApplicationStatus(application.getApplicationStatus(), ApplicationStatus.REJECTED, ApplicationStatus.REQUESTED);

commandApplicationPort.saveApplication(
application.reapply(
request.getAttachments().stream()
.map(attachment -> new ApplicationAttachment(attachment.getUrl(), attachment.getType()))
.toList()
)
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -16,6 +17,7 @@
import team.retum.jobis.domain.application.dto.response.CompanyQueryApplicationsResponse;
import team.retum.jobis.domain.application.dto.response.QueryEmploymentCountResponse;
import team.retum.jobis.domain.application.dto.response.QueryPassedApplicationStudentsResponse;
import team.retum.jobis.domain.application.dto.response.QueryRejectionReasonResponse;
import team.retum.jobis.domain.application.dto.response.StudentQueryApplicationsResponse;
import team.retum.jobis.domain.application.dto.response.TeacherQueryApplicationsResponse;
import team.retum.jobis.domain.application.model.ApplicationStatus;
Expand All @@ -30,7 +32,9 @@
import team.retum.jobis.domain.application.usecase.CompanyQueryApplicationsUseCase;
import team.retum.jobis.domain.application.usecase.QueryEmploymentCountUseCase;
import team.retum.jobis.domain.application.usecase.QueryPassedApplicationStudentsUseCase;
import team.retum.jobis.domain.application.usecase.QueryRejectionReasonUseCase;
import team.retum.jobis.domain.application.usecase.QueryStudentApplicationsUseCase;
import team.retum.jobis.domain.application.usecase.ReapplyUseCase;
import team.retum.jobis.domain.application.usecase.RejectApplicationUseCase;
import team.retum.jobis.domain.application.usecase.TeacherQueryApplicationsUseCase;

Expand All @@ -51,6 +55,8 @@ public class ApplicationWebAdapter {
private final RejectApplicationUseCase rejectApplicationUseCase;
private final QueryEmploymentCountUseCase queryEmploymentCountUseCase;
private final QueryPassedApplicationStudentsUseCase queryPassedApplicationStudentsUseCase;
private final ReapplyUseCase reapplyUseCase;
private final QueryRejectionReasonUseCase queryRejectionReasonUseCase;

@ResponseStatus(HttpStatus.CREATED)
@PostMapping("/{recruitment-id}")
Expand Down Expand Up @@ -110,7 +116,7 @@ public void changeFieldTrainDate(@RequestBody @Valid ChangeFieldTrainDateWebRequ
}

@ResponseStatus(HttpStatus.NO_CONTENT)
@PatchMapping("/reject/{application-id}")
@PatchMapping("/rejection/{application-id}")
public void rejectApplication(
@PathVariable("application-id") Long applicationId,
@Valid @RequestBody RejectApplicationWebRequest request
Expand All @@ -129,4 +135,18 @@ public QueryPassedApplicationStudentsResponse queryFieldTrainApplication(
) {
return queryPassedApplicationStudentsUseCase.execute(companyId);
}

@ResponseStatus(HttpStatus.NO_CONTENT)
@PutMapping("/{application-id}")
public void reapply(
@PathVariable("application-id") Long applicationId,
@RequestBody CreateApplicationWebRequest request
) {
reapplyUseCase.execute(applicationId, request.toDomainRequest());
}

@GetMapping("/rejection/{application-id}")
public QueryRejectionReasonResponse queryRejectionReason(@PathVariable("application-id") Long applicationId) {
return queryRejectionReasonUseCase.execute(applicationId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -53,22 +53,24 @@ protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.antMatchers(HttpMethod.POST, "/students").permitAll()
.antMatchers(HttpMethod.PATCH, "/students//forgotten_password").permitAll()
.antMatchers(HttpMethod.GET, "/students/exists").permitAll()
.antMatchers(HttpMethod.PATCH, "/students/profile").hasAuthority(STUDENT.name())
.antMatchers(HttpMethod.GET, "/students/password").hasAuthority(STUDENT.name())
.antMatchers(HttpMethod.PATCH, "/students/password").hasAuthority(STUDENT.name())
.antMatchers(HttpMethod.PATCH, "/students/profile").hasAnyAuthority(STUDENT.name(), DEVELOPER.name())
.antMatchers(HttpMethod.GET, "/students/password").hasAnyAuthority(STUDENT.name(), DEVELOPER.name())
.antMatchers(HttpMethod.PATCH, "/students/password").hasAnyAuthority(STUDENT.name(), DEVELOPER.name())

// applications
.antMatchers(HttpMethod.GET, "/applications").hasAuthority(TEACHER.name())
.antMatchers(HttpMethod.GET, "/applications/count").hasAuthority(TEACHER.name())
.antMatchers(HttpMethod.GET, "/applications/employment/count").permitAll()
.antMatchers(HttpMethod.GET, "/applications/pass/{company-id}").hasAuthority(TEACHER.name())
.antMatchers(HttpMethod.GET, "/applications/pass/{company-id}").hasAnyAuthority(TEACHER.name())
.antMatchers(HttpMethod.GET, "/applications/company").hasAuthority(COMPANY.name())
.antMatchers(HttpMethod.GET, "/applications/students").hasAnyAuthority(STUDENT.name())
.antMatchers(HttpMethod.POST, "/applications/{company-id}").hasAuthority(STUDENT.name())
.antMatchers(HttpMethod.GET, "/applications/students").hasAnyAuthority(STUDENT.name(), DEVELOPER.name())
.antMatchers(HttpMethod.POST, "/applications/{company-id}").hasAnyAuthority(STUDENT.name(), DEVELOPER.name())
.antMatchers(HttpMethod.DELETE, "/applications/{application-id}").hasAuthority(STUDENT.name())
.antMatchers(HttpMethod.PATCH, "/applications/status").hasAnyAuthority(TEACHER.name())
.antMatchers(HttpMethod.PATCH, "/applications/train-date").hasAuthority(TEACHER.name())
.antMatchers(HttpMethod.PATCH, "/applications/reject/{application-id}").hasAuthority(TEACHER.name())
.antMatchers(HttpMethod.PATCH, "/applications/rejection/{application-id}").hasAuthority(TEACHER.name())
.antMatchers(HttpMethod.PUT, "/applications/{application-id}").hasAnyAuthority(STUDENT.name(), DEVELOPER.name())
.antMatchers(HttpMethod.GET, "/applications/rejection/{application-id}").hasAnyAuthority(STUDENT.name(), DEVELOPER.name())

// recruitments
.antMatchers(HttpMethod.GET, "/recruitments/my").hasAuthority(COMPANY.name())
Expand Down Expand Up @@ -133,7 +135,7 @@ protected SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
// review
.antMatchers(HttpMethod.GET, "/reviews/{company-id}").hasAnyAuthority(STUDENT.name(), TEACHER.name())
.antMatchers(HttpMethod.GET, "/reviews/details/{review-id}").hasAnyAuthority(STUDENT.name(), TEACHER.name())
.antMatchers(HttpMethod.POST, "/reviews").hasAuthority(STUDENT.name())
.antMatchers(HttpMethod.POST, "/reviews").hasAnyAuthority(STUDENT.name(), DEVELOPER.name())
.antMatchers(HttpMethod.DELETE, "/reviews/{review-id}").hasAuthority(TEACHER.name())

.anyRequest().authenticated()
Expand Down

0 comments on commit 7593458

Please sign in to comment.