-
Notifications
You must be signed in to change notification settings - Fork 2
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
#112 마이페이지 조회 API 구현 #113
#112 마이페이지 조회 API 구현 #113
Changes from 2 commits
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,35 @@ | ||
package com.example.aboutme.app.controller; | ||
|
||
import com.example.aboutme.apiPayload.ApiResponse; | ||
import com.example.aboutme.app.dto.MyPageResponse; | ||
import com.example.aboutme.service.MemberService.MemberService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.RequestHeader; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@RestController | ||
@RequestMapping("/mypages") | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class MyPageController { | ||
|
||
private final MemberService memberService; | ||
|
||
/** | ||
* [GET] /mypages | ||
* @param memberId 멤버 식별자 | ||
* @return | ||
*/ | ||
@GetMapping("") | ||
public ApiResponse<MyPageResponse.GetMyPageDTO> getMyPage(@RequestHeader("member-id") Long memberId){ | ||
|
||
MyPageResponse.GetMyPageDTO getMyPageDTO = memberService.getMyPage(memberId); | ||
|
||
log.info("마이페이지 조회: {}", memberId); | ||
|
||
return ApiResponse.onSuccess(getMyPageDTO); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
package com.example.aboutme.app.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
public class MyPageResponse { | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class GetMyPageDTO { | ||
@JsonProperty("my_info") | ||
private MyPageInfo myPageInfo; | ||
|
||
@JsonProperty("insight") | ||
private MyPageInsight myPageInsight; | ||
} | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class MyPageInfo{ | ||
@JsonProperty("profile_name") | ||
private String profileName; | ||
|
||
@JsonProperty("space_name") | ||
private String spaceName; | ||
} | ||
|
||
@Builder | ||
@Getter | ||
@NoArgsConstructor | ||
@AllArgsConstructor | ||
public static class MyPageInsight{ | ||
@JsonProperty("profile_shared_num") | ||
private int profileSharedNum; | ||
|
||
@JsonProperty("space_shared_num") | ||
private int spaceSharedNum; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,10 +1,21 @@ | ||
package com.example.aboutme.repository; | ||
|
||
import com.example.aboutme.domain.Member; | ||
import com.example.aboutme.domain.ProfileFeature; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
import java.util.List; | ||
|
||
public interface ProfileFeatureRepository extends JpaRepository<ProfileFeature, Long> { | ||
List<ProfileFeature> findByProfileKeyAndProfileValueContaining(String profileKey, String profileValue); | ||
|
||
@Query("select pf.profileValue " + | ||
"from Profile p " + | ||
"join ProfileFeature pf on p = pf.profile " + | ||
"where pf.profileKey = 'name' and p.member = :member " + | ||
"order by p.isDefault desc, p.createdAt asc ") | ||
List<String> findProfileFeature(@Param("member") Member member, Pageable pageable); | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,9 +2,12 @@ | |
|
||
import com.example.aboutme.apiPayload.code.status.ErrorStatus; | ||
import com.example.aboutme.apiPayload.exception.GeneralException; | ||
import com.example.aboutme.app.dto.MyPageResponse; | ||
import com.example.aboutme.converter.MemberConverter; | ||
import com.example.aboutme.domain.Member; | ||
import com.example.aboutme.repository.MemberRepository; | ||
import com.example.aboutme.repository.*; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
|
@@ -14,6 +17,9 @@ | |
public class MemberServiceImpl implements MemberService{ | ||
|
||
private final MemberRepository memberRepository; | ||
private final ProfileFeatureRepository profileFeatureRepository; | ||
private final MemberProfileRepository memberProfileRepository; | ||
private final MemberSpaceRepository memberSpaceRepository; | ||
|
||
public Member findMember(Long memberId){ | ||
return memberRepository.findById(memberId).orElseThrow( | ||
|
@@ -26,4 +32,21 @@ public void deleteMember(Long memberId){ | |
findMember(memberId); | ||
memberRepository.deleteById(memberId); | ||
} | ||
|
||
/** | ||
* 마이페이지 조회 | ||
* @param memberId 멤버 식별자 | ||
* @return 마이프로필 정보 | ||
*/ | ||
public MyPageResponse.GetMyPageDTO getMyPage(Long memberId){ | ||
Member member = findMember(memberId); | ||
|
||
String profileName = profileFeatureRepository.findProfileFeature(member, PageRequest.of(0,1)).get(0); | ||
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. Paging하신 이유가 궁금합니다. @query("select pf.profileValue " + 이렇게 페이지네이션 처리없이 조회했을 때와 비교하여 이점이 있는 건가요? 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. 저도 paging으로 처리하고싶진 않았는데, 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. 넵 확인했습니다. 저도 궁금해서 질문드린거라 더 좋은 방법은 모르겠네요😅 |
||
String spaceName = member.getSpace() != null ? member.getSpace().getNickname() : null; | ||
|
||
int profileSharedNum = memberProfileRepository.countSharedProfileByMember(member); | ||
int spaceSharedNum = memberSpaceRepository.countSharedProfileByMember(member); | ||
|
||
return MemberConverter.toGetMyPageDTO(profileName, spaceName, profileSharedNum, spaceSharedNum); | ||
} | ||
} |
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.
혹시 countShared"Profile"ByMember라고 작명하신 이유가 있을까요?
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.
앗! 이건 제가 잘못 작명했습니다! profile -> space로 변경하겠습니다. 꼼꼼한 확인 감사합니당