Skip to content

Commit

Permalink
Merge pull request #142 from TEAM-YOAJUNG/feature/club-service-update…
Browse files Browse the repository at this point in the history
…-api

[FEAT] 동아리 관련 수정 API 추가
  • Loading branch information
EeeasyCode authored Nov 19, 2024
2 parents d837378 + c708270 commit 4cd3fa0
Show file tree
Hide file tree
Showing 11 changed files with 359 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
import club.gach_dong.dto.request.CreateClubActivityRequest;
import club.gach_dong.dto.request.CreateClubRecruitmentRequest;
import club.gach_dong.dto.request.CreateClubRequest;
import club.gach_dong.dto.request.UpdateClubActivityRequest;
import club.gach_dong.dto.request.UpdateClubRequest;
import club.gach_dong.dto.request.UpdateContactInfoRequest;
import club.gach_dong.dto.response.AdminAuthorizedClubResponse;
import club.gach_dong.dto.response.ArrayResponse;
import club.gach_dong.dto.response.AutorizeAdminResponse;
import club.gach_dong.dto.response.ContactInfoResponse;
import club.gach_dong.dto.response.CreateClubActivityResponse;
import club.gach_dong.dto.response.CreateClubContactInfoResponse;
import club.gach_dong.dto.response.CreateClubRecruitmentResponse;
import club.gach_dong.dto.response.ClubResponse;
import club.gach_dong.dto.response.UpdateClubActivityResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
Expand All @@ -21,6 +26,7 @@
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
Expand Down Expand Up @@ -146,4 +152,46 @@ ResponseEntity<AutorizeAdminResponse> authorizeAdmin(
String userReferenceId,
@RequestBody Long clubId
);

@Operation(
summary = "동아리 정보 수정",
description = "동아리 정보를 입력받아 동아리를 수정합니다.",
security = @SecurityRequirement(name = "Authorization")
)
@PutMapping("/update")
ResponseEntity<ClubResponse> updateClubInfo(
@RequestUserReferenceId
String userReferenceId,
@Valid
@RequestBody
UpdateClubRequest updateClubRequest
);

@Operation(
summary = "동아리 연락처 정보 수정",
description = "동아리 연락처 정보를 입력받아 연락처 정보를 수정합니다.",
security = @SecurityRequirement(name = "Authorization")
)
@PutMapping("/contact-info/update")
ResponseEntity<ContactInfoResponse> updateContactInfo(
@RequestUserReferenceId
String userReferenceId,
@Valid
@RequestBody
UpdateContactInfoRequest updateContactInfoRequest
);

