Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,14 @@ public class ClubController implements ClubControllerDocs{

private final UserRepository userRepository;

@PostMapping(value = "/club", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PostMapping(value = "/clubs", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public BaseResponse<ClubSaveOutput> clubSave(@AuthenticationPrincipal UserDetailsImpl userDetailsImpl, @ModelAttribute @Valid ClubInput clubInput) throws IOException {
// public BaseResponse<ClubSaveOutput> clubSave(@ModelAttribute @Valid ClubInput clubInput) throws IOException {
// User user = userRepository.findById(1L).get();
return BaseResponse.onSuccess(clubCommandService.saveClub(userDetailsImpl.getUser(), clubInput), ResponseCode.OK);
}

@PatchMapping(value = "/club/{id}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
@PatchMapping(value = "/clubs/{id}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE, produces = MediaType.APPLICATION_JSON_VALUE)
public BaseResponse<ClubUpdateOutput> clubUpdate(@AuthenticationPrincipal UserDetailsImpl userDetailsImpl, @ModelAttribute ClubUpdateInput clubUpdateInput, @PathVariable("id") Long clubId) throws IOException {
// public BaseResponse<ClubUpdateOutput> clubUpdate(@ModelAttribute ClubUpdateInput clubUpdateInput, @PathVariable("id") Long clubId) throws IOException {
// User user = userRepository.findById(1L).get();
Expand All @@ -48,7 +48,7 @@ public BaseResponse<List<ClubSearchOutput>> findClubs(@AuthenticationPrincipal U
return BaseResponse.onSuccess(clubQueryService.searchClub(clubSearchCond), ResponseCode.OK);
}

@PostMapping("/club/{id}/join")
@PostMapping("/clubs/{id}/join")
public BaseResponse<UserClubOutput> clubUserSave(@AuthenticationPrincipal UserDetailsImpl userDetailsImpl, @RequestBody ClubUserSaveInput clubUserSaveInput, @PathVariable("id") Long clubId) {
// public BaseResponse<UserClubOutput> clubUserSave(@RequestBody ClubUserSaveInput clubUserSaveInput, @PathVariable("id") Long clubId) {
// User user = userRepository.findById(1L).get();
Expand All @@ -60,26 +60,30 @@ public BaseResponse<UserClubOutput> clubUserSave(@AuthenticationPrincipal UserDe
// return clubService.inviteClubUser(userDetailsImpl.getUser(), clubInviteInput);
// }

@PatchMapping("/club/{id}/role")
@DeleteMapping("/clubs/{id}/users")
public BaseResponse<String> clubUserDelete(@AuthenticationPrincipal UserDetailsImpl userDetailsImpl, @PathVariable("id") Long clubId, @RequestBody ClubUserDeleteInput clubUserDeleteInput) {
return BaseResponse.onSuccess(clubCommandService.deleteClubUser(userDetailsImpl.getUser(), clubId, clubUserDeleteInput.getUserId()), ResponseCode.OK);
}

@PatchMapping("/clubs/{id}/role")
public BaseResponse<UserClubOutput> clubUserUpdate(@AuthenticationPrincipal UserDetailsImpl userDetailsImpl, @RequestBody ClubUserUpdateInput clubInput, @PathVariable("id") Long clubId) {
// public BaseResponse<UserClubOutput> clubUserUpdate(@RequestBody ClubUserUpdateInput clubInput, @PathVariable("id") Long clubId) {
// User user = userRepository.findById(1L).get();
return BaseResponse.onSuccess(clubCommandService.updateClubUser(userDetailsImpl.getUser(), clubInput, clubId), ResponseCode.OK);
}

@GetMapping("/club/{id}")
@GetMapping("/clubs/{id}")
public BaseResponse<ClubOutput> clubFind(@AuthenticationPrincipal UserDetailsImpl userDetailsImpl, @PathVariable("id") Long clubId) {
// public BaseResponse<ClubOutput> clubFind(@Parameter(description = "조회할 모임 ID", required = true, example = "1") @PathVariable("id") Long id) {
// User user = userRepository.findById(1L).get();
return BaseResponse.onSuccess(clubQueryService.findClub(clubId, userDetailsImpl.getUser()), ResponseCode.OK);
}

@PatchMapping(value = "/club/{id}/password", consumes = MediaType.APPLICATION_JSON_VALUE)
public BaseResponse clubPasswordUpdate(@AuthenticationPrincipal UserDetailsImpl userDetailsImpl, @RequestBody @Valid ClubPswdUpdateInput clubPswdUpdateInput, @PathVariable("id") Long clubId) {
@PatchMapping(value = "/clubs/{id}/password", consumes = MediaType.APPLICATION_JSON_VALUE)
public BaseResponse<String> clubPasswordUpdate(@AuthenticationPrincipal UserDetailsImpl userDetailsImpl, @RequestBody @Valid ClubPswdUpdateInput clubPswdUpdateInput, @PathVariable("id") Long clubId) {
// public BaseResponse clubPasswordUpdate(@RequestBody @Valid ClubPswdUpdateInput clubPswdUpdateInput, @PathVariable("id") Long clubId) {
// User user = userRepository.findById(1L).get();
clubCommandService.clubPasswordUpdate(userDetailsImpl.getUser(), clubPswdUpdateInput, clubId);
return BaseResponse.onSuccess(null, ResponseCode.OK);
return BaseResponse.onSuccess(clubCommandService.clubPasswordUpdate(userDetailsImpl.getUser(), clubPswdUpdateInput, clubId), ResponseCode.OK);
}

// @PatchMapping(value = "/club/profile", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public interface ClubControllerDocs {
BaseResponse<UserClubOutput> clubUserSave(@AuthenticationPrincipal UserDetailsImpl userDetailsImpl, @RequestBody ClubUserSaveInput clubInput, @PathVariable("id") Long clubId);
// BaseResponse<UserClubOutput> clubUserSave(@RequestBody ClubUserSaveInput clubInput, @PathVariable Long clubId);

@Operation(summary = "모임에서 내보내기")
BaseResponse<String> clubUserDelete(@AuthenticationPrincipal UserDetailsImpl userDetailsImpl, @PathVariable("id") Long clubId, @RequestBody ClubUserDeleteInput clubUserDeleteInput);

// @Operation(summary = "모임에 초대")
// UserClubOutput clubUserInvite(@AuthenticationPrincipal userDetailsImpl userDetailsImpl, @RequestBody ClubUserSaveInput clubInput);

Expand All @@ -45,7 +48,7 @@ public interface ClubControllerDocs {
// BaseResponse<ClubOutput> clubFind(@PathVariable("id") Long clubId);

@Operation(summary = "모임 비밀번호 변경")
BaseResponse clubPasswordUpdate(@AuthenticationPrincipal UserDetailsImpl userDetailsImpl, @RequestBody ClubPswdUpdateInput clubPswdUpdateInput, @PathVariable("id") Long clubId);
BaseResponse<String> clubPasswordUpdate(@AuthenticationPrincipal UserDetailsImpl userDetailsImpl, @RequestBody ClubPswdUpdateInput clubPswdUpdateInput, @PathVariable("id") Long clubId);
// BaseResponse clubPasswordUpdate(@RequestBody ClubPswdUpdateInput clubPswdUpdateInput, @PathVariable Long clubId);

// @Operation(summary = "모임 사진 변경")
Expand Down
11 changes: 8 additions & 3 deletions src/main/java/com/example/moim/club/dto/request/ClubInput.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.example.moim.club.dto.request;

import com.example.moim.club.exception.advice.ClubControllerAdvice;
import com.example.moim.global.exception.ResponseCode;
import jakarta.validation.constraints.NotBlank;
import lombok.Builder;
import lombok.Data;
Expand All @@ -14,9 +16,9 @@ public class ClubInput {
private String title;
@NotBlank(message = "모임 설명을 적어야합니다!")
private String explanation;
@NotBlank(message = "모임 소개를 적어야합니다!")
@NotBlank(message = "모임 한줄 소개를 적어야합니다!")
private String introduction;
@NotBlank(message = "클럽 카테고리를 지정해야합니다!")
@NotBlank(message = "모임 종류를 지정해야합니다!")
private String clubCategory;
private String university;
@NotBlank(message = "성별을 지정해야합니다!")
Expand All @@ -29,14 +31,16 @@ public class ClubInput {
private String sportsType;
@NotBlank(message = "모임 비밀번호를 적어야합니다!")
private String clubPassword;
@NotBlank(message = "모임 확인 비밀번호를 적어야합니다!")
private String clubCheckPassword;
private MultipartFile profileImg;
@NotBlank(message = "메인 유니폼 색을 지정해야합니다!")
private String mainUniformColor;
@NotBlank(message = "서브 유니폼 색을 지정해야합니다!")
private String subUniformColor;

@Builder
public ClubInput(String title, String explanation, String introduction, String clubCategory, String university, String gender, String activityArea, String ageRange, String sportsType, String clubPassword, MultipartFile profileImg, String mainUniformColor, String subUniformColor) {
public ClubInput(String title, String explanation, String introduction, String clubCategory, String university, String gender, String activityArea, String ageRange, String sportsType, String clubPassword, String clubCheckPassword,MultipartFile profileImg, String mainUniformColor, String subUniformColor) {
this.title = title;
this.explanation = explanation;
this.introduction = introduction;
Expand All @@ -46,6 +50,7 @@ public ClubInput(String title, String explanation, String introduction, String c
this.activityArea = activityArea;
this.ageRange = ageRange;
this.sportsType = sportsType;
this.clubCheckPassword = clubCheckPassword;
this.clubPassword = clubPassword;
this.profileImg = profileImg;
this.mainUniformColor = mainUniformColor;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.moim.club.dto.request;

import lombok.Data;

@Data
public class ClubUserDeleteInput {
private Long userId;
}
3 changes: 3 additions & 0 deletions src/main/java/com/example/moim/club/entity/Club.java
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,9 @@ public static Club createClub(ClubInput clubInput, String profileImgPath) {
club.activityArea = ActivityArea.fromKoreanName(clubInput.getActivityArea()).get();
club.sportsType = SportsType.fromKoreanName(clubInput.getSportsType()).get();
club.ageRange = AgeRange.fromKoreanName(clubInput.getAgeRange()).get();
if (!clubInput.getClubPassword().equals(clubInput.getClubCheckPassword())) {
throw new ClubControllerAdvice(ResponseCode.CLUB_CHECK_PASSWORD_INCORRECT);
}
club.clubPassword = clubInput.getClubPassword();
club.profileImgPath = profileImgPath;
club.mainUniformColor = clubInput.getMainUniformColor();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,4 +47,6 @@ public interface UserClubRepository extends JpaRepository<UserClub, Long> {
" where uc.club = :club" +
" and (uc.clubRole = 'STAFF')")
List<UserClub> findAdminByClub(@Param("club") Club Club);

void deleteByClubIdAndUserId(Long clubId, Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,8 @@ public interface ClubCommandService {
ClubSaveOutput saveClub(User user, ClubInput clubInput) throws IOException;
ClubUpdateOutput updateClub(User user, ClubUpdateInput clubUpdateInput, Long clubId) throws IOException;
UserClubOutput saveClubUser(User user, ClubUserSaveInput clubUserSaveInput, Long clubId);
String deleteClubUser(User user, Long clubId, Long userId);
UserClubOutput updateClubUser(User user, ClubUserUpdateInput clubInput, Long clubId);
void clubPasswordUpdate(User user, ClubPswdUpdateInput clubPswdUpdateInput, Long clubId);
String clubPasswordUpdate(User user, ClubPswdUpdateInput clubPswdUpdateInput, Long clubId);

}
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,20 @@ public UserClubOutput saveClubUser(User user, ClubUserSaveInput clubUserSaveInpu
throw new ClubControllerAdvice(ResponseCode.CLUB_PASSWORD_INCORRECT);
}

@Transactional
public String deleteClubUser(User user, Long clubId, Long userId) {

User targetUser = getUser(userId);

// 관리자 권한 확인
validateIsStaff(getUserClub(getClub(clubId), user));

userClubRepository.deleteByClubIdAndUserId(clubId, userId);

return targetUser.getName() + "님이 가입에서 내보내졌습니다.";

}

// public UserClubOutput inviteClubUser(User user, ClubInviteInput clubInviteInput) {
// userRepository.findById(clubInviteInput.getUser().)
// }
Expand All @@ -112,7 +126,7 @@ public UserClubOutput updateClubUser(User user, ClubUserUpdateInput clubUserUpda
}

@Transactional
public void clubPasswordUpdate(User user, ClubPswdUpdateInput clubPswdUpdateInput, Long clubId) {
public String clubPasswordUpdate(User user, ClubPswdUpdateInput clubPswdUpdateInput, Long clubId) {
Club club = getClub(clubId);
// Club club = clubRepository.findById(clubPswdUpdateInput.getId()).orElseThrow(() -> new ClubControllerAdvice(ResponseCode.CLUB_NOT_FOUND));
UserClub userClub = userClubRepository.findByClubAndUser(club, user).orElseThrow(() -> new ClubControllerAdvice(ResponseCode.CLUB_USER_NOT_FOUND));
Expand All @@ -127,13 +141,30 @@ public void clubPasswordUpdate(User user, ClubPswdUpdateInput clubPswdUpdateInpu
if (!clubPswdUpdateInput.getNewPassword().equals(clubPswdUpdateInput.getRePassword())) {
throw new ClubControllerAdvice(ResponseCode.CLUB_CHECK_PASSWORD_INCORRECT);
}

club.updateClubPassword(clubPswdUpdateInput.getNewPassword());

return club.getTitle() + "의 비밀번호를 변경하였습니다.";
}

private UserClub getUserClub(Club club, User user) {
return userClubRepository.findByClubAndUser(club, user).orElseThrow(() -> new ClubControllerAdvice(ResponseCode.CLUB_USER_NOT_FOUND));
}

private Club getClub(Long clubId) {
return clubRepository.findById(clubId).orElseThrow(() -> new ClubControllerAdvice(ResponseCode.CLUB_NOT_FOUND));
}

private User getUser(Long userId) {
return userRepository.findById(userId).orElseThrow(() -> new ClubControllerAdvice(ResponseCode.MEMBER_NOT_FOUND));
}

private void validateIsStaff(UserClub userClub) {
if (!userClub.getClubRole().equals(ClubRole.STAFF)) {
throw new ClubControllerAdvice(ResponseCode.CLUB_PERMISSION_DENIED);
}
}

private void saveClubSearch(Club club) {
ClubSearch clubSearch = ClubSearch.builder()
.club(club)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,10 +50,10 @@ void init() {

ClubInput clubInput = ClubInput.builder().title(title).explanation(explanation).introduction(introduction).clubCategory(clubCategory.getKoreanName())
.university(university).gender(gender.getKoreanName()).activityArea(activityArea.getKoreanName()).ageRange(ageRange.getKoreanName()).sportsType(sportsType.getKoreanName())
.clubPassword(clubPassword).profileImg(profileImg).mainUniformColor(mainUniformColor).subUniformColor(subUniformColor).build();
.clubPassword(clubPassword).clubCheckPassword(clubPassword).profileImg(profileImg).mainUniformColor(mainUniformColor).subUniformColor(subUniformColor).build();
ClubInput clubInput2 = ClubInput.builder().title(title2).explanation(explanation).introduction(introduction).clubCategory(clubCategory2.getKoreanName())
.university(university).gender(gender.getKoreanName()).activityArea(activityArea.getKoreanName()).ageRange(ageRange.getKoreanName()).sportsType(sportsType.getKoreanName())
.clubPassword(clubPassword).profileImg(profileImg).mainUniformColor(mainUniformColor).subUniformColor(subUniformColor).build();
.clubPassword(clubPassword).clubCheckPassword(clubPassword).profileImg(profileImg).mainUniformColor(mainUniformColor).subUniformColor(subUniformColor).build();

Club savedClub = clubRepository.save(Club.createClub(clubInput, "/club"));
Club savedClub2 = clubRepository.save(Club.createClub(clubInput2, "/club"));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ void init() {

this.clubInput = ClubInput.builder().title(title).explanation(explanation).introduction(introduction).clubCategory(clubCategory.getKoreanName())
.university(organization).gender(gender.getKoreanName()).activityArea(activityArea.getKoreanName()).ageRange(ageRange.getKoreanName()).sportsType(sportsType.getKoreanName())
.clubPassword(clubPassword).profileImg(profileImg).mainUniformColor(mainUniformColor).subUniformColor(subUniformColor).build();
.clubPassword(clubPassword).clubCheckPassword(clubPassword).profileImg(profileImg).mainUniformColor(mainUniformColor).subUniformColor(subUniformColor).build();

String updateTitle = "update title";
String updateExplanation = "update explanation";
Expand Down Expand Up @@ -248,6 +248,49 @@ void updateClubUser_exception_wrong_permission() {
verify(userClubRepository, times(1)).findByClubAndUser(any(Club.class), any(User.class));
}

@Test
@DisplayName("운영진은 사용자를 모임에서 내보낼 수 있다")
void deleteClubUser() {
//given
Club club = Club.createClub(clubInput, null);

//when
when(clubRepository.findById(any(Long.class))).thenReturn(Optional.of(club));
when(userClubRepository.findByClubAndUser(any(Club.class), any(User.class)))
.thenReturn(Optional.of(UserClub.createLeaderUserClub(new User(), club)))
.thenReturn(Optional.of(UserClub.createUserClub(new User(), club)));
when(userRepository.findById(any(Long.class))).thenReturn(Optional.of(new User()));
String result = clubCommandService.deleteClubUser(new User(), 1L, 1L);

//then
assertThat(result).contains("님이 가입에서 내보내졌습니다.");
verify(clubRepository, times(1)).findById(any(Long.class));
verify(userClubRepository, times(1)).findByClubAndUser(any(Club.class), any(User.class));
verify(userClubRepository, times(1)).deleteByClubIdAndUserId(any(Long.class), any(Long.class));
}

@Test
@DisplayName("운영진이 아니면 모임에 속한 사용자를 내보내려 할 때 예외가 발생한다")
void delete_ClubUser_exception_wrong_permission() {
//given
Club club = Club.createClub(clubInput, null);

//when
//then
when(clubRepository.findById(any(Long.class))).thenReturn(Optional.of(club));
when(userClubRepository.findByClubAndUser(any(Club.class), any(User.class)))
.thenReturn(Optional.of(UserClub.createUserClub(new User(), club)));
when(userRepository.findById(any(Long.class))).thenReturn(Optional.of(new User()));

Exception exception = assertThrows(ClubControllerAdvice.class, () -> {
clubCommandService.deleteClubUser(new User(), 1L, 1L);
});
assertThat(exception.getMessage()).isEqualTo(ResponseCode.CLUB_PERMISSION_DENIED.getMessage());
verify(userRepository, times(1)).findById(any(Long.class));
verify(clubRepository, times(1)).findById(any(Long.class));
verify(userClubRepository, times(1)).findByClubAndUser(any(Club.class), any(User.class));
}

@Test
@DisplayName("운영진은 동아리 인증 비밀번호를 바꿀 수 있다")
void clubPasswordUpdate() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,7 @@ void init() {

this.clubInput = ClubInput.builder().title(title).explanation(explanation).introduction(introduction).clubCategory(clubCategory.getKoreanName())
.university(university).gender(gender.getKoreanName()).activityArea(activityArea.getKoreanName()).ageRange(ageRange.getKoreanName()).sportsType(sportsType.getKoreanName())
.clubPassword(clubPassword).profileImg(profileImg).mainUniformColor(mainUniformColor).subUniformColor(subUniformColor).build();
.clubPassword(clubPassword).clubCheckPassword(clubPassword).profileImg(profileImg).mainUniformColor(mainUniformColor).subUniformColor(subUniformColor).build();
}

@Test
Expand Down
Loading