Skip to content

Commit

Permalink
Merge pull request #60 from WE-ARE-RACCOONS/RAC-184
Browse files Browse the repository at this point in the history
  • Loading branch information
ywj9811 authored Nov 25, 2023
2 parents 9f4aa01 + 4104f9e commit a82d43d
Show file tree
Hide file tree
Showing 16 changed files with 205 additions and 110 deletions.
Original file line number Diff line number Diff line change
@@ -1,26 +1,7 @@
package com.postgraduate.domain.auth.application.dto.req;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class SeniorChangeRequest {
@NotNull
private String major;
@NotNull
private String postgradu;
@NotNull
private String professor;
@NotNull
private String lab;
@NotNull
private String field;
@NotNull
private String keyword;
@NotNull
private String certification;
public record SeniorChangeRequest(@NotNull String major, @NotNull String postgradu, @NotNull String professor,
@NotNull String lab, @NotNull String field, @NotNull String keyword, @NotNull String certification) {
}
Original file line number Diff line number Diff line change
@@ -1,34 +1,9 @@
package com.postgraduate.domain.auth.application.dto.req;

import jakarta.validation.constraints.NotNull;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@AllArgsConstructor
@NoArgsConstructor
public class SeniorSignUpRequest {
@NotNull
private Long socialId;
@NotNull
private String phoneNumber;
@NotNull
private String nickName;
@NotNull
private Boolean marketingReceive;
@NotNull
private String major;
@NotNull
private String postgradu;
@NotNull
private String professor;
@NotNull
private String lab;
@NotNull
private String field;
@NotNull
private String keyword;
@NotNull
private String certification;
public record SeniorSignUpRequest(@NotNull Long socialId, @NotNull String phoneNumber, @NotNull String nickName,
@NotNull Boolean marketingReceive, @NotNull String major, @NotNull String postgradu,
@NotNull String professor, @NotNull String lab, @NotNull String field,
@NotNull String keyword, @NotNull String certification) {
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.postgraduate.domain.image.application.dto;
package com.postgraduate.domain.image.application.dto.req;

import lombok.AllArgsConstructor;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.postgraduate.domain.image.application.dto.res;

import jakarta.validation.constraints.NotNull;

public record ImageUrlResponse(@NotNull String profileUrl) {}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.postgraduate.domain.image.application.dto;
package com.postgraduate.domain.image.application.dto.res;

import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.postgraduate.domain.image.application.usecase;

import com.postgraduate.domain.image.application.dto.res.ImageUrlResponse;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.global.config.s3.S3UploadService;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

@Service
@RequiredArgsConstructor
public class ImageUploadUseCase {
private final S3UploadService uploadService;

public ImageUrlResponse uploadCertification(MultipartFile certification) {
String url = uploadService.saveCertificationFile(certification);
return new ImageUrlResponse(url);
}

public ImageUrlResponse uploadProfile(User user, MultipartFile profile) {
if (user.getProfile() != null)
uploadService.deleteProfileImage(user.getProfile());
String url = uploadService.saveProfileFile(profile);
return new ImageUrlResponse(url);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.postgraduate.domain.image.application.usecase;

import com.postgraduate.domain.image.application.dto.PreSignedUrlRequest;
import com.postgraduate.domain.image.application.dto.PreSignedUrlResponse;
import com.postgraduate.domain.image.application.dto.req.PreSignedUrlRequest;
import com.postgraduate.domain.image.application.dto.res.PreSignedUrlResponse;
import com.postgraduate.domain.image.exception.EmptyFileException;
import com.postgraduate.global.config.s3.S3Service;
import lombok.RequiredArgsConstructor;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.postgraduate.domain.image.exception;

import static com.postgraduate.domain.image.presentation.constant.ImageResponseCode.IMAGE_DELETE_ERROR;
import static com.postgraduate.domain.image.presentation.constant.ImageResponseMessage.DELETE_ERROR;

public class DeleteException extends ImageException{
public DeleteException() {
super(DELETE_ERROR.getMessage(), IMAGE_DELETE_ERROR.getCode());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.postgraduate.domain.image.exception;

import static com.postgraduate.domain.image.presentation.constant.ImageResponseCode.IMAGE_UPLOAD_ERROR;
import static com.postgraduate.domain.image.presentation.constant.ImageResponseMessage.UPLOAD_ERROR;

public class UploadException extends ImageException{
public UploadException() {
super(UPLOAD_ERROR.getMessage(), IMAGE_UPLOAD_ERROR.getCode());
}
}
Original file line number Diff line number Diff line change
@@ -1,38 +1,56 @@
package com.postgraduate.domain.image.presentation;

import com.postgraduate.domain.image.application.dto.PreSignedUrlRequest;
import com.postgraduate.domain.image.application.dto.PreSignedUrlResponse;
import com.postgraduate.domain.image.application.dto.req.PreSignedUrlRequest;
import com.postgraduate.domain.image.application.dto.res.PreSignedUrlResponse;
import com.postgraduate.domain.image.application.dto.res.ImageUrlResponse;
import com.postgraduate.domain.image.application.usecase.ImageUploadUseCase;
import com.postgraduate.domain.image.application.usecase.PreSignedUseCase;
import com.postgraduate.domain.user.domain.entity.User;
import com.postgraduate.global.dto.ResponseDto;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.RequiredArgsConstructor;
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;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;

import static com.postgraduate.domain.image.presentation.constant.ImageResponseCode.IMAGE_CREATE;
import static com.postgraduate.domain.image.presentation.constant.ImageResponseMessage.ISSUE_URL;
import static com.postgraduate.domain.image.presentation.constant.ImageResponseMessage.UPLOAD_URL;

@RestController
@RequiredArgsConstructor
@RequestMapping("/image")
@Tag(name = "IMAGE Controller")
public class ImageController {
private final PreSignedUseCase preSignedUseCase;
private final ImageUploadUseCase imageUploadUseCase;

@PostMapping("/url/profile")
@Operation(description = "USER Profile 등록 URL API - 이미지 풀네임으로 주세요 xxx.확장자, 이미지 이름을 유니크하게 만들어주세요 UUID+파일명 등등")
public ResponseDto<PreSignedUrlResponse> getProfileUrl(@RequestBody PreSignedUrlRequest preSignedUrlRequest) {
public ResponseDto<PreSignedUrlResponse> getProfilePreSignedUrl(@RequestBody PreSignedUrlRequest preSignedUrlRequest) {
PreSignedUrlResponse profileUrl = preSignedUseCase.getProfileUrl(preSignedUrlRequest);
return ResponseDto.create(IMAGE_CREATE.getCode(), ISSUE_URL.getMessage(), profileUrl);
}

@PostMapping("/url/certification")
@Operation(description = "Senior 학생증 인증 등록 URL API - 이미지 풀네임으로 주세요 xxx.확장자, 이미지 이름을 유니크하게 만들어주세요 UUID+파일명 등등")
public ResponseDto<PreSignedUrlResponse> getCertificationUrl(@RequestBody PreSignedUrlRequest preSignedUrlRequest) {
public ResponseDto<PreSignedUrlResponse> getCertificationPreSignedUrl(@RequestBody PreSignedUrlRequest preSignedUrlRequest) {
PreSignedUrlResponse certificationUrl = preSignedUseCase.getCertificationUrl(preSignedUrlRequest);
return ResponseDto.create(IMAGE_CREATE.getCode(), ISSUE_URL.getMessage(), certificationUrl);
}

@PostMapping("/upload/profile")
@Operation(summary = "USER Profile 업로드 후 업로드 URL return / 토큰 필요", description = "profileFile 사진 Multipart File로 보내주세요")
public ResponseDto<ImageUrlResponse> getProfileUrl(@AuthenticationPrincipal User user, @RequestPart MultipartFile profileFile) {
ImageUrlResponse imageUrlResponse = imageUploadUseCase.uploadProfile(user, profileFile);
return ResponseDto.create(IMAGE_CREATE.getCode(), UPLOAD_URL.getMessage(), imageUrlResponse);
}

@PostMapping("/upload/certification")
@Operation(summary = "SENIOR Certification 업로드 후 업로드 URL return", description = "certificationFile 사진 Multipart File로 보내주세요")
public ResponseDto<ImageUrlResponse> getCertificationUrl(@RequestPart MultipartFile certificationFile) {
ImageUrlResponse imageUrlResponse = imageUploadUseCase.uploadCertification(certificationFile);
return ResponseDto.create(IMAGE_CREATE.getCode(), UPLOAD_URL.getMessage(), imageUrlResponse);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ public enum ImageResponseCode {
IMAGE_CREATE("IMG202"),
IMAGE_DELETE("IMG203"),

IMAGE_EMPTY("EX800");
IMAGE_EMPTY("EX800"),
IMAGE_UPLOAD_ERROR("EX801"),
IMAGE_DELETE_ERROR("EX802");
private final String code;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,10 @@
@RequiredArgsConstructor
public enum ImageResponseMessage {
ISSUE_URL("URL발급에 성공하였습니다."),
UPLOAD_URL("이미지 업로드에 성공하였습니다."),

EMPTY_IMAGE("이미지 파일이 입력되지 않았습니다.");
EMPTY_IMAGE("이미지 파일이 입력되지 않았습니다."),
UPLOAD_ERROR("이미지 파일이 업로드되지 않았습니다."),
DELETE_ERROR("이미지 파일이 삭제되지 않았습니다.");
private final String message;
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
package com.postgraduate.domain.senior.application.dto.res;

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

@Builder
@Getter
@AllArgsConstructor
public class SeniorMyPageUserAccountResponse {
private final String profile;
private final String nickName;
private final String bank;
private final String accountNumber;
private final String accountHolder;
public record SeniorMyPageUserAccountResponse(String profile, String phoneNumber, String nickName, String bank, String accountNumber,
String accountHolder) {
public SeniorMyPageUserAccountResponse(String profile, String phoneNumber, String nickName) {
this(profile, phoneNumber, nickName, null, null, null);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,20 @@ public static Senior mapToSenior(User user, SeniorSignUpRequest request) {
return Senior.builder()
.user(user)
.info(mapToInfo(request))
.certification(request.getCertification())
.certification(request.certification())
.build();
}

public static Info mapToInfo(SeniorSignUpRequest request) {
return Info.builder()
.major(request.getMajor())
.postgradu(request.getPostgradu())
.professor(request.getProfessor())
.lab(request.getLab())
.keyword(request.getKeyword())
.field(request.getField())
.totalInfo(request.getMajor() + request.getLab() + request.getField()
+ request.getProfessor() + request.getPostgradu())
.major(request.major())
.postgradu(request.postgradu())
.professor(request.professor())
.lab(request.lab())
.keyword(request.keyword())
.field(request.field())
.totalInfo(request.major() + request.lab() + request.field()
+ request.professor() + request.postgradu() + request.field())
.build();
}

Expand Down Expand Up @@ -59,20 +59,20 @@ public static Senior mapToSenior(User user, SeniorChangeRequest request) {
return Senior.builder()
.user(user)
.info(mapToInfo(request))
.certification(request.getCertification())
.certification(request.certification())
.build();
}

public static Info mapToInfo(SeniorChangeRequest request) {
return Info.builder()
.major(request.getMajor())
.postgradu(request.getPostgradu())
.professor(request.getProfessor())
.lab(request.getLab())
.keyword(request.getKeyword())
.field(request.getField())
.totalInfo(request.getMajor() + request.getLab() + request.getField()
+ request.getProfessor() + request.getPostgradu())
.major(request.major())
.postgradu(request.postgradu())
.professor(request.professor())
.lab(request.lab())
.keyword(request.keyword())
.field(request.field())
.totalInfo(request.major() + request.lab() + request.field()
+ request.professor() + request.postgradu() + request.keyword())
.build();
}

Expand Down Expand Up @@ -104,21 +104,21 @@ public static SeniorMyPageProfileResponse mapToMyPageProfile(Senior senior) {

public static SeniorMyPageUserAccountResponse mapToMyPageUserAccount(Senior senior, Account account, String accountNumber) {
User user = senior.getUser();
return SeniorMyPageUserAccountResponse.builder()
.profile(user.getProfile())
.nickName(user.getNickName())
.bank(account.getBank())
.accountNumber(accountNumber)
.accountHolder(account.getAccountHolder())
.build();
return new SeniorMyPageUserAccountResponse(
user.getProfile(),
user.getPhoneNumber(),
user.getNickName(),
account.getBank(),
accountNumber,
account.getAccountHolder());
}

public static SeniorMyPageUserAccountResponse mapToMyPageUserAccount(Senior senior) {
User user = senior.getUser();
return SeniorMyPageUserAccountResponse.builder()
.profile(user.getProfile())
.nickName(user.getNickName())
.build();
return new SeniorMyPageUserAccountResponse(
user.getProfile(),
user.getPhoneNumber(),
user.getNickName());
}

public static SeniorDetailResponse mapToSeniorDetail(Senior senior) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ public static User mapToUser(SignUpRequest request) {

public static User mapToUser(SeniorSignUpRequest request) {
return User.builder()
.socialId(request.getSocialId())
.nickName(request.getNickName())
.phoneNumber(request.getPhoneNumber())
.marketingReceive(request.getMarketingReceive())
.socialId(request.socialId())
.nickName(request.nickName())
.phoneNumber(request.phoneNumber())
.marketingReceive(request.marketingReceive())
.role(SENIOR)
.build();
}
Expand Down
Loading

0 comments on commit a82d43d

Please sign in to comment.