-
Notifications
You must be signed in to change notification settings - Fork 0
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
[FEAT/#71] 내 프로필 조회 API 구현 #72
Changes from 4 commits
2043b02
372426b
3949c1c
dfa3499
1d3e024
cdc2136
8d4e920
d9ec997
b45eb1b
d0498ab
6ec4de5
1b17944
1702792
ec3adef
5c6a704
fab7583
5fa0dcc
6f5d031
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
package com.acon.server.member.api.response; | ||
|
||
import com.fasterxml.jackson.annotation.JsonInclude; | ||
import com.fasterxml.jackson.annotation.JsonInclude.Include; | ||
import java.util.List; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
@JsonInclude(Include.NON_NULL) | ||
public record ProfileResponse( | ||
String image, | ||
String nickname, | ||
int leftAcornCount, | ||
String birthDate, | ||
List<VerifiedArea> verifiedArea | ||
) { | ||
|
||
public record VerifiedArea( | ||
Long id, | ||
String name | ||
) { | ||
|
||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,6 +8,7 @@ | |
import com.acon.server.global.external.NaverMapsAdapter; | ||
import com.acon.server.member.api.response.AcornCountResponse; | ||
import com.acon.server.member.api.response.LoginResponse; | ||
import com.acon.server.member.api.response.ProfileResponse; | ||
import com.acon.server.member.application.mapper.GuidedSpotMapper; | ||
import com.acon.server.member.application.mapper.MemberMapper; | ||
import com.acon.server.member.application.mapper.PreferenceMapper; | ||
|
@@ -37,6 +38,7 @@ | |
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
@@ -89,31 +91,23 @@ public LoginResponse login( | |
return LoginResponse.of(accessToken, refreshToken); | ||
} | ||
|
||
private boolean isExistingMember( | ||
final SocialType socialType, | ||
final String socialId | ||
) { | ||
return memberRepository.findBySocialTypeAndSocialId(socialType, socialId).isPresent(); | ||
} | ||
|
||
protected Long fetchMemberId( | ||
final SocialType socialType, | ||
final String socialId | ||
) { | ||
MemberEntity memberEntity; | ||
|
||
if (isExistingMember(socialType, socialId)) { | ||
memberEntity = memberRepository.findBySocialTypeAndSocialId( | ||
socialType, | ||
socialId | ||
).orElse(null); | ||
} else { | ||
memberEntity = memberRepository.save(MemberEntity.builder() | ||
.socialType(socialType) | ||
.socialId(socialId) | ||
.leftAcornCount(25) | ||
.build()); | ||
} | ||
Optional<MemberEntity> optionalMemberEntity = memberRepository.findBySocialTypeAndSocialId(socialType, | ||
socialId); | ||
MemberEntity memberEntity = optionalMemberEntity.orElseGet(() -> | ||
memberRepository.save(MemberEntity.builder() | ||
.socialType(socialType) | ||
.socialId(socialId) | ||
.leftAcornCount(25) | ||
// TODO: 닉네임 생성 방식 변경 | ||
.nickname(UUID.randomUUID().toString()) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P1:
다른 방식으로 닉네임을 할당해야 할 것 같아요 ~! 해당 부분은 TODO로 남겨주시면 프로필 수정 API 구현 때 제가 수정해 보겠습니다 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 감사합니다! |
||
// TODO: 기본 이미지 구현 전까지 임의로 이미지 할당 | ||
.profileImage("https://avatars.githubusercontent.com/u/81469686?v=4") | ||
.build()) | ||
); | ||
|
||
Member member = memberMapper.toDomain(memberEntity); | ||
|
||
|
@@ -216,5 +210,23 @@ public AcornCountResponse fetchAcornCount() { | |
return new AcornCountResponse(acornCount); | ||
} | ||
|
||
@Transactional(readOnly = true) | ||
public ProfileResponse fetchProfile() { | ||
MemberEntity memberEntity = memberRepository.findByIdOrElseThrow(principalHandler.getUserIdFromPrincipal()); | ||
List<VerifiedAreaEntity> verifiedAreaEntityList = verifiedAreaRepository.findAllByMemberId( | ||
memberEntity.getId()); | ||
|
||
return ProfileResponse.builder(). | ||
image(memberEntity.getProfileImage()) | ||
.nickname(memberEntity.getNickname()) | ||
.birthDate(memberEntity.getBirthDate() != null ? memberEntity.getBirthDate().toString() : null) | ||
.leftAcornCount(memberEntity.getLeftAcornCount()) | ||
.verifiedArea(verifiedAreaEntityList.stream() | ||
.map(verifiedAreaEntity -> new ProfileResponse.VerifiedArea(verifiedAreaEntity.getId(), | ||
verifiedAreaEntity.getName())) | ||
.toList()) | ||
.build(); | ||
} | ||
|
||
// TODO: 최근 길 안내 장소 지우는 스케줄러 추가 | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P5:
좋은 리팩토링이네요 👍