@Operation(
summary = "동아리 활동 내역 수정",
description = "동아리 활동 내역을 입력받아 활동 내역을 수정합니다.",
security = @SecurityRequirement(name = "Authorization")
)
@PutMapping("/activities/update")
ResponseEntity<UpdateClubActivityResponse> updateClubActivity(
@RequestUserReferenceId
String userReferenceId,
@Valid
@RequestBody
UpdateClubActivityRequest updateClubActivityRequest
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,18 @@
import club.gach_dong.dto.request.CreateClubContactInfoRequest;
import club.gach_dong.dto.request.CreateClubRecruitmentRequest;
import club.gach_dong.dto.request.CreateClubRequest;
import club.gach_dong.dto.request.UpdateClubActivityRequest;
import club.gach_dong.dto.request.UpdateClubRequest;
import club.gach_dong.dto.request.UpdateContactInfoRequest;
import club.gach_dong.dto.response.AdminAuthorizedClubResponse;
import club.gach_dong.dto.response.ArrayResponse;
import club.gach_dong.dto.response.AutorizeAdminResponse;
import club.gach_dong.dto.response.ContactInfoResponse;
import club.gach_dong.dto.response.CreateClubActivityResponse;
import club.gach_dong.dto.response.CreateClubContactInfoResponse;
import club.gach_dong.dto.response.CreateClubRecruitmentResponse;
import club.gach_dong.dto.response.ClubResponse;
import club.gach_dong.dto.response.UpdateClubActivityResponse;
import club.gach_dong.service.ClubReadService;
import club.gach_dong.service.ClubService;
import java.time.LocalDateTime;
Expand Down Expand Up @@ -101,4 +106,23 @@ public ResponseEntity<AutorizeAdminResponse> authorizeAdmin(String userReference
return new ResponseEntity<>(new AutorizeAdminResponse(), HttpStatus.OK);
}

@Override
public ResponseEntity<ClubResponse> updateClubInfo(String userReferenceId, UpdateClubRequest updateClubRequest) {
ClubResponse updateClubResponse = clubService.updateClubInfo(userReferenceId, updateClubRequest);
return new ResponseEntity<>(updateClubResponse, HttpStatus.OK);
}

@Override
public ResponseEntity<ContactInfoResponse> updateContactInfo(String userReferenceId,
UpdateContactInfoRequest updateContactInfoRequest) {
ContactInfoResponse updateContactInfoResponse = clubService.updateContactInfo(userReferenceId, updateContactInfoRequest);
return new ResponseEntity<>(updateContactInfoResponse, HttpStatus.OK);
}

@Override
public ResponseEntity<UpdateClubActivityResponse> updateClubActivity(String userReferenceId, UpdateClubActivityRequest updateClubActivityRequest) {
UpdateClubActivityResponse updateClubActivityResponse = clubService.updateClubActivity(userReferenceId, updateClubActivityRequest);
return new ResponseEntity<>(updateClubActivityResponse, HttpStatus.OK);
}

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

import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import jakarta.validation.constraints.NotNull;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand Down Expand Up @@ -48,4 +49,10 @@ private Activity(String title, LocalDate date, String description, Club club) {
public static Activity of(String title, LocalDate date, String description, Club club) {
return new Activity(title, date, description, club);
}

public void update(String title, String description, LocalDate date) {
this.title = title;
this.description = description;
this.date = date;
}
}
20 changes: 20 additions & 0 deletions club-service/src/main/java/club/gach_dong/domain/Club.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package club.gach_dong.domain;

import club.gach_dong.dto.request.UpdateClubRequest;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.persistence.*;
import lombok.AccessLevel;
Expand Down Expand Up @@ -122,4 +123,23 @@ public void addPresident(String userReferenceId) {
public void addAdminMember(ClubAdmin clubAdmin) {
this.admins.add(clubAdmin);
}

public Club update(
Long clubId,
String name,
ClubCategory category,
String shortDescription,
String introduction,
String clubImageUrl,
LocalDateTime establishedAt
) {
this.id = clubId;
this.name = name;
this.category = category;
this.shortDescription = shortDescription;
this.introduction = introduction;
this.clubImageUrl = clubImageUrl;
this.establishedAt = establishedAt;
return this;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ private ContactInfo(String contactMethod, String contactValue, Club club) {
public static ContactInfo of(String contactMethod, String contactValue, Club club) {
return new ContactInfo(contactMethod, contactValue, club);
}

public void update(String contactMethod, String contactValue) {
this.contactMethod = contactMethod;
this.contactValue = contactValue;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package club.gach_dong.dto.request;

import club.gach_dong.domain.Activity;
import club.gach_dong.domain.ContactInfo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDate;

public record UpdateClubActivityRequest(
@Schema(description = "동아리 ID", example = "1")
@NotNull
Long clubId,

@Schema(description = "활동 ID", example = "1")
@NotNull
Long activityId,

@Schema(description = "활동 제목", example = "가츠동 축구 동아리 첫 모임")
@NotNull
String title,

@Schema(description = "활동 설명", example = "가츠동 축구 동아리 첫 모임입니다.")
@NotNull
String description,

@Schema(description = "활동 날짜", example = "2023-08-31")
@NotNull
LocalDate date
) implements ClubIdentifiable {
public void updateToEntity(Activity activity) {
activity.update(title, description, date);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package club.gach_dong.dto.request;

import club.gach_dong.domain.Club;
import club.gach_dong.domain.ClubCategory;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotBlank;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDateTime;

public record UpdateClubRequest(
@Schema(description = "동아리 ID", example = "1")
@NotNull
Long clubId,

@Schema(description = "동아리 이름", example = "가츠동")
@NotBlank
String name,

@Schema(description = "동아리 카테고리", example = "SPORTS")
@NotNull
ClubCategory category,

@Schema(description = "동아리 한줄 설명", example = "가츠동은 최고의 동아리입니다.")
@NotBlank
String shortDescription,

@Schema(description = "동아리 소개", example = "<h1>가츠동</h1> <p>최고의 동아리입니다</p>")
String introduction,

@Schema(description = "동아리 이미지 URL", example = "http://example.com/image.png")
String clubImageUrl,

@Schema(description = "동아리 설립일", example = "2023-01-01T00:00:00")
LocalDateTime establishedAt
) implements ClubIdentifiable {
public void updateToEntity(Club club) {
club.update(clubId, name, category, shortDescription, introduction, clubImageUrl, establishedAt);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package club.gach_dong.dto.request;

import club.gach_dong.domain.Club;
import club.gach_dong.domain.ContactInfo;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;

public record UpdateContactInfoRequest(
@Schema(description = "동아리 ID", example = "1")
@NotNull
Long clubId,

@Schema(description = "연락처 ID", example = "1")
@NotNull
Long contactInfoId,

@Schema(description = "연락처 유형", example = "전화번호")
@NotNull
String type,

@Schema(description = "연락처", example = "010-1234-5678")
@NotNull
String contact
) implements ClubIdentifiable {
public void updateToEntity(ContactInfo contactInfo) {
contactInfo.update(type, contact);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package club.gach_dong.dto.response;

import club.gach_dong.domain.Activity;
import io.swagger.v3.oas.annotations.media.Schema;
import jakarta.validation.constraints.NotNull;
import java.time.LocalDate;

public record UpdateClubActivityResponse(
@Schema(description = "동아리 ID", example = "1")
@NotNull
Long clubId,

@Schema(description = "활동 ID", example = "1")
@NotNull
Long activityId,

@Schema(description = "활동 제목", example = "가츠동 축구 동아리 첫 모임")
@NotNull
String title,

@Schema(description = "활동 설명", example = "가츠동 축구 동아리 첫 모임입니다.")
@NotNull
String description,

@Schema(description = "활동 날짜", example = "2023-08-31")
@NotNull
LocalDate date
) {
public static UpdateClubActivityResponse from(Activity updatedActivity) {
return new UpdateClubActivityResponse(
updatedActivity.getClub().getId(),
updatedActivity.getId(),
updatedActivity.getTitle(),
updatedActivity.getDescription(),
updatedActivity.getDate()
);
}
}
59 changes: 59 additions & 0 deletions club-service/src/main/java/club/gach_dong/service/ClubService.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,15 @@
import club.gach_dong.dto.request.CreateClubContactInfoRequest;
import club.gach_dong.dto.request.CreateClubRecruitmentRequest;
import club.gach_dong.dto.request.CreateClubRequest;
import club.gach_dong.dto.request.UpdateClubActivityRequest;
import club.gach_dong.dto.request.UpdateClubRequest;
import club.gach_dong.dto.request.UpdateContactInfoRequest;
import club.gach_dong.dto.response.ContactInfoResponse;
import club.gach_dong.dto.response.CreateClubActivityResponse;
import club.gach_dong.dto.response.CreateClubContactInfoResponse;
import club.gach_dong.dto.response.CreateClubRecruitmentResponse;
import club.gach_dong.dto.response.ClubResponse;
import club.gach_dong.dto.response.UpdateClubActivityResponse;
import club.gach_dong.exception.ClubException.ClubNotFoundException;
import club.gach_dong.repository.ClubRepository;
import lombok.RequiredArgsConstructor;
Expand Down Expand Up @@ -102,6 +107,60 @@ public CreateClubRecruitmentResponse createClubRecruitment(
return CreateClubRecruitmentResponse.of(savedRecruitment);
}

@AdminAuthorizationCheck(role = {ClubAdminRole.PRESIDENT, ClubAdminRole.MEMBER})
public ClubResponse updateClubInfo(String userReferenceId, UpdateClubRequest updateClubRequest) {

Club club = clubRepository.findById(updateClubRequest.clubId())
.orElseThrow(ClubNotFoundException::new);

updateClubRequest.updateToEntity(club);

Club updateClub = clubRepository.save(club);

return ClubResponse.of(updateClub);
}

@AdminAuthorizationCheck(role = {ClubAdminRole.PRESIDENT, ClubAdminRole.MEMBER})
public ContactInfoResponse updateContactInfo(String userReferenceId, UpdateContactInfoRequest updateContactInfoRequest) {

Club club = clubRepository.findById(updateContactInfoRequest.clubId())
.orElseThrow(ClubNotFoundException::new);

ContactInfo contactInfo = club.getContactInfo().stream()
.filter(c -> c.getId().equals(updateContactInfoRequest.contactInfoId()))
.findFirst()
.orElseThrow(ContactInfoNotFoundException::new);

updateContactInfoRequest.updateToEntity(contactInfo);

ContactInfo updateContactInfo = clubRepository.save(club).getContactInfo().stream()
.filter(c -> c.getId().equals(updateContactInfoRequest.contactInfoId()))
.findFirst()
.orElseThrow(ContactInfoNotFoundException::new);

return ContactInfoResponse.from(updateContactInfo);
}

@AdminAuthorizationCheck(role = {ClubAdminRole.PRESIDENT, ClubAdminRole.MEMBER})
public UpdateClubActivityResponse updateClubActivity(String userReferenceId, UpdateClubActivityRequest updateClubActivityRequest) {
Club club = clubRepository.findById(updateClubActivityRequest.clubId())
.orElseThrow(ClubNotFoundException::new);

Activity activity = club.getActivities().stream()
.filter(a -> a.getId().equals(updateClubActivityRequest.activityId()))
.findFirst()
.orElseThrow(ActivityNotFoundException::new);

updateClubActivityRequest.updateToEntity(activity);

Activity updatedActivity = clubRepository.save(club).getActivities().stream()
.filter(a -> a.getId().equals(updateClubActivityRequest.activityId()))
.findFirst()
.orElseThrow(ActivityNotFoundException::new);

return UpdateClubActivityResponse.from(updatedActivity);
}

public boolean hasRoleForClub(String userReferenceId, Long clubId, ClubAdminRole requiredRole) {
Club club = clubRepository.findById(clubId)
.orElseThrow(ClubNotFoundException::new);
Expand Down
Loading

0 comments on commit 4cd3fa0

Please sign in to comment.