-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Feature/#15
- Loading branch information
Showing
13 changed files
with
393 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
15 changes: 12 additions & 3 deletions
15
src/main/java/Journey/Together/domain/member/controller/MemberController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,32 @@ | ||
package Journey.Together.domain.member.controller; | ||
|
||
import Journey.Together.domain.member.dto.MemberReq; | ||
import Journey.Together.domain.member.dto.MemberRes; | ||
import Journey.Together.domain.member.service.MemberService; | ||
import Journey.Together.global.common.ApiResponse; | ||
import Journey.Together.global.exception.Success; | ||
import Journey.Together.global.security.PrincipalDetails; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/v1/member") | ||
@Tag(name = "Member", description = "사용자 관련 API") | ||
public class MemberController { | ||
|
||
private final MemberService memberService; | ||
|
||
@PatchMapping ("") | ||
public ApiResponse saveMemberInfo(@AuthenticationPrincipal PrincipalDetails principalDetails, @RequestBody MemberReq memberReq) { | ||
memberService.saveInfo(principalDetails.getMember(),memberReq); | ||
return ApiResponse.success(Success.UPDATE_USER_INFO_SUCCESS); | ||
} | ||
|
||
@GetMapping("") | ||
public ApiResponse<MemberRes> getMember() { | ||
return ApiResponse.success(Success.LOGIN_SUCCESS); | ||
public ApiResponse<MemberRes> findMemberInfo(@AuthenticationPrincipal PrincipalDetails principalDetails){ | ||
MemberRes memberRes = memberService.findMemberInfo(principalDetails.getMember()); | ||
return ApiResponse.success(Success.GET_MYPAGE_SUCCESS,memberRes); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/Journey/Together/domain/member/dto/MemberReq.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package Journey.Together.domain.member.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import jakarta.validation.constraints.Null; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@JsonInclude(JsonInclude.Include.NON_NULL) | ||
public record MemberReq( | ||
@Null | ||
String name, | ||
@Null | ||
String phone, | ||
@Null | ||
MultipartFile profileImage, | ||
@Null | ||
String bloodType, | ||
@Null | ||
String birth, | ||
@Null | ||
String disease, | ||
@Null | ||
String allergy, | ||
@Null | ||
String medication, | ||
@Null | ||
String part1_rel, | ||
@Null | ||
String part1_phone, | ||
@Null | ||
String part2_rel, | ||
@Null | ||
String part2_phone | ||
){ | ||
|
||
} |
37 changes: 36 additions & 1 deletion
37
src/main/java/Journey/Together/domain/member/dto/MemberRes.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,39 @@ | ||
package Journey.Together.domain.member.dto; | ||
|
||
public record MemberRes() { | ||
import Journey.Together.domain.member.entity.Member; | ||
import lombok.Builder; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Builder | ||
public record MemberRes( | ||
String name, | ||
String phone, | ||
String profileImage, | ||
String bloodType, | ||
String birth, | ||
String disease, | ||
String allergy, | ||
String medication, | ||
String part1_rel, | ||
String part1_phone, | ||
String part2_rel, | ||
String part2_phone | ||
) { | ||
public static MemberRes of(Member member,String profileUrl){ | ||
return MemberRes.builder() | ||
.name(member.getName()) | ||
.phone(member.getPhone()) | ||
.profileImage(profileUrl) | ||
.bloodType(member.getBloodType()) | ||
.birth(member.getBirth()) | ||
.disease(member.getDisease()) | ||
.allergy(member.getAllergy()) | ||
.medication(member.getMedication()) | ||
.part1_rel(member.getPart1Rel()) | ||
.part1_phone(member.getPart1Phone()) | ||
.part2_rel(member.getPart2Rel()) | ||
.part2_phone(member.getPart2Phone()) | ||
.build(); | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 0 additions & 5 deletions
5
src/main/java/Journey/Together/domain/member/enumerate/BloodType.java
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
src/main/java/Journey/Together/domain/member/service/MemberService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,16 +1,77 @@ | ||
package Journey.Together.domain.member.service; | ||
|
||
import Journey.Together.domain.member.dto.MemberReq; | ||
import Journey.Together.domain.member.dto.MemberRes; | ||
import Journey.Together.domain.member.entity.Member; | ||
import Journey.Together.domain.member.repository.MemberRepository; | ||
import Journey.Together.global.exception.ApplicationException; | ||
import Journey.Together.global.exception.ErrorCode; | ||
import Journey.Together.global.util.S3Client; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import org.springframework.web.multipart.MultipartFile; | ||
|
||
@Service | ||
@Transactional(readOnly = true) | ||
@RequiredArgsConstructor | ||
public class MemberService { | ||
|
||
private final MemberRepository memberRepository; | ||
private final S3Client s3Client; | ||
|
||
@Transactional | ||
public void saveInfo(Member member,MemberReq memberReq){ | ||
// Validation | ||
memberRepository.findMemberByEmailAndDeletedAtIsNull(member.getEmail()).orElseThrow(()->new ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION)); | ||
//Business | ||
if (memberReq.name() != null) { | ||
member.setName(memberReq.name()); | ||
} | ||
if (memberReq.phone() != null) { | ||
member.setPhone(memberReq.phone()); | ||
} | ||
if (memberReq.profileImage() != null) { | ||
String uuid = s3Client.update(member.getProfileUuid(),memberReq.profileImage()); | ||
member.setProfileUuid(uuid); | ||
} | ||
if (memberReq.bloodType() != null) { | ||
member.setBloodType(memberReq.bloodType()); | ||
} | ||
if (memberReq.birth() != null) { | ||
member.setBirth(memberReq.birth()); | ||
} | ||
if (memberReq.disease() != null) { | ||
member.setDisease(memberReq.disease()); | ||
} | ||
if (memberReq.allergy() != null) { | ||
member.setAllergy(memberReq.allergy()); | ||
} | ||
if (memberReq.medication() != null) { | ||
member.setMedication(memberReq.medication()); | ||
} | ||
if (memberReq.part1_rel() != null) { | ||
member.setPart1Rel(memberReq.part1_rel()); | ||
} | ||
if (memberReq.part1_phone() != null) { | ||
member.setPart1Phone(memberReq.part1_phone()); | ||
} | ||
if (memberReq.part2_rel() != null) { | ||
member.setPart2Rel(memberReq.part2_rel()); | ||
} | ||
if (memberReq.part2_phone() != null) { | ||
member.setPart2Phone(memberReq.part2_phone()); | ||
} | ||
|
||
} | ||
|
||
public MemberRes findMemberInfo(Member member){ | ||
// Validation | ||
memberRepository.findMemberByEmailAndDeletedAtIsNull(member.getEmail()).orElseThrow(()->new ApplicationException(ErrorCode.NOT_FOUND_EXCEPTION)); | ||
//Business | ||
MemberRes memberRes = MemberRes.of(member, s3Client.getUrl()+member.getProfileUuid()); | ||
//Response | ||
return memberRes; | ||
} | ||
|
||
} |
Oops, something went wrong.