Skip to content
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

[DDING-66] ClubMember 목록 조회 API 응답값 변경 #201

Merged
merged 2 commits into from
Jan 8, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,9 @@
import ddingdong.ddingdongBE.common.exception.ErrorResponse;
import ddingdong.ddingdongBE.domain.club.controller.dto.request.UpdateClubInfoRequest;
import ddingdong.ddingdongBE.domain.club.controller.dto.request.UpdateClubMemberRequest;
import ddingdong.ddingdongBE.domain.club.controller.dto.response.CentralClubMemberListResponse;
import ddingdong.ddingdongBE.domain.club.controller.dto.response.AllClubMemberInfoResponse;
import ddingdong.ddingdongBE.domain.club.controller.dto.response.MyClubInfoResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Content;
import io.swagger.v3.oas.annotations.media.ExampleObject;
import io.swagger.v3.oas.annotations.media.Schema;
Expand All @@ -16,7 +15,6 @@
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import java.util.List;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
Expand Down Expand Up @@ -54,10 +52,10 @@ public interface CentralClubApi {
@Operation(summary = "동아리원 명단 조회 API")
@ResponseStatus(HttpStatus.OK)
@ApiResponse(responseCode = "200", description = "동아리원 명단 조회 성공",
content = @Content(array = @ArraySchema(schema = @Schema(implementation = CentralClubMemberListResponse.class))))
content = @Content(schema = @Schema(implementation = AllClubMemberInfoResponse.class)))
@SecurityRequirement(name = "AccessToken")
@GetMapping("/club-members")
List<CentralClubMemberListResponse> getMyClubMembers(@AuthenticationPrincipal PrincipalDetails principalDetails);
AllClubMemberInfoResponse getMyClubMembers(@AuthenticationPrincipal PrincipalDetails principalDetails);

@Operation(summary = "내 동아리 정보 수정 API")
@ResponseStatus(HttpStatus.NO_CONTENT)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,16 +4,16 @@
import ddingdong.ddingdongBE.domain.club.api.CentralClubApi;
import ddingdong.ddingdongBE.domain.club.controller.dto.request.UpdateClubInfoRequest;
import ddingdong.ddingdongBE.domain.club.controller.dto.request.UpdateClubMemberRequest;
import ddingdong.ddingdongBE.domain.club.controller.dto.response.CentralClubMemberListResponse;
import ddingdong.ddingdongBE.domain.club.controller.dto.response.AllClubMemberInfoResponse;
import ddingdong.ddingdongBE.domain.club.controller.dto.response.MyClubInfoResponse;
import ddingdong.ddingdongBE.domain.club.service.FacadeCentralClubService;
import ddingdong.ddingdongBE.domain.club.service.dto.query.MyClubInfoQuery;
import ddingdong.ddingdongBE.domain.clubmember.service.FacadeCentralClubMemberService;
import ddingdong.ddingdongBE.domain.clubmember.service.dto.command.UpdateClubMemberListCommand;
import ddingdong.ddingdongBE.domain.clubmember.service.dto.query.AllClubMemberInfoQuery;
import ddingdong.ddingdongBE.domain.user.entity.User;
import java.net.URLEncoder;
import java.nio.charset.StandardCharsets;
import java.util.List;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.http.HttpHeaders;
Expand Down Expand Up @@ -54,11 +54,10 @@ public MyClubInfoResponse getMyClub(PrincipalDetails principalDetails) {
}

@Override
public List<CentralClubMemberListResponse> getMyClubMembers(PrincipalDetails principalDetails) {
public AllClubMemberInfoResponse getMyClubMembers(PrincipalDetails principalDetails) {
User user = principalDetails.getUser();
return facadeCentralClubMemberService.getAllMyClubMember(user.getId()).stream()
.map(CentralClubMemberListResponse::from)
.toList();
AllClubMemberInfoQuery query = facadeCentralClubMemberService.getAllMyClubMember(user.getId());
return AllClubMemberInfoResponse.from(query);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
package ddingdong.ddingdongBE.domain.club.controller.dto.response;

import ddingdong.ddingdongBE.domain.clubmember.entity.ClubMember;
import ddingdong.ddingdongBE.domain.clubmember.service.dto.query.AllClubMemberInfoQuery;
import io.swagger.v3.oas.annotations.media.ArraySchema;
import io.swagger.v3.oas.annotations.media.Schema;
import java.util.List;

public record AllClubMemberInfoResponse(
@Schema(name = "동아리명", example = "COW")
String clubName,
@ArraySchema(schema = @Schema(implementation = ClubMemberListResponse.class))
List<ClubMemberListResponse> clubMembers
) {

public static AllClubMemberInfoResponse from(AllClubMemberInfoQuery query) {
List<ClubMemberListResponse> responses = query.clubMembers().stream()
.map(ClubMemberListResponse::from)
.toList();
return new AllClubMemberInfoResponse(query.clubName(), responses);
}

@Schema(
name = "ClubMemberResponse",
description = "중앙동아리 - 동아리원 조회 응답"
)
record ClubMemberListResponse(
@Schema(description = "식별자", example = "1")
Long id,
@Schema(description = "이름", example = "홍길동")
String name,
@Schema(description = "학번", example = "60001111")
String studentNumber,
@Schema(description = "전화번호", example = "010-1234-5678")
String phoneNumber,
@Schema(description = "동아리원 역할",
example = "LEADER",
allowableValues = {"LEADER", "EXECUTION", "MEMBER"}
)
String position,
Comment on lines +36 to +40
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

Position 필드를 enum으로 변경하는 것이 좋겠습니다.

현재 position 필드가 String으로 되어있는데, 허용 가능한 값이 제한적이므로 enum을 사용하는 것이 타입 안전성을 보장할 수 있습니다.

public enum ClubMemberPosition {
    LEADER, EXECUTION, MEMBER
}

그리고 다음과 같이 변경하세요:

-    String position,
+    ClubMemberPosition position,

@Schema(description = "학과", example = "학과")
String department
) {

public static ClubMemberListResponse from(ClubMember clubMember) {
return new ClubMemberListResponse(
clubMember.getId(),
clubMember.getName(),
clubMember.getStudentNumber(),
clubMember.getPhoneNumber(),
clubMember.getPosition().getName(),
clubMember.getDepartment()
);
}
Comment on lines +45 to +54
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🛠️ Refactor suggestion

from 메서드에서 position 매핑 로직 개선이 필요합니다.

position 값을 가져올 때 getName()을 호출하고 있는데, enum으로 변경 후에는 직접 enum 값으로 매핑하는 것이 좋겠습니다.

-    clubMember.getPosition().getName(),
+    clubMember.getPosition(),

Committable suggestion skipped: line range outside the PR's diff.


}
}

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@

import ddingdong.ddingdongBE.domain.clubmember.service.dto.command.UpdateClubMemberCommand;
import ddingdong.ddingdongBE.domain.clubmember.service.dto.command.UpdateClubMemberListCommand;
import ddingdong.ddingdongBE.domain.clubmember.service.dto.query.CentralClubMemberListQuery;
import java.util.List;
import ddingdong.ddingdongBE.domain.clubmember.service.dto.query.AllClubMemberInfoQuery;

public interface FacadeCentralClubMemberService {

byte[] getClubMemberListFile(Long userId);

List<CentralClubMemberListQuery> getAllMyClubMember(Long userId);
AllClubMemberInfoQuery getAllMyClubMember(Long userId);

void updateMemberList(UpdateClubMemberListCommand command);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import ddingdong.ddingdongBE.domain.clubmember.entity.ClubMember;
import ddingdong.ddingdongBE.domain.clubmember.service.dto.command.UpdateClubMemberCommand;
import ddingdong.ddingdongBE.domain.clubmember.service.dto.command.UpdateClubMemberListCommand;
import ddingdong.ddingdongBE.domain.clubmember.service.dto.query.CentralClubMemberListQuery;
import ddingdong.ddingdongBE.domain.clubmember.service.dto.query.AllClubMemberInfoQuery;
import ddingdong.ddingdongBE.file.service.ExcelFileService;
import java.util.HashSet;
import java.util.List;
Expand All @@ -31,11 +31,9 @@ public byte[] getClubMemberListFile(Long userId) {
}

@Override
public List<CentralClubMemberListQuery> getAllMyClubMember(Long userId) {
public AllClubMemberInfoQuery getAllMyClubMember(Long userId) {
Club club = clubService.getByUserId(userId);
return club.getClubMembers().stream()
.map(CentralClubMemberListQuery::from)
.toList();
return AllClubMemberInfoQuery.of(club.getName(), club.getClubMembers());
}

@Override
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package ddingdong.ddingdongBE.domain.clubmember.service.dto.query;

import ddingdong.ddingdongBE.domain.clubmember.entity.ClubMember;
import java.util.List;

public record AllClubMemberInfoQuery(
String clubName,
List<ClubMember> clubMembers
) {

public static AllClubMemberInfoQuery of(String clubName, List<ClubMember> clubMembers) {
return new AllClubMemberInfoQuery(clubName, clubMembers);
}
}

This file was deleted.

Loading