Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

#260 [feat] 지원서 작성하기 POST API에 response로 만료일 보내기 #261

Merged
merged 6 commits into from
Mar 3, 2024
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.moddy.server.controller.application;

import com.moddy.server.common.dto.ErrorResponse;
import com.moddy.server.common.dto.SuccessNonDataResponse;
import com.moddy.server.common.dto.SuccessResponse;
import com.moddy.server.common.exception.enums.SuccessCode;
import com.moddy.server.config.resolver.user.UserId;
import com.moddy.server.controller.application.dto.response.ApplicationExpireDateResponse;
import com.moddy.server.controller.model.dto.request.ModelApplicationRequest;
import com.moddy.server.service.application.HairModelApplicationRegisterService;
import io.swagger.v3.oas.annotations.Operation;
Expand Down Expand Up @@ -33,18 +34,17 @@ public class ApplicationRegisterController {

@Operation(summary = "[JWT] 모델 지원서 작성", description = "모델 지원서 작성 API입니다.")
@ApiResponses({
@ApiResponse(responseCode = "200", description = "모델 지원서 작성 성공"),
@ApiResponse(responseCode = "200", description = "모델 지원서 작성 성공", content = @Content(schema = @Schema(implementation = ApplicationExpireDateResponse.class))),
@ApiResponse(responseCode = "400", description = "인증 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
@ApiResponse(responseCode = "500", description = "서버 내부 오류 입니다.", content = @Content(schema = @Schema(implementation = ErrorResponse.class))),
})
@SecurityRequirement(name = "JWT Auth")
@PostMapping(consumes = {MediaType.APPLICATION_JSON_VALUE, MediaType.MULTIPART_FORM_DATA_VALUE})
public SuccessNonDataResponse submitModelApplication(
public SuccessResponse<ApplicationExpireDateResponse> submitModelApplication(
@Parameter(hidden = true) @UserId Long modelId,
@RequestPart(value = "modelImgUrl", required = false) MultipartFile modelImgUrl,
@RequestPart(value = "applicationCaptureImgUrl", required = false) MultipartFile applicationCaptureImgUrl,
@RequestPart(value = "applicationInfo") @Valid ModelApplicationRequest applicationInfo) {
hairModelApplicationRegisterService.postApplication(modelId, modelImgUrl, applicationCaptureImgUrl, applicationInfo);
return SuccessNonDataResponse.success(SuccessCode.CREATE_MODEL_APPLICATION_SUCCESS);
return SuccessResponse.success(SuccessCode.CREATE_MODEL_APPLICATION_SUCCESS, hairModelApplicationRegisterService.postApplication(modelId, modelImgUrl, applicationCaptureImgUrl, applicationInfo));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.moddy.server.controller.application.dto.response;

public record ApplicationExpireDateResponse(
String expireDate
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@

import com.moddy.server.domain.BaseTimeEntity;
import com.moddy.server.domain.model.Model;
import com.moddy.server.domain.user.User;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.experimental.SuperBuilder;

import java.time.LocalDate;

@Entity
@Getter
Expand Down Expand Up @@ -48,4 +48,8 @@ public HairModelApplication(Model model, HairLength hairLength, String hairDetai
this.instagramId = instagramId;
this.applicationCaptureUrl = applicationCaptureUrl;
}

public LocalDate getExpiredDate(){
return getCreatedAt().plusDays(7).toLocalDate();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.moddy.server.common.exception.enums.ErrorCode;
import com.moddy.server.common.exception.model.NotFoundException;
import com.moddy.server.controller.application.dto.response.ApplicationExpireDateResponse;
import com.moddy.server.controller.model.dto.request.ModelApplicationRequest;
import com.moddy.server.domain.hair_model_application.HairModelApplication;
import com.moddy.server.domain.hair_model_application.repository.HairModelApplicationJpaRepository;
Expand All @@ -17,6 +18,7 @@
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.multipart.MultipartFile;

import java.time.format.DateTimeFormatter;
import java.util.List;

@Service
Expand All @@ -29,7 +31,7 @@ public class HairModelApplicationRegisterService {
private final ModelJpaRepository modelJpaRepository;

@Transactional
public void postApplication(final Long modelId, final MultipartFile modelImgUrl, final MultipartFile applicationCaptureImgUrl, final ModelApplicationRequest applicationInfo) {
public ApplicationExpireDateResponse postApplication(final Long modelId, final MultipartFile modelImgUrl, final MultipartFile applicationCaptureImgUrl, final ModelApplicationRequest applicationInfo) {
Model model = modelJpaRepository.findById(modelId).orElseThrow(() -> new NotFoundException(ErrorCode.NOT_FOUND_MODEL_INFO));
String s3ModelImgUrl = s3Service.uploadProfileImage(modelImgUrl, model.getRole());
String s3applicationCaptureImgUrl = s3Service.uploadApplicationImage(applicationCaptureImgUrl);
Expand All @@ -39,6 +41,8 @@ public void postApplication(final Long modelId, final MultipartFile modelImgUrl,

savePreferHairStyles(applicationInfo, hairModelApplication);
saveHairServiceRecords(applicationInfo, hairModelApplication);

return new ApplicationExpireDateResponse(hairModelApplication.getExpiredDate().format(DateTimeFormatter.ofPattern("yyyy. MM. dd.")));
}

public void deleteModelApplications(final Long modelId) {
Expand Down
Loading