Skip to content

Commit

Permalink
[DDOING-000] 동아리원 명단 조회 API 분리 (#157)
Browse files Browse the repository at this point in the history
  • Loading branch information
5uhwann authored Oct 25, 2024
1 parent e104d08 commit ea7fa58
Show file tree
Hide file tree
Showing 8 changed files with 110 additions and 54 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<CentralClubMemberListResponse> getMyClubMembers(@AuthenticationPrincipal PrincipalDetails principalDetails);

@Operation(summary = "내 동아리 정보 수정 API")
@ResponseStatus(HttpStatus.NO_CONTENT)
@ApiResponse(responseCode = "204", description = "내 동아리 정보 수정 성공")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -27,12 +28,12 @@
public class CentralClubController implements CentralClubApi {

private final FacadeCentralClubService facadeCentralClubService;
private final FacadeClubMemberService facadeClubMemberService;
private final FacadeCentralClubMemberService facadeCentralClubMemberService;

@Override
public ResponseEntity<byte[]> 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");

Expand All @@ -52,6 +53,14 @@ public MyClubInfoResponse getMyClub(PrincipalDetails principalDetails) {
return MyClubInfoResponse.from(query);
}

@Override
public List<CentralClubMemberListResponse> 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();
Expand All @@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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()
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down Expand Up @@ -43,8 +41,7 @@ public record MyClubInfoResponse(
String formUrl,
@Schema(description = "동아리 프로필 이미지 Url", example = "url")
MyClubInfoImageUrlResponse profileImageUrl,
MyClubInfoImageUrlResponse introduceImageUrl,
List<ClubMemberResponse> clubMembers
MyClubInfoImageUrlResponse introductionImageUrl
) {

public static MyClubInfoResponse from(MyClubInfoQuery query) {
Expand All @@ -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())
);
}

Expand All @@ -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()
);
}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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<CentralClubMemberListQuery> getAllMyClubMember(Long userId);

void updateMemberList(UpdateClubMemberListCommand command);

void update(UpdateClubMemberCommand updateClubMemberCommand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -29,6 +30,14 @@ public byte[] getClubMemberListFile(Long userId) {
return excelFileService.generateClubMemberListFile(club.getClubMembers());
}

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

@Override
@Transactional
public void updateMemberList(UpdateClubMemberListCommand command) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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()
);
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -113,7 +112,7 @@ void updateClubMemberList() throws IOException {
.build();

//when
facadeClubMemberService.updateMemberList(command);
facadeCentralClubMemberService.updateMemberList(command);

//then
List<ClubMember> updatedClubMemberList = clubMemberRepository.findAll();
Expand Down Expand Up @@ -145,7 +144,7 @@ void update() {
.department("test").build();

//when
facadeClubMemberService.update(command);
facadeCentralClubMemberService.update(command);

//then
ClubMember updatedClubMember = clubMemberService.getById(savedClubMember.getId());
Expand Down

0 comments on commit ea7fa58

Please sign in to comment.