Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
10 changes: 2 additions & 8 deletions src/main/java/es/princip/ringus/domain/mentee/Mentee.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package es.princip.ringus.domain.mentee;

import es.princip.ringus.domain.common.Education;
import es.princip.ringus.infra.storage.domain.Certificate;
import es.princip.ringus.infra.storage.domain.ProfileImage;
import jakarta.persistence.*;
import lombok.AccessLevel;
Expand Down Expand Up @@ -43,18 +42,13 @@ public Mentee(
final String nickname,
final Education education,
final String introduction,
final ProfileImage profileImage,
final Long memberId
) {
this.nickname = nickname;
this.education = education;
this.introduction = introduction;
this.memberId = memberId;
}

/**
* 프로필 이미지 업데이트
*/
public void updateProfileImage(ProfileImage profileImage) {
this.profileImage = profileImage;
this.memberId = memberId;
}
}
Original file line number Diff line number Diff line change
@@ -1,12 +1,7 @@
package es.princip.ringus.infra.storage.application;

import es.princip.ringus.domain.member.MemberType;
import es.princip.ringus.domain.mentee.Mentee;
import es.princip.ringus.domain.mentee.MenteeRepository;
import es.princip.ringus.domain.mentor.Mentor;
import es.princip.ringus.domain.mentor.MentorRepository;
import es.princip.ringus.infra.storage.domain.CertificateType;
import es.princip.ringus.infra.storage.domain.ProfileImage;
import es.princip.ringus.infra.storage.dto.CertificateUploadRequest;
import es.princip.ringus.infra.storage.dto.ProfileUploadRequest;
import lombok.RequiredArgsConstructor;
Expand All @@ -19,8 +14,6 @@
public class StorageService {

private final S3Service s3Service;
private final MenteeRepository menteeRepository;
private final MentorRepository mentorRepository;

@Transactional
public String uploadMenteeCertificate(CertificateUploadRequest request) {
Expand All @@ -47,22 +40,8 @@ public String uploadMentorCertificate(CertificateUploadRequest request) {
@Transactional
public String uploadProfileImage(ProfileUploadRequest request) {
String folderPath = buildProfileFolderPath(request.memberType());
String uploadedFilePath = s3Service.uploadFile(request.file(), folderPath);

ProfileImage profileImage = ProfileUploadRequest.toEntity(request, uploadedFilePath);

if(request.memberType() == MemberType.MENTEE) {
Mentee mentee = menteeRepository.findById(request.userId())
.orElseThrow(() -> new IllegalArgumentException("Mentee not found with id: " + request.userId()));
mentee.updateProfileImage(profileImage);
menteeRepository.save(mentee);
} else if(request.memberType() == MemberType.MENTOR) {
Mentor mentor = mentorRepository.findById(request.userId())
.orElseThrow(() -> new IllegalArgumentException("Mentor not found with id: " + request.userId()));
mentor.updateProfileImage(profileImage);
mentorRepository.save(mentor);
}
return uploadedFilePath;
return s3Service.uploadFile(request.file(), folderPath);
}

// 증명서 폴더 경로 생성 (멘티용)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package es.princip.ringus.presentation.common.dto;

import es.princip.ringus.infra.storage.domain.ProfileImage;
import jakarta.validation.constraints.NotBlank;

public record ProfileImageRequest(
@NotBlank String fileName,
@NotBlank String filePath
) {
public ProfileImage toEntity() {
return ProfileImage.builder()
.fileName(fileName)
.filePath(filePath)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,27 @@
package es.princip.ringus.presentation.mentee;

import es.princip.ringus.application.mentee.service.MenteeService;
import es.princip.ringus.global.util.ApiResponseWrapper;
import es.princip.ringus.presentation.mentee.dto.MenteeRequest;
import es.princip.ringus.presentation.mentee.dto.MenteeResponse;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
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
@RequiredArgsConstructor
@RequestMapping("/mentee")
public class MenteeController {
private final MenteeService menteeService;

@PostMapping
public ResponseEntity<ApiResponseWrapper<MenteeResponse>> create(@Valid @RequestBody MenteeRequest request) {
MenteeResponse response = MenteeResponse.from(menteeService.register(request));
return ResponseEntity.ok(ApiResponseWrapper.success(HttpStatus.OK, "성공", response));
}
}
Original file line number Diff line number Diff line change
@@ -1,21 +1,23 @@
package es.princip.ringus.presentation.mentee.dto;

import es.princip.ringus.domain.mentee.EducationLevelType;
import es.princip.ringus.domain.mentee.Mentee;
import es.princip.ringus.domain.common.Education;
import es.princip.ringus.presentation.common.dto.EducationRequest;
import es.princip.ringus.presentation.common.dto.ProfileImageRequest;
import jakarta.validation.constraints.NotBlank;

public record MenteeRequest(
@NotBlank String email,
@NotBlank String nickname,
EducationRequest education,
ProfileImageRequest image,
@NotBlank String introduction
) {
public Mentee toEntity() {
return Mentee.builder()
.nickname(nickname)
.education(new Education(education.schoolName(), education().major()))
.profileImage(image.toEntity())
.introduction(introduction)
.build();
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
package es.princip.ringus.presentation.mentee.dto;

public record MenteeResponse(

Long menteeId
) {
public static MenteeResponse from(Long menteeId) {
return new MenteeResponse(menteeId);
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package es.princip.ringus.presentation.mentor.dto;

public record MentorResponse(
Long mentorId
Long mentorId
) {
public static MentorResponse from(Long mentorId) {
return new MentorResponse(mentorId);
Expand Down
Loading