From ea7fa58527e776a9534896e7ce0f0acc96686be9 Mon Sep 17 00:00:00 2001 From: 5uhwann <106325839+5uhwann@users.noreply.github.com> Date: Fri, 25 Oct 2024 17:35:44 +0900 Subject: [PATCH] =?UTF-8?q?[DDOING-000]=20=EB=8F=99=EC=95=84=EB=A6=AC?= =?UTF-8?q?=EC=9B=90=20=EB=AA=85=EB=8B=A8=20=EC=A1=B0=ED=9A=8C=20API=20?= =?UTF-8?q?=EB=B6=84=EB=A6=AC=20(#157)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../domain/club/api/CentralClubApi.java | 11 +++++ .../controller/CentralClubController.java | 19 +++++--- .../CentralClubMemberListResponse.java | 39 ++++++++++++++++ .../dto/response/MyClubInfoResponse.java | 44 +------------------ ...va => FacadeCentralClubMemberService.java} | 6 ++- ...> FacadeCentralClubMemberServiceImpl.java} | 11 ++++- .../dto/query/CentralClubMemberListQuery.java | 25 +++++++++++ ...> FacadeCentralClubMemberServiceTest.java} | 9 ++-- 8 files changed, 110 insertions(+), 54 deletions(-) create mode 100644 src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/response/CentralClubMemberListResponse.java rename src/main/java/ddingdong/ddingdongBE/domain/clubmember/service/{FacadeClubMemberService.java => FacadeCentralClubMemberService.java} (64%) rename src/main/java/ddingdong/ddingdongBE/domain/clubmember/service/{FacadeClubMemberServiceImpl.java => FacadeCentralClubMemberServiceImpl.java} (87%) create mode 100644 src/main/java/ddingdong/ddingdongBE/domain/clubmember/service/dto/query/CentralClubMemberListQuery.java rename src/test/java/ddingdong/ddingdongBE/domain/clubmember/service/{FacadeClubMemberServiceTest.java => FacadeCentralClubMemberServiceTest.java} (95%) diff --git a/src/main/java/ddingdong/ddingdongBE/domain/club/api/CentralClubApi.java b/src/main/java/ddingdong/ddingdongBE/domain/club/api/CentralClubApi.java index 513070ad..f9fc9770 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/club/api/CentralClubApi.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/club/api/CentralClubApi.java @@ -4,8 +4,10 @@ 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.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; @@ -14,6 +16,7 @@ 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; @@ -48,6 +51,14 @@ public interface CentralClubApi { @GetMapping MyClubInfoResponse getMyClub(@AuthenticationPrincipal PrincipalDetails principalDetails); + @Operation(summary = "동아리원 명단 조회 API") + @ResponseStatus(HttpStatus.OK) + @ApiResponse(responseCode = "200", description = "동아리원 명단 조회 성공", + content = @Content(array = @ArraySchema(schema = @Schema(implementation = CentralClubMemberListResponse.class)))) + @SecurityRequirement(name = "AccessToken") + @GetMapping("/club-members") + List getMyClubMembers(@AuthenticationPrincipal PrincipalDetails principalDetails); + @Operation(summary = "내 동아리 정보 수정 API") @ResponseStatus(HttpStatus.NO_CONTENT) @ApiResponse(responseCode = "204", description = "내 동아리 정보 수정 성공") diff --git a/src/main/java/ddingdong/ddingdongBE/domain/club/controller/CentralClubController.java b/src/main/java/ddingdong/ddingdongBE/domain/club/controller/CentralClubController.java index 37890e92..f1919b7f 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/club/controller/CentralClubController.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/club/controller/CentralClubController.java @@ -4,10 +4,11 @@ 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.MyClubInfoResponse; import ddingdong.ddingdongBE.domain.club.service.FacadeCentralClubService; import ddingdong.ddingdongBE.domain.club.service.dto.query.MyClubInfoQuery; -import ddingdong.ddingdongBE.domain.clubmember.service.FacadeClubMemberService; +import ddingdong.ddingdongBE.domain.clubmember.service.FacadeCentralClubMemberService; import ddingdong.ddingdongBE.domain.clubmember.service.dto.command.UpdateClubMemberListCommand; import ddingdong.ddingdongBE.domain.user.entity.User; import java.net.URLEncoder; @@ -27,12 +28,12 @@ public class CentralClubController implements CentralClubApi { private final FacadeCentralClubService facadeCentralClubService; - private final FacadeClubMemberService facadeClubMemberService; + private final FacadeCentralClubMemberService facadeCentralClubMemberService; @Override public ResponseEntity getMyClubMemberListFile(PrincipalDetails principalDetails) { User user = principalDetails.getUser(); - byte[] clubMemberListFileData = facadeClubMemberService.getClubMemberListFile(user.getId()); + byte[] clubMemberListFileData = facadeCentralClubMemberService.getClubMemberListFile(user.getId()); String filename = "동아리원명단.xlsx"; String encodedFilename = URLEncoder.encode(filename, StandardCharsets.UTF_8).replaceAll("\\+", "%20"); @@ -52,6 +53,14 @@ public MyClubInfoResponse getMyClub(PrincipalDetails principalDetails) { return MyClubInfoResponse.from(query); } + @Override + public List getMyClubMembers(PrincipalDetails principalDetails) { + User user = principalDetails.getUser(); + return facadeCentralClubMemberService.getAllMyClubMember(user.getId()).stream() + .map(CentralClubMemberListResponse::from) + .toList(); + } + @Override public void updateClub(PrincipalDetails principalDetails, UpdateClubInfoRequest request) { User user = principalDetails.getUser(); @@ -65,11 +74,11 @@ public void updateClubMemberList(PrincipalDetails principalDetails, MultipartFil .userId(user.getId()) .clubMemberListFile(clubMemberListFile) .build(); - facadeClubMemberService.updateMemberList(command); + facadeCentralClubMemberService.updateMemberList(command); } @Override public void updateClubMembers(Long clubMemberId, UpdateClubMemberRequest request) { - facadeClubMemberService.update(request.toCommand(clubMemberId)); + facadeCentralClubMemberService.update(request.toCommand(clubMemberId)); } } diff --git a/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/response/CentralClubMemberListResponse.java b/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/response/CentralClubMemberListResponse.java new file mode 100644 index 00000000..28a512a2 --- /dev/null +++ b/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/response/CentralClubMemberListResponse.java @@ -0,0 +1,39 @@ +package ddingdong.ddingdongBE.domain.club.controller.dto.response; + +import ddingdong.ddingdongBE.domain.clubmember.service.dto.query.CentralClubMemberListQuery; +import io.swagger.v3.oas.annotations.media.Schema; + +@Schema( + name = "ClubMemberResponse", + description = "중앙동아리 - 동아리원 조회 응답" +) +public record CentralClubMemberListResponse( + @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 CentralClubMemberListResponse from(CentralClubMemberListQuery query) { + return new CentralClubMemberListResponse( + query.id(), + query.name(), + query.studentNumber(), + query.phoneNumber(), + query.position(), + query.department() + ); + } + +} diff --git a/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/response/MyClubInfoResponse.java b/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/response/MyClubInfoResponse.java index 57a7c964..1781f498 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/response/MyClubInfoResponse.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/club/controller/dto/response/MyClubInfoResponse.java @@ -2,11 +2,9 @@ import com.fasterxml.jackson.annotation.JsonFormat; import ddingdong.ddingdongBE.domain.club.service.dto.query.MyClubInfoQuery; -import ddingdong.ddingdongBE.domain.clubmember.entity.ClubMember; import ddingdong.ddingdongBE.file.service.dto.query.UploadedFileUrlQuery; import io.swagger.v3.oas.annotations.media.Schema; import java.time.LocalDateTime; -import java.util.List; @Schema( name = "MyClubInfoResponse", @@ -43,8 +41,7 @@ public record MyClubInfoResponse( String formUrl, @Schema(description = "동아리 프로필 이미지 Url", example = "url") MyClubInfoImageUrlResponse profileImageUrl, - MyClubInfoImageUrlResponse introduceImageUrl, - List clubMembers + MyClubInfoImageUrlResponse introductionImageUrl ) { public static MyClubInfoResponse from(MyClubInfoQuery query) { @@ -63,10 +60,7 @@ public static MyClubInfoResponse from(MyClubInfoQuery query) { query.ideal(), query.formUrl(), MyClubInfoImageUrlResponse.from(query.profileImageUrlQuery()), - MyClubInfoImageUrlResponse.from(query.introductionImageUrlQuery()), - query.clubMembers().stream() - .map(ClubMemberResponse::from) - .toList() + MyClubInfoImageUrlResponse.from(query.introductionImageUrlQuery()) ); } @@ -90,38 +84,4 @@ public static MyClubInfoImageUrlResponse from(UploadedFileUrlQuery query) { } - @Schema( - name = "ClubMemberResponse", - description = "중앙동아리 - 동아리원 조회 응답" - ) - public record ClubMemberResponse( - @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(ClubMember clubMember) { - return new ClubMemberResponse( - clubMember.getId(), - clubMember.getName(), - clubMember.getStudentNumber(), - clubMember.getPhoneNumber(), - clubMember.getPosition().getName(), - clubMember.getDepartment() - ); - } - } - } diff --git a/src/main/java/ddingdong/ddingdongBE/domain/clubmember/service/FacadeClubMemberService.java b/src/main/java/ddingdong/ddingdongBE/domain/clubmember/service/FacadeCentralClubMemberService.java similarity index 64% rename from src/main/java/ddingdong/ddingdongBE/domain/clubmember/service/FacadeClubMemberService.java rename to src/main/java/ddingdong/ddingdongBE/domain/clubmember/service/FacadeCentralClubMemberService.java index 48d964b0..28a8b3b6 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/clubmember/service/FacadeClubMemberService.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/clubmember/service/FacadeCentralClubMemberService.java @@ -2,11 +2,15 @@ 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; -public interface FacadeClubMemberService { +public interface FacadeCentralClubMemberService { byte[] getClubMemberListFile(Long userId); + List getAllMyClubMember(Long userId); + void updateMemberList(UpdateClubMemberListCommand command); void update(UpdateClubMemberCommand updateClubMemberCommand); diff --git a/src/main/java/ddingdong/ddingdongBE/domain/clubmember/service/FacadeClubMemberServiceImpl.java b/src/main/java/ddingdong/ddingdongBE/domain/clubmember/service/FacadeCentralClubMemberServiceImpl.java similarity index 87% rename from src/main/java/ddingdong/ddingdongBE/domain/clubmember/service/FacadeClubMemberServiceImpl.java rename to src/main/java/ddingdong/ddingdongBE/domain/clubmember/service/FacadeCentralClubMemberServiceImpl.java index 467db29b..4feb318c 100644 --- a/src/main/java/ddingdong/ddingdongBE/domain/clubmember/service/FacadeClubMemberServiceImpl.java +++ b/src/main/java/ddingdong/ddingdongBE/domain/clubmember/service/FacadeCentralClubMemberServiceImpl.java @@ -5,6 +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.file.service.ExcelFileService; import java.util.HashSet; import java.util.List; @@ -17,7 +18,7 @@ @Service @Transactional(readOnly = true) @RequiredArgsConstructor -public class FacadeClubMemberServiceImpl implements FacadeClubMemberService { +public class FacadeCentralClubMemberServiceImpl implements FacadeCentralClubMemberService { private final ClubService clubService; private final ClubMemberService clubMemberService; @@ -29,6 +30,14 @@ public byte[] getClubMemberListFile(Long userId) { return excelFileService.generateClubMemberListFile(club.getClubMembers()); } + @Override + public List getAllMyClubMember(Long userId) { + Club club = clubService.getByUserId(userId); + return club.getClubMembers().stream() + .map(CentralClubMemberListQuery::from) + .toList(); + } + @Override @Transactional public void updateMemberList(UpdateClubMemberListCommand command) { diff --git a/src/main/java/ddingdong/ddingdongBE/domain/clubmember/service/dto/query/CentralClubMemberListQuery.java b/src/main/java/ddingdong/ddingdongBE/domain/clubmember/service/dto/query/CentralClubMemberListQuery.java new file mode 100644 index 00000000..ffa6fd2f --- /dev/null +++ b/src/main/java/ddingdong/ddingdongBE/domain/clubmember/service/dto/query/CentralClubMemberListQuery.java @@ -0,0 +1,25 @@ +package ddingdong.ddingdongBE.domain.clubmember.service.dto.query; + +import ddingdong.ddingdongBE.domain.clubmember.entity.ClubMember; + +public record CentralClubMemberListQuery( + Long id, + String name, + String studentNumber, + String phoneNumber, + String position, + String department +) { + + public static CentralClubMemberListQuery from(ClubMember clubMember){ + return new CentralClubMemberListQuery( + clubMember.getId(), + clubMember.getName(), + clubMember.getStudentNumber(), + clubMember.getPhoneNumber(), + clubMember.getPosition().getName(), + clubMember.getDepartment() + ); + } + +} diff --git a/src/test/java/ddingdong/ddingdongBE/domain/clubmember/service/FacadeClubMemberServiceTest.java b/src/test/java/ddingdong/ddingdongBE/domain/clubmember/service/FacadeCentralClubMemberServiceTest.java similarity index 95% rename from src/test/java/ddingdong/ddingdongBE/domain/clubmember/service/FacadeClubMemberServiceTest.java rename to src/test/java/ddingdong/ddingdongBE/domain/clubmember/service/FacadeCentralClubMemberServiceTest.java index 0707c409..40d2fbc9 100644 --- a/src/test/java/ddingdong/ddingdongBE/domain/clubmember/service/FacadeClubMemberServiceTest.java +++ b/src/test/java/ddingdong/ddingdongBE/domain/clubmember/service/FacadeCentralClubMemberServiceTest.java @@ -30,14 +30,13 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.boot.test.context.SpringBootTest; import org.springframework.mock.web.MockMultipartFile; -import org.springframework.transaction.annotation.Transactional; import org.springframework.web.multipart.MultipartFile; @SpringBootTest -class FacadeClubMemberServiceTest extends TestContainerSupport { +class FacadeCentralClubMemberServiceTest extends TestContainerSupport { @Autowired - private FacadeClubMemberService facadeClubMemberService; + private FacadeCentralClubMemberService facadeCentralClubMemberService; @Autowired private UserRepository userRepository; @Autowired @@ -113,7 +112,7 @@ void updateClubMemberList() throws IOException { .build(); //when - facadeClubMemberService.updateMemberList(command); + facadeCentralClubMemberService.updateMemberList(command); //then List updatedClubMemberList = clubMemberRepository.findAll(); @@ -145,7 +144,7 @@ void update() { .department("test").build(); //when - facadeClubMemberService.update(command); + facadeCentralClubMemberService.update(command); //then ClubMember updatedClubMember = clubMemberService.getById(savedClubMember.getId());