Skip to content

Commit

Permalink
Merge pull request #57 from Leets-Official/refactor/#56-반환-데이터-변경-및-세…
Browse files Browse the repository at this point in the history
…부-사항-수정

Refactor : 반환 데이터 변경 및 세부 사항 수정
  • Loading branch information
huncozyboy authored Nov 10, 2024
2 parents 71129d4 + 14f54b7 commit d374b4e
Show file tree
Hide file tree
Showing 11 changed files with 242 additions and 137 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,9 @@
import land.leets.Carrot.domain.user.dto.request.EmployeeCareerUpdateRequest;
import land.leets.Carrot.domain.user.dto.request.EmployeeSelfIntroUpdateRequest;
import land.leets.Carrot.domain.user.dto.request.EmployeeStrengthUpdateRequest;
import land.leets.Carrot.domain.user.dto.response.ProfileResponse;
import land.leets.Carrot.domain.user.dto.response.EmployeeProfileResponse;
import land.leets.Carrot.domain.user.dto.response.GetCeoInfoResponse;
import land.leets.Carrot.domain.user.dto.response.UserBasicInfoResponse;
import land.leets.Carrot.domain.user.service.CeoInfoService;
import land.leets.Carrot.domain.user.service.UserProfileService;
import land.leets.Carrot.global.auth.annotation.CurrentUser;
Expand All @@ -30,8 +31,8 @@
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PatchMapping;
import org.springframework.web.bind.annotation.PostMapping;
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.RequestParam;
Expand All @@ -46,14 +47,18 @@ public class UserProfileController {
private final S3ImageService s3ImageService;
private final CeoInfoService ceoInfoService;

/*
공통 필드
*/
@GetMapping("/profile")
@Operation(summary = "프로필 메인 페이지")
public ResponseEntity<ResponseDto<ProfileResponse>> check(@Parameter(hidden = true) @CurrentUser Long userId) {
ProfileResponse profileResponse = userProfileService.check(userId);
@Operation(summary = "프로필 기본정보 조회")
public ResponseEntity<ResponseDto<UserBasicInfoResponse>> check(
@Parameter(hidden = true) @CurrentUser Long userId) {
UserBasicInfoResponse userBasicInfoResponse = userProfileService.check(userId);
return ResponseEntity.ok(ResponseDto.response(
PROFILE_CHECK_SUCCESS.getCode(),
PROFILE_CHECK_SUCCESS.getMessage(),
profileResponse
userBasicInfoResponse
));
}

Expand All @@ -68,8 +73,63 @@ public ResponseEntity<ResponseDto<Void>> updateBasicInfo(@RequestBody @Valid Bas
);
}

@PostMapping("/upload-profile-image")
@Operation(summary = "프로필 이미지 업로드")
public ResponseEntity<ResponseDto<Void>> uploadProfileImage(
@RequestParam("image") MultipartFile image,
@Parameter(hidden = true) @CurrentUser Long userId) {
String imageUrl = s3ImageService.uploadImage(image, "profile-images");
userProfileService.updateProfileImageUrl(userId, imageUrl);
return ResponseEntity.ok(
ResponseDto.response(IMAGE_UPLOAD_SUCCESS.getCode(),
IMAGE_UPLOAD_SUCCESS.getMessage())
);
}

@PatchMapping("/update-profile-image")
@Operation(summary = "프로필 이미지 수정")
public ResponseEntity<ResponseDto<Void>> updateProfileImage(
@RequestParam("image") MultipartFile image,
@RequestParam("oldFileName") String oldFileName,
@Parameter(hidden = true) @CurrentUser Long userId) {
String imageUrl = s3ImageService.updateImage(image, oldFileName, "profile-images");
userProfileService.updateProfileImageUrl(userId, imageUrl);
return ResponseEntity.ok(
ResponseDto.response(IMAGE_UPDATE_SUCCESS.getCode(),
IMAGE_UPDATE_SUCCESS.getMessage())
);
}

@DeleteMapping("/delete-profile-image")
@Operation(summary = "프로필 이미지 삭제")
public ResponseEntity<ResponseDto<Void>> deleteProfileImage(
@RequestParam("fileName") String fileName,
@Parameter(hidden = true) @CurrentUser Long userId) {
s3ImageService.deleteImage(fileName);
userProfileService.updateProfileImageUrl(userId, null);
return ResponseEntity.ok(
ResponseDto.response(IMAGE_DELETE_SUCCESS.getCode(),
IMAGE_DELETE_SUCCESS.getMessage())
);
}

/*
employee(구직자 프로필 관련)
*/
@GetMapping("/employee-main-profile")
@Operation(summary = "내 지원서 관리")
public ResponseEntity<ResponseDto<EmployeeProfileResponse>> employeeAll(
@Parameter(hidden = true) @CurrentUser Long userId) {
EmployeeProfileResponse employeeProfileResponse = userProfileService.employeeAll(userId);
return ResponseEntity.ok(ResponseDto.response(
PROFILE_CHECK_SUCCESS.getCode(),
PROFILE_CHECK_SUCCESS.getMessage(),
employeeProfileResponse
));
}

@PatchMapping("/update-career")
@Operation(summary = "구직자 경력 수정")
@Operation(summary = "구직자 경력사항 추가")
public ResponseEntity<ResponseDto<Void>> updateCareer(@RequestBody @Valid EmployeeCareerUpdateRequest request,
@Parameter(hidden = true) @CurrentUser Long userId) {
userProfileService.updateCareer(request, userId);
Expand Down Expand Up @@ -114,45 +174,9 @@ public ResponseEntity<ResponseDto<Void>> updateStrength(@RequestBody @Valid Empl
);
}

@PostMapping("/upload-profile-image")
@Operation(summary = "프로필 이미지 업로드")
public ResponseEntity<ResponseDto<Void>> uploadProfileImage(
@RequestParam("image") MultipartFile image,
@Parameter(hidden = true) @CurrentUser Long userId) {
String imageUrl = s3ImageService.uploadImage(image, "profile-images");
userProfileService.updateProfileImageUrl(userId, imageUrl);
return ResponseEntity.ok(
ResponseDto.response(IMAGE_UPLOAD_SUCCESS.getCode(),
IMAGE_UPLOAD_SUCCESS.getMessage())
);
}

@PatchMapping("/update-profile-image")
@Operation(summary = "프로필 이미지 수정")
public ResponseEntity<ResponseDto<Void>> updateProfileImage(
@RequestParam("image") MultipartFile image,
@RequestParam("oldFileName") String oldFileName,
@Parameter(hidden = true) @CurrentUser Long userId) {
String imageUrl = s3ImageService.updateImage(image, oldFileName, "profile-images");
userProfileService.updateProfileImageUrl(userId, imageUrl);
return ResponseEntity.ok(
ResponseDto.response(IMAGE_UPDATE_SUCCESS.getCode(),
IMAGE_UPDATE_SUCCESS.getMessage())
);
}

@DeleteMapping("/delete-profile-image")
@Operation(summary = "프로필 이미지 삭제")
public ResponseEntity<ResponseDto<Void>> deleteProfileImage(
@RequestParam("fileName") String fileName,
@Parameter(hidden = true) @CurrentUser Long userId) {
s3ImageService.deleteImage(fileName);
userProfileService.updateProfileImageUrl(userId, null);
return ResponseEntity.ok(
ResponseDto.response(IMAGE_DELETE_SUCCESS.getCode(),
IMAGE_DELETE_SUCCESS.getMessage())
);
}
/*
ceo(고용자 프로필 관련)
*/
@GetMapping("/ceo-info/{ceoId}")
public ResponseEntity<ResponseDto<GetCeoInfoResponse>> getCeoInfo(@PathVariable("ceoId") Long ceoId) {
return ResponseEntity.ok(ceoInfoService.getCeoInfo(ceoId));
Expand Down
Original file line number Diff line number Diff line change
@@ -1,26 +1,24 @@
package land.leets.Carrot.domain.user.dto.request;

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

@Getter
@NoArgsConstructor
public class CeoSignupRequest {
@NotNull
private String email;
@NotNull
private String password;
@NotNull
private String ceoName;
@NotNull
private String ceoPhoneNumber;
@NotNull
private String ceoNumber;
@NotNull
private String storeName;
@NotNull
private String openDate;
@NotNull
private String ceoAddress;
public record CeoSignupRequest(
String email,
String password,
String ceoName,
String ceoPhoneNumber,
String ceoNumber,
String storeName,
String openDate,
String ceoAddress
) {
public static CeoSignupRequest of(String email,
String password,
String ceoName,
String ceoPhoneNumber,
String ceoNumber,
String storeName,
String openDate,
String ceoAddress) {
return new CeoSignupRequest(email, password, ceoName, ceoPhoneNumber, ceoNumber, storeName, openDate,
ceoAddress);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package land.leets.Carrot.domain.user.dto.response;

import land.leets.Carrot.domain.user.entity.Ceo;
import land.leets.Carrot.domain.user.entity.Gender;

public record CeoBasicInfoResponse(
String ceoName,
String ceoPhoneNumber,
String ceoAddress,
Gender gender,
Integer birthYear
) implements UserBasicInfoResponse {
public static CeoBasicInfoResponse from(Ceo ceo) {
return new CeoBasicInfoResponse(
ceo.getCeoName(),
ceo.getCeoPhoneNumber(),
ceo.getCeoAddress(),
ceo.getGender(),
ceo.getBirthYear()
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package land.leets.Carrot.domain.user.dto.response;

import land.leets.Carrot.domain.user.entity.Employee;
import land.leets.Carrot.domain.user.entity.Gender;

public record EmployeeBasicInfoResponse(
String employeeName,
String employeeAddress,
String phoneNumber,
Gender gender,
Integer birthYear
) implements UserBasicInfoResponse {
public static EmployeeBasicInfoResponse from(Employee employee) {
return new EmployeeBasicInfoResponse(
employee.getEmployeeName(),
employee.getEmployeeAddress(),
employee.getPhoneNumber(),
employee.getGender(),
employee.getBirthYear()
);
}
}
Original file line number Diff line number Diff line change
@@ -1,18 +1,56 @@
package land.leets.Carrot.domain.user.dto.response;

import land.leets.Carrot.domain.user.entity.Employee;
import lombok.Getter;
import land.leets.Carrot.domain.user.entity.Gender;

@Getter
public class EmployeeProfileResponse extends ProfileResponse {
private final String employeeName;
private final String employeeAddress;
private final String phoneNumber;

public EmployeeProfileResponse(Employee employee) {
super(employee.getGender(), employee.getBirthYear());
this.employeeName = employee.getEmployeeName();
this.employeeAddress = employee.getEmployeeAddress();
this.phoneNumber = employee.getPhoneNumber();
public record EmployeeProfileResponse(
String phoneNumber,
String employeeName,
String employeeAddress,
String workplace,
String workType,
String workYear,
String workPeriod,
String selfIntro,
boolean isSmoke,
boolean isLongWork,
boolean isCarLicense,
boolean isEnglish,
boolean isMilitary,
boolean isCookLicense,
boolean isDiligent,
boolean isOnTime,
boolean isClean,
boolean isNearHome,
boolean isSleepless,
Gender gender,
Integer birthYear,
String profileImageUrl
) {
public static EmployeeProfileResponse from(Employee employee) {
return new EmployeeProfileResponse(
employee.getPhoneNumber(),
employee.getEmployeeName(),
employee.getEmployeeAddress(),
employee.getWorkplace(),
employee.getWorkType(),
employee.getWorkYear(),
employee.getWorkPeriod(),
employee.getSelfIntro(),
employee.isSmoke(),
employee.isLongWork(),
employee.isCarLicense(),
employee.isEnglish(),
employee.isMilitary(),
employee.isCookLicense(),
employee.isDiligent(),
employee.isOnTime(),
employee.isClean(),
employee.isNearHome(),
employee.isSleepless(),
employee.getGender(),
employee.getBirthYear(),
employee.getProfileImageUrl()
);
}
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package land.leets.Carrot.domain.user.dto.response;

import land.leets.Carrot.domain.user.entity.Ceo;
import land.leets.Carrot.domain.user.entity.Employee;
import land.leets.Carrot.domain.user.entity.Gender;
import land.leets.Carrot.domain.user.entity.User;
import land.leets.Carrot.domain.user.exception.UnknownUserTypeException;

public sealed interface UserBasicInfoResponse permits CeoBasicInfoResponse, EmployeeBasicInfoResponse {
Gender gender();

Integer birthYear();

static UserBasicInfoResponse from(User user) {
if (user instanceof Employee employee) {
return EmployeeBasicInfoResponse.from(employee);
} else if (user instanceof Ceo ceo) {
return CeoBasicInfoResponse.from(ceo);
} else {
throw new UnknownUserTypeException();
}
}
}
Loading

0 comments on commit d374b4e

Please sign in to comment.