diff --git a/src/main/java/com/cotato/squadus/api/club/controller/ClubController.java b/src/main/java/com/cotato/squadus/api/club/controller/ClubController.java index 1a9d316..2c58954 100644 --- a/src/main/java/com/cotato/squadus/api/club/controller/ClubController.java +++ b/src/main/java/com/cotato/squadus/api/club/controller/ClubController.java @@ -68,10 +68,24 @@ public ResponseEntity joinClub(@PathVariable Long clubId, @Re return ResponseEntity.ok(clubApplyResponse); } - @PatchMapping("/{clubId}") + @PatchMapping(value = "/{clubId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE) @Operation(summary = "동아리 기본정보 수정", description = "동아리의 기본 정보를 변경합니다.") - public ResponseEntity updateClub(@AuthenticationPrincipal CustomOAuth2Member customOAuth2Member, @PathVariable Long clubId, @RequestBody ClubUpdateRequest clubUpdateRequest) { - ClubUpdateResponse clubUpdateResponse = clubService.updateClub(customOAuth2Member, clubId, clubUpdateRequest); + public ResponseEntity updateClub( + @AuthenticationPrincipal CustomOAuth2Member customOAuth2Member, + @PathVariable Long clubId, + @Parameter(description = "동아리 수정 요청 정보", schema = @Schema(implementation = ClubUpdateRequest.class)) + @RequestPart("clubUpdateRequest") String clubUpdateRequestString, + @RequestPart(value = "logoImage", required = false) MultipartFile logoImage) { + + // JSON String을 객체로 변환 + ObjectMapper objectMapper = new ObjectMapper(); + ClubUpdateRequest clubUpdateRequest; + try { + clubUpdateRequest = objectMapper.readValue(clubUpdateRequestString, ClubUpdateRequest.class); + } catch (JsonProcessingException e) { + throw new RuntimeException("Invalid JSON format", e); + } + ClubUpdateResponse clubUpdateResponse = clubService.updateClub(customOAuth2Member, clubId, clubUpdateRequest, logoImage); return ResponseEntity.ok(clubUpdateResponse); } } diff --git a/src/main/java/com/cotato/squadus/api/club/dto/ClubCreateRequest.java b/src/main/java/com/cotato/squadus/api/club/dto/ClubCreateRequest.java index e138a37..c1a90e8 100644 --- a/src/main/java/com/cotato/squadus/api/club/dto/ClubCreateRequest.java +++ b/src/main/java/com/cotato/squadus/api/club/dto/ClubCreateRequest.java @@ -1,11 +1,12 @@ package com.cotato.squadus.api.club.dto; -import com.cotato.squadus.domain.club.common.entity.Region; import com.cotato.squadus.domain.club.common.enums.ClubCategory; import com.cotato.squadus.domain.club.common.enums.SportsCategory; import lombok.Getter; import lombok.Setter; +import java.util.List; + @Getter @Setter public class ClubCreateRequest { @@ -18,6 +19,10 @@ public class ClubCreateRequest { private Long maxMembers; + private String clubMessage; + + private List tags; + private String city; private String district; diff --git a/src/main/java/com/cotato/squadus/api/club/dto/ClubUpdateRequest.java b/src/main/java/com/cotato/squadus/api/club/dto/ClubUpdateRequest.java index f3d8265..2836758 100644 --- a/src/main/java/com/cotato/squadus/api/club/dto/ClubUpdateRequest.java +++ b/src/main/java/com/cotato/squadus/api/club/dto/ClubUpdateRequest.java @@ -1,8 +1,13 @@ package com.cotato.squadus.api.club.dto; +import java.util.List; + public record ClubUpdateRequest( - String logo, - String clubMessage + String clubMessage, + String city, + String district, + Long maxMembers, + List tags ) { } diff --git a/src/main/java/com/cotato/squadus/api/member/dto/MemberClubResponse.java b/src/main/java/com/cotato/squadus/api/member/dto/MemberClubResponse.java index 8794046..bd95ccc 100644 --- a/src/main/java/com/cotato/squadus/api/member/dto/MemberClubResponse.java +++ b/src/main/java/com/cotato/squadus/api/member/dto/MemberClubResponse.java @@ -6,6 +6,7 @@ public record MemberClubResponse( Long clubId, + Long clubMemberIdx, String clubName, Boolean isAdmin ) { @@ -20,6 +21,7 @@ public static MemberClubResponse from(ClubMember clubMember) { return new MemberClubResponse( clubMember.getClub().getClubId(), + clubMember.getClubMemberIdx(), clubMember.getClub().getClubName(), isAdmin ); diff --git a/src/main/java/com/cotato/squadus/domain/club/common/entity/Club.java b/src/main/java/com/cotato/squadus/domain/club/common/entity/Club.java index 94475df..87c05da 100644 --- a/src/main/java/com/cotato/squadus/domain/club/common/entity/Club.java +++ b/src/main/java/com/cotato/squadus/domain/club/common/entity/Club.java @@ -84,7 +84,7 @@ public class Club extends BaseTimeEntity { private List feeTypes = new ArrayList<>(); @Builder - private Club(String clubName, String university, ClubCategory clubCategory, SportsCategory sportsCategory, String logo, ClubTier clubTier, Integer clubRank, String clubMessage, Long maxMembers, Region region) { + private Club(String clubName, String university, ClubCategory clubCategory, SportsCategory sportsCategory, String logo, ClubTier clubTier, Integer clubRank, String clubMessage, Long maxMembers, Region region, List tags) { this.clubName = clubName; this.university = university; this.clubCategory = clubCategory; @@ -96,6 +96,7 @@ private Club(String clubName, String university, ClubCategory clubCategory, Spor this.maxMembers = maxMembers; this.numberOfMembers = 1; this.region = region; + this.tags = tags; } public void addClubMember(ClubMember clubMember) { @@ -121,9 +122,12 @@ public void updateMatchScore(int points) { this.matchScore += points; } - public Club updateClub(String logo, String clubMessage) { + public Club updateClub(String logo, String clubMessage, Region region, Long maxMembers, List tags) { this.logo = logo; this.clubMessage = clubMessage; + this.region = region; + this.maxMembers = maxMembers; + this.tags = tags; return this; } } diff --git a/src/main/java/com/cotato/squadus/domain/club/common/service/ClubService.java b/src/main/java/com/cotato/squadus/domain/club/common/service/ClubService.java index e25ea40..8ceb268 100644 --- a/src/main/java/com/cotato/squadus/domain/club/common/service/ClubService.java +++ b/src/main/java/com/cotato/squadus/domain/club/common/service/ClubService.java @@ -42,11 +42,6 @@ public class ClubService { private final MemberService memberService; private final S3ImageService s3ImageService; - /** - * - * @param clubCreateRequest 동아리 생성 dto - * @return ClubCreateResponse 생성된 동아리 id - */ @Transactional public ClubCreateResponse createClub(CustomOAuth2Member customOAuth2Member, ClubCreateRequest clubCreateRequest, MultipartFile logoImage) { @@ -75,8 +70,9 @@ public ClubCreateResponse createClub(CustomOAuth2Member customOAuth2Member, Club .sportsCategory(clubCreateRequest.getSportsCategory()) .logo(logo) .clubTier(ClubTier.BRONZE) - .clubMessage(clubCreateRequest.getClubName() + "입니다.") + .clubMessage(clubCreateRequest.getClubMessage()) .maxMembers(clubCreateRequest.getMaxMembers()) + .tags(clubCreateRequest.getTags()) .region(Region.builder() .city(clubCreateRequest.getCity()) .district(clubCreateRequest.getDistrict()) @@ -101,13 +97,6 @@ public ClubCreateResponse createClub(CustomOAuth2Member customOAuth2Member, Club return new ClubCreateResponse(savedClub.getClubId()); } - /** - * - * @param clubApplyRequest 동아리 가입 신청 dto - * @return ClubApplyResponse clubApplication id 담아서 리턴 - * 동아리 가입 신청하는 매서드입니다. - * 초기에는 상태 PENDING으로 설정되고 나중에 동아리장이 가입 승인하면 바뀜 - */ @Transactional public ClubApplyResponse joinClub(Long clubId, ClubApplyRequest clubApplyRequest) { Club club = clubRepository.findById(clubId) @@ -143,15 +132,27 @@ public ClubInfoResponse findClubInfo(Long clubId) { @Transactional - public ClubUpdateResponse updateClub(CustomOAuth2Member customOAuth2Member, Long clubId, ClubUpdateRequest clubUpdateRequest) { + public ClubUpdateResponse updateClub(CustomOAuth2Member customOAuth2Member, Long clubId, ClubUpdateRequest clubUpdateRequest, MultipartFile logoImage) { clubAdminService.validateAdminMember(clubId); Club club = clubRepository.findById(clubId) .orElseThrow(() -> new EntityNotFoundException("해당 clubId를 가진 동아리가 존재하지 않습니다.")); + // logo 설정 + String logo = club.getLogo(); + if (logoImage != null && !logoImage.isEmpty()) { + logo = s3ImageService.upload(logoImage); + } + Club updateClub = club.updateClub( - clubUpdateRequest.logo(), - clubUpdateRequest.clubMessage() + logo, + clubUpdateRequest.clubMessage(), + Region.builder() + .city(clubUpdateRequest.city()) + .district(clubUpdateRequest.district()) + .build(), + clubUpdateRequest.maxMembers(), + clubUpdateRequest.tags() ); Club savedClub = clubRepository.save(updateClub);