Skip to content

Commit

Permalink
Merge pull request #70 from IT-Cotato/refactor/club-info
Browse files Browse the repository at this point in the history
Refactor 동아리 기본정보 생성, 수정 기능에 변경사항 적용
  • Loading branch information
goalSetter09 authored Aug 20, 2024
2 parents 50358c8 + f2d2d65 commit 4e8bdc7
Show file tree
Hide file tree
Showing 6 changed files with 55 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,10 +68,24 @@ public ResponseEntity<ClubApplyResponse> 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<ClubUpdateResponse> updateClub(@AuthenticationPrincipal CustomOAuth2Member customOAuth2Member, @PathVariable Long clubId, @RequestBody ClubUpdateRequest clubUpdateRequest) {
ClubUpdateResponse clubUpdateResponse = clubService.updateClub(customOAuth2Member, clubId, clubUpdateRequest);
public ResponseEntity<ClubUpdateResponse> 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);
}
}
Original file line number Diff line number Diff line change
@@ -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 {
Expand All @@ -18,6 +19,10 @@ public class ClubCreateRequest {

private Long maxMembers;

private String clubMessage;

private List<String> tags;

private String city;

private String district;
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> tags
) {

}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@

public record MemberClubResponse(
Long clubId,
Long clubMemberIdx,
String clubName,
Boolean isAdmin
) {
Expand All @@ -20,6 +21,7 @@ public static MemberClubResponse from(ClubMember clubMember) {

return new MemberClubResponse(
clubMember.getClub().getClubId(),
clubMember.getClubMemberIdx(),
clubMember.getClub().getClubName(),
isAdmin
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -84,7 +84,7 @@ public class Club extends BaseTimeEntity {
private List<FeeType> 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<String> tags) {
this.clubName = clubName;
this.university = university;
this.clubCategory = clubCategory;
Expand All @@ -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) {
Expand All @@ -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<String> tags) {
this.logo = logo;
this.clubMessage = clubMessage;
this.region = region;
this.maxMembers = maxMembers;
this.tags = tags;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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) {

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

0 comments on commit 4e8bdc7

Please sign in to comment.