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 1 commit
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,21 @@
package ddingdong.ddingdongBE.domain.club.controller.dto.response;

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.clubMemberListQueries().stream()
.map(ClubMemberListResponse::from)
.toList();
return new AllClubMemberInfoResponse(query.clubName(), responses);
}
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

p3)
별도의 클래스로 분리하지 말고 하나의 이너 클래스로 두어 관리하는건 어떨까요?

Suggested change
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.clubMemberListQueries().stream()
.map(ClubMemberListResponse::from)
.toList();
return new AllClubMemberInfoResponse(query.clubName(), responses);
}
}
public record ClubMemberListResponse(
@Schema(name = "동아리명", example = "COW")
String clubName,
@ArraySchema(schema = @Schema(implementation = ClubMemberListResponse.class))
List<ClubMemberResponse> clubMembers
) {
public static AllClubMemberInfoResponse from(AllClubMemberInfoQuery query) {
List<ClubMemberListResponse> responses = query.clubMemberListQueries().stream()
.map(ClubMemberResponse::from)
.toList();
return new ClubMemberListResponse(query.clubName(), responses);
}
@Schema(
name = "ClubMemberResponse",
description = "중앙동아리 - 동아리원 정보 조회 응답"
)
public 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,
@Schema(description = "학과", example = "학과")
String department
) {
public static ClubMemberResponse from(ClubMemberListQuery query) {
return new ClubMemberListResponse(
query.id(),
query.name(),
query.studentNumber(),
query.phoneNumber(),
query.position(),
query.department()
);
}
}
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

수정 완료하였습니다!
56d8d84

Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
package ddingdong.ddingdongBE.domain.club.controller.dto.response;

import ddingdong.ddingdongBE.domain.clubmember.service.dto.query.CentralClubMemberListQuery;
import ddingdong.ddingdongBE.domain.clubmember.service.dto.query.ClubMemberListQuery;
import io.swagger.v3.oas.annotations.media.Schema;

@Schema(
name = "ClubMemberResponse",
description = "중앙동아리 - 동아리원 조회 응답"
)
public record CentralClubMemberListResponse(
public record ClubMemberListResponse(
@Schema(description = "식별자", example = "1")
Long id,
@Schema(description = "이름", example = "홍길동")
Expand All @@ -25,8 +25,8 @@ public record CentralClubMemberListResponse(
String department
) {

public static CentralClubMemberListResponse from(CentralClubMemberListQuery query) {
return new CentralClubMemberListResponse(
public static ClubMemberListResponse from(ClubMemberListQuery query) {
return new ClubMemberListResponse(
query.id(),
query.name(),
query.studentNumber(),
Expand Down
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,8 @@
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.domain.clubmember.service.dto.query.ClubMemberListQuery;
import ddingdong.ddingdongBE.file.service.ExcelFileService;
import java.util.HashSet;
import java.util.List;
Expand All @@ -31,11 +32,12 @@ 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();
List<ClubMemberListQuery> clubMemberListQueries = club.getClubMembers().stream()
.map(ClubMemberListQuery::from)
.toList();
return AllClubMemberInfoQuery.of(club.getName(), clubMemberListQueries);
}

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

import java.util.List;

public record AllClubMemberInfoQuery(
String clubName,
List<ClubMemberListQuery> clubMemberListQueries
) {

public static AllClubMemberInfoQuery of(String clubName, List<ClubMemberListQuery> clubMemberListQueries) {
return new AllClubMemberInfoQuery(clubName, clubMemberListQueries);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

import ddingdong.ddingdongBE.domain.clubmember.entity.ClubMember;

public record CentralClubMemberListQuery(
public record ClubMemberListQuery(
Long id,
String name,
String studentNumber,
Expand All @@ -11,8 +11,8 @@ public record CentralClubMemberListQuery(
String department
) {

public static CentralClubMemberListQuery from(ClubMember clubMember){
return new CentralClubMemberListQuery(
public static ClubMemberListQuery from(ClubMember clubMember){
return new ClubMemberListQuery(
clubMember.getId(),
clubMember.getName(),
clubMember.getStudentNumber(),
Expand Down
Loading