Skip to content

Commit

Permalink
Merge pull request #182 from IoTeaTime/feature/181-member-detail
Browse files Browse the repository at this point in the history
feat: 회원 상세 정보 조회 시 그룹 정보도 함께 조회
  • Loading branch information
ywonchae1 authored Nov 27, 2024
2 parents be8ff68 + fe8218b commit 9bb1c19
Show file tree
Hide file tree
Showing 6 changed files with 60 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
import org.ioteatime.meonghanyangserver.group.dto.response.UpdateNicknameAndGroupNameResponse;
import org.ioteatime.meonghanyangserver.member.dto.request.ChangePasswordRequest;
import org.ioteatime.meonghanyangserver.member.dto.request.UpdateNicknameAndGroupNameRequest;
import org.ioteatime.meonghanyangserver.member.dto.response.MemberDetailResponse;
import org.ioteatime.meonghanyangserver.member.dto.response.MemberWithGroupDetailResponse;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
Expand All @@ -17,7 +17,7 @@
public interface MemberApi {

@Operation(summary = "회원 상세 정보를 조회합니다.", description = "담당자: 임지인")
Api<MemberDetailResponse> getMemberDetail(@PathVariable("memberId") Long memberId);
Api<MemberWithGroupDetailResponse> getMemberDetail(@PathVariable("memberId") Long memberId);

@Operation(summary = "회원 정보를 삭제합니다.", description = "담당자: 임지인")
Api<Object> deleteMember(@LoginMember Long memberId);
Expand All @@ -35,7 +35,4 @@ Api<Object> changeMemberPassword(
"담당자: 양원채\n\n닉네임 또는 그룹명을 갱신할 수 있으며, 한꺼번에 갱신도 가능합니다.\n\n갱신하고 싶지 않은 필드는 아예 적지 않거나 null로 담아 요청하시면 됩니다. 응답으로는 변경된 사항만 응답합니다.")
Api<UpdateNicknameAndGroupNameResponse> updateNicknameAndGroupName(
@LoginMember Long memberId, @RequestBody UpdateNicknameAndGroupNameRequest request);

@Operation(summary = "로그아웃을 진행합니다.", description = "담당자: 최민석")
Api<?> logout();
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
import org.ioteatime.meonghanyangserver.group.dto.response.UpdateNicknameAndGroupNameResponse;
import org.ioteatime.meonghanyangserver.member.dto.request.ChangePasswordRequest;
import org.ioteatime.meonghanyangserver.member.dto.request.UpdateNicknameAndGroupNameRequest;
import org.ioteatime.meonghanyangserver.member.dto.response.MemberDetailResponse;
import org.ioteatime.meonghanyangserver.member.dto.response.MemberWithGroupDetailResponse;
import org.ioteatime.meonghanyangserver.member.service.MemberService;
import org.springframework.web.bind.annotation.*;

Expand All @@ -21,8 +21,9 @@ public class MemberController implements MemberApi {
private final MemberService memberService;

@GetMapping("/{memberId}")
public Api<MemberDetailResponse> getMemberDetail(@PathVariable("memberId") Long memberId) {
MemberDetailResponse userDto = memberService.getMemberDetail(memberId);
public Api<MemberWithGroupDetailResponse> getMemberDetail(
@PathVariable("memberId") Long memberId) {
MemberWithGroupDetailResponse userDto = memberService.getMemberDetail(memberId);
return Api.success(AuthSuccessType.GET_USER_DETAIL, userDto);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.ioteatime.meonghanyangserver.member.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import org.ioteatime.meonghanyangserver.group.domain.GroupEntity;

@Schema(description = "그룹의 상세 정보 조회")
public record GroupDetailResponse(
@NotNull @Schema(description = "그룹 ID", example = "1") Long id,
@NotNull @Schema(description = "그룹 이름", example = "멍하냥 그룹") String groupName) {
public static GroupDetailResponse from(GroupEntity group) {
return new GroupDetailResponse(group.getId(), group.getGroupName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.ioteatime.meonghanyangserver.member.dto.response;

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import lombok.Builder;

@Schema(description = "회원 및 그룹 정보 조회")
public record MemberWithGroupDetailResponse(
@NotNull @Schema(description = "회원 정보") MemberDetailResponse member,
@Schema(description = "그룹 정보") GroupDetailResponse group) {
@Builder
public MemberWithGroupDetailResponse(MemberDetailResponse member, GroupDetailResponse group) {
this.member = member;
this.group = group;
}
}
Original file line number Diff line number Diff line change
@@ -1,11 +1,21 @@
package org.ioteatime.meonghanyangserver.member.mapper;

import org.ioteatime.meonghanyangserver.group.domain.GroupEntity;
import org.ioteatime.meonghanyangserver.member.domain.MemberEntity;
import org.ioteatime.meonghanyangserver.member.dto.response.GroupDetailResponse;
import org.ioteatime.meonghanyangserver.member.dto.response.MemberDetailResponse;
import org.ioteatime.meonghanyangserver.member.dto.response.MemberWithGroupDetailResponse;

public class MemberResponseMapper {
public static MemberDetailResponse from(MemberEntity member) {
return new MemberDetailResponse(
member.getId(), member.getEmail(), member.getProfileImgUrl(), member.getNickname());
public static MemberWithGroupDetailResponse from(MemberEntity member, GroupEntity group) {
MemberDetailResponse memberDetail = MemberDetailResponse.from(member);
if (group != null) {
GroupDetailResponse groupDetail = GroupDetailResponse.from(group);
return MemberWithGroupDetailResponse.builder()
.member(memberDetail)
.group(groupDetail)
.build();
}
return MemberWithGroupDetailResponse.builder().member(memberDetail).build();
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package org.ioteatime.meonghanyangserver.member.service;

import java.util.List;
import java.util.Optional;
import lombok.RequiredArgsConstructor;
import org.ioteatime.meonghanyangserver.auth.dto.reponse.RefreshResponse;
import org.ioteatime.meonghanyangserver.auth.mapper.AuthResponseMapper;
Expand All @@ -23,7 +24,7 @@
import org.ioteatime.meonghanyangserver.member.domain.MemberEntity;
import org.ioteatime.meonghanyangserver.member.dto.request.ChangePasswordRequest;
import org.ioteatime.meonghanyangserver.member.dto.request.UpdateNicknameAndGroupNameRequest;
import org.ioteatime.meonghanyangserver.member.dto.response.MemberDetailResponse;
import org.ioteatime.meonghanyangserver.member.dto.response.MemberWithGroupDetailResponse;
import org.ioteatime.meonghanyangserver.member.mapper.MemberResponseMapper;
import org.ioteatime.meonghanyangserver.member.repository.MemberRepository;
import org.ioteatime.meonghanyangserver.redis.AccessTokenRepository;
Expand Down Expand Up @@ -51,13 +52,20 @@ public class MemberService {
private final RefreshTokenRepository refreshTokenRepository;
private final AccessTokenRepository accessTokenRepository;

public MemberDetailResponse getMemberDetail(Long memberId) {
public MemberWithGroupDetailResponse getMemberDetail(Long memberId) {
MemberEntity memberEntity =
memberRepository
.findById(memberId)
.orElseThrow(() -> new NotFoundException(AuthErrorType.NOT_FOUND));

return MemberResponseMapper.from(memberEntity);
Optional<GroupMemberEntity> groupMemberEntity =
groupMemberRepository.findByMemberId(memberId);
GroupEntity groupEntity = null;
if (groupMemberEntity.isPresent()) {
groupEntity = groupMemberEntity.get().getGroup();
}

return MemberResponseMapper.from(memberEntity, groupEntity);
}

// NOTE.
Expand Down

0 comments on commit 9bb1c19

Please sign in to comment.