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
12 changes: 12 additions & 0 deletions src/main/java/gg/agit/konect/domain/club/controller/ClubApi.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@
import gg.agit.konect.domain.club.dto.ClubRecruitmentUpdateRequest;
import gg.agit.konect.domain.club.dto.ClubTagsResponse;
import gg.agit.konect.domain.club.dto.ClubsResponse;
import gg.agit.konect.domain.club.dto.MyManagedClubResponse;
import gg.agit.konect.domain.club.dto.MemberPositionChangeRequest;
import gg.agit.konect.domain.club.dto.PresidentTransferRequest;
import gg.agit.konect.domain.club.dto.VicePresidentChangeRequest;
Expand Down Expand Up @@ -153,6 +154,17 @@ ResponseEntity<ClubMembershipsResponse> getManagedClubs(
@UserId Integer userId
);

@Operation(summary = "관리자 권한을 가지고 있는 동아리 단건을 조회한다.", description = """
## 에러
- FORBIDDEN_CLUB_MANAGER_ACCESS (403): 동아리 매니저 권한이 없습니다.
- NOT_FOUND_CLUB (404): 동아리를 찾을 수 없습니다.
""")
@GetMapping("/managed/{clubId}")
ResponseEntity<MyManagedClubResponse> getManagedClubDetail(
@PathVariable(name = "clubId") Integer clubId,
@UserId Integer userId
);

@Operation(summary = "가입 승인 대기 중인 동아리 리스트를 조회한다.")
@GetMapping("/applied")
ResponseEntity<ClubAppliedClubsResponse> getAppliedClubs(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
import gg.agit.konect.domain.club.dto.ClubRecruitmentUpdateRequest;
import gg.agit.konect.domain.club.dto.ClubTagsResponse;
import gg.agit.konect.domain.club.dto.ClubsResponse;
import gg.agit.konect.domain.club.dto.MyManagedClubResponse;
import gg.agit.konect.domain.club.dto.MemberPositionChangeRequest;
import gg.agit.konect.domain.club.dto.PresidentTransferRequest;
import gg.agit.konect.domain.club.dto.VicePresidentChangeRequest;
Expand Down Expand Up @@ -130,6 +131,15 @@ public ResponseEntity<ClubMembershipsResponse> getManagedClubs(
return ResponseEntity.ok(response);
}

@Override
public ResponseEntity<MyManagedClubResponse> getManagedClubDetail(
@PathVariable(name = "clubId") Integer clubId,
@UserId Integer userId
) {
MyManagedClubResponse response = clubService.getManagedClubDetail(clubId, userId);
return ResponseEntity.ok(response);
}

@Override
public ResponseEntity<ClubAppliedClubsResponse> getAppliedClubs(
@UserId Integer userId
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package gg.agit.konect.domain.club.dto;

import static io.swagger.v3.oas.annotations.media.Schema.RequiredMode.REQUIRED;

import gg.agit.konect.domain.club.model.Club;
import gg.agit.konect.domain.club.model.ClubMember;
import gg.agit.konect.domain.user.model.User;
import io.swagger.v3.oas.annotations.media.Schema;

public record MyManagedClubResponse(
@Schema(description = "동아리 고유 ID", example = "1", requiredMode = REQUIRED)
Integer clubId,

@Schema(description = "동아리 이름", example = "BCSD", requiredMode = REQUIRED)
String clubName,

@Schema(description = "회원 이름", example = "배진호", requiredMode = REQUIRED)
String name,

@Schema(description = "회원 학번", example = "2020136061", requiredMode = REQUIRED)
String studentNumber,

@Schema(description = "직책", example = "회장", requiredMode = REQUIRED)
String position
) {
public static MyManagedClubResponse from(Club club, ClubMember clubMember) {
User user = clubMember.getUser();
return new MyManagedClubResponse(
club.getId(),
club.getName(),
user.getName(),
user.getStudentNumber(),
clubMember.getClubPosition().getName()
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,19 @@ List<ClubMember> findAllByUserIdAndClubPosition(
@Param("clubPositionGroup") ClubPositionGroup clubPositionGroup
);

@Query("""
SELECT cm
FROM ClubMember cm
JOIN FETCH cm.club c
JOIN FETCH cm.clubPosition cp
WHERE cm.id.userId = :userId
AND cp.clubPositionGroup IN :clubPositionGroups
""")
List<ClubMember> findAllByUserIdAndClubPositionGroups(
@Param("userId") Integer userId,
@Param("clubPositionGroups") Set<ClubPositionGroup> clubPositionGroups
);

@Query("""
SELECT COUNT(cm) > 0
FROM ClubMember cm
Expand All @@ -96,6 +109,7 @@ boolean existsByClubIdAndUserIdAndPositionGroupIn(
@Query("""
SELECT cm
FROM ClubMember cm
JOIN FETCH cm.user
JOIN FETCH cm.clubPosition
WHERE cm.club.id = :clubId
AND cm.user.id = :userId
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import gg.agit.konect.domain.club.dto.ClubRecruitmentUpdateRequest;
import gg.agit.konect.domain.club.dto.ClubTagsResponse;
import gg.agit.konect.domain.club.dto.ClubsResponse;
import gg.agit.konect.domain.club.dto.MyManagedClubResponse;
import gg.agit.konect.domain.club.enums.ClubPositionGroup;
import gg.agit.konect.domain.club.model.Club;
import gg.agit.konect.domain.club.model.ClubApply;
Expand Down Expand Up @@ -81,6 +82,8 @@ public class ClubService {
EnumSet.of(PRESIDENT);
private static final Set<ClubPositionGroup> MANAGER_ALLOWED_GROUPS =
EnumSet.of(PRESIDENT, MANAGER);
private static final Set<ClubPositionGroup> MANAGER_OR_HIGHER_ALLOWED_GROUPS =
EnumSet.of(PRESIDENT, VICE_PRESIDENT, MANAGER);
private static final Set<ClubPositionGroup> LEADER_ALLOWED_GROUPS =
EnumSet.of(PRESIDENT, VICE_PRESIDENT);

Expand Down Expand Up @@ -238,10 +241,24 @@ public ClubMembershipsResponse getJoinedClubs(Integer userId) {
}

public ClubMembershipsResponse getManagedClubs(Integer userId) {
List<ClubMember> clubMembers = clubMemberRepository.findAllByUserIdAndClubPosition(userId, PRESIDENT);
List<ClubMember> clubMembers = clubMemberRepository.findAllByUserIdAndClubPositionGroups(
userId,
MANAGER_OR_HIGHER_ALLOWED_GROUPS
);
return ClubMembershipsResponse.from(clubMembers);
}

public MyManagedClubResponse getManagedClubDetail(Integer clubId, Integer userId) {
Club club = clubRepository.getById(clubId);

if (!hasClubManageAccess(clubId, userId, MANAGER_OR_HIGHER_ALLOWED_GROUPS)) {
throw CustomException.of(FORBIDDEN_CLUB_MANAGER_ACCESS);
}

ClubMember clubMember = clubMemberRepository.getByClubIdAndUserId(clubId, userId);
return MyManagedClubResponse.from(club, clubMember);
}

public ClubAppliedClubsResponse getAppliedClubs(Integer userId) {
List<ClubApply> clubApplies = clubApplyRepository.findAllPendingByUserIdWithClub(userId);
return ClubAppliedClubsResponse.from(clubApplies);
Expand Down