Skip to content

Commit

Permalink
Merge pull request #104 from Kernel360/99-fix-filter
Browse files Browse the repository at this point in the history
feat: 동호회 전체 조회, 필터 수정
  • Loading branch information
I-migi authored Oct 7, 2024
2 parents 2fa671b + 9428d7d commit 8acf0a0
Show file tree
Hide file tree
Showing 17 changed files with 272 additions and 99 deletions.
36 changes: 0 additions & 36 deletions badminton-api/src/main/java/org/badminton/api/HomeController.java

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,11 +1,14 @@
package org.badminton.api.club.controller;

import java.util.List;

import org.badminton.api.club.model.dto.ClubCreateRequest;
import org.badminton.api.club.model.dto.ClubCreateResponse;
import org.badminton.api.club.model.dto.ClubDeleteResponse;
import org.badminton.api.club.model.dto.ClubReadResponse;
import org.badminton.api.club.model.dto.ClubUpdateRequest;
import org.badminton.api.club.model.dto.ClubUpdateResponse;
import org.badminton.api.club.model.dto.ClubsReadResponse;
import org.badminton.api.club.service.ClubService;
import org.badminton.api.member.oauth2.dto.CustomOAuth2Member;
import org.springframework.http.ResponseEntity;
Expand All @@ -25,12 +28,12 @@

@RequiredArgsConstructor
@RestController
@RequestMapping("/v1/club")
@RequestMapping("/v1")
public class ClubController {

private final ClubService clubService;

@GetMapping
@GetMapping("/club")
@Operation(summary = "동호회 조회",
description = "동호회를 조회합니다.",
tags = {"Club"})
Expand All @@ -39,7 +42,7 @@ public ResponseEntity<ClubReadResponse> readClub(@RequestParam Long clubId) {
return ResponseEntity.ok(clubReadResponse);
}

@PostMapping
@PostMapping("/club")
@Operation(summary = "동호회 추가",
description = "동호회를 추가합니다.",
tags = {"Club"})
Expand All @@ -51,7 +54,7 @@ public ResponseEntity<ClubCreateResponse> createClub(@Valid @RequestBody ClubCre
return ResponseEntity.ok(clubAddResponse);
}

@PatchMapping
@PatchMapping("/club")
@Operation(summary = "동호회 수정",
description = "동호회를 수정합니다.",
tags = {"Club"})
Expand All @@ -61,7 +64,7 @@ public ResponseEntity<ClubUpdateResponse> updateClub(@RequestParam Long clubId,
return ResponseEntity.ok(clubUpdateResponse);
}

@DeleteMapping
@DeleteMapping("/club")
@Operation(summary = "동호회 삭제",
description = "동호회를 삭제합니다.",
tags = {"Club"})
Expand All @@ -70,4 +73,13 @@ public ResponseEntity<ClubDeleteResponse> deleteClub(@RequestParam Long clubId)
return ResponseEntity.ok(clubDeleteResponse);
}

@GetMapping("/clubs")
@Operation(summary = "전체 동호회 조회",
description = "전체 동호회를 조회합니다.",
tags = {"Club"})
public ResponseEntity<List<ClubsReadResponse>> readAllClub() {

return ResponseEntity.ok(clubService.readAllClub());
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package org.badminton.api.club.model.dto;

import java.time.LocalDateTime;
import java.util.Map;

import org.badminton.domain.club.entity.ClubEntity;
import org.badminton.domain.common.enums.MemberTier;

public record ClubsReadResponse(
String clubName,
String clubDescription,
String clubImage,
LocalDateTime createdAt,
LocalDateTime modifiedAt,
Map<MemberTier, Long> tierCounts
) {

public static ClubsReadResponse clubEntityToClubsReadResponse(ClubEntity clubEntity,
Map<MemberTier, Long> tierCounts) {
return new ClubsReadResponse(clubEntity.getClubName(), clubEntity.getClubDescription(),
clubEntity.getClubImage(),
clubEntity.getCreatedAt(),
clubEntity.getModifiedAt(),
tierCounts
);
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,26 @@
package org.badminton.api.club.service;

import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

import org.badminton.api.club.model.dto.ClubCreateRequest;
import org.badminton.api.club.model.dto.ClubCreateResponse;
import org.badminton.api.club.model.dto.ClubDeleteResponse;
import org.badminton.api.club.model.dto.ClubReadResponse;
import org.badminton.api.club.model.dto.ClubUpdateRequest;
import org.badminton.api.club.model.dto.ClubUpdateResponse;
import org.badminton.api.club.model.dto.ClubsReadResponse;
import org.badminton.api.common.exception.club.ClubNameDuplicateException;
import org.badminton.api.common.exception.club.ClubNotExistException;
import org.badminton.api.common.exception.member.MemberNotExistException;
import org.badminton.api.leaguerecord.service.LeagueRecordService;
import org.badminton.domain.club.entity.ClubEntity;
import org.badminton.domain.club.repository.ClubRepository;
import org.badminton.domain.clubmember.entity.ClubMemberEntity;
import org.badminton.domain.clubmember.entity.ClubMemberRole;
import org.badminton.domain.clubmember.repository.ClubMemberRepository;
import org.badminton.domain.common.enums.MemberTier;
import org.badminton.domain.leaguerecord.entity.LeagueRecordEntity;
import org.badminton.domain.leaguerecord.repository.LeagueRecordRepository;
import org.badminton.domain.member.entity.MemberEntity;
Expand All @@ -33,12 +40,24 @@ public class ClubService {
private final ClubMemberRepository clubMemberRepository;
private final MemberRepository memberRepository;
private final LeagueRecordRepository leagueRecordRepository;
private final LeagueRecordService leagueRecordService;

public ClubReadResponse readClub(Long clubId) {
ClubEntity club = findClubByClubId(clubId);
return ClubReadResponse.clubEntityToClubReadResponse(club);
}

public List<ClubsReadResponse> readAllClub() {
List<ClubEntity> clubs = clubRepository.findAllByIsClubDeletedIsFalse();

return clubs.stream()
.map(club -> {
Map<MemberTier, Long> tierCounts = leagueRecordService.getMemberCountByTierInClub(club.getClubId());
return ClubsReadResponse.clubEntityToClubsReadResponse(club, tierCounts);
})
.collect(Collectors.toList());
}

// TODO: clubAddRequest에 이미지가 없으면 default 이미지를 넣어주도록 구현
@Transactional
public ClubCreateResponse createClub(ClubCreateRequest clubAddRequest, Long memberId) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
import org.badminton.api.member.oauth2.dto.CustomOAuth2Member;
import org.badminton.domain.member.repository.MemberRepository;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.Authentication;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
Expand All @@ -26,16 +26,14 @@ public class ClubMemberController {
description = "동호회에 가입을 신청합니다.",
tags = {"ClubMember"})
@PostMapping
public ResponseEntity<ClubMemberJoinResponse> joinClub(Authentication authentication,
public ResponseEntity<ClubMemberJoinResponse> joinClub(@AuthenticationPrincipal CustomOAuth2Member member,
@Parameter(description = "동호회 ID", example = "1") @RequestParam Long clubId) {

CustomOAuth2Member member = (CustomOAuth2Member)authentication.getPrincipal();
Long memberId = member.getMemberId();

ClubMemberJoinResponse clubMemberJoinResponse = clubMemberService.joinClub(memberId, clubId);

return ResponseEntity.ok(clubMemberJoinResponse);

}
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,30 @@
import org.badminton.domain.leaguerecord.entity.LeagueRecordEntity;
import org.badminton.domain.member.entity.MemberEntity;

import io.swagger.v3.oas.annotations.media.Schema;

public record ClubMemberInfoResponse(
@Schema(description = "회원 ID", example = "1")
Long memberId,
@Schema(description = "회원 이름", example = "김철수")
String name,
@Schema(description = "이메일", example = "sunn10189@gmail.com")
String email,
@Schema(description = "프로필 이미지", example = "https://lh3.googleusercontent.com/a/ACg8ocI_eGCDYzQe6vX3e4wCYpm6syVZ-UnGg9TZtm6S1U2K04PiAw=s96-c")
String profileImage,
@Schema(description = "동호회 회원 ID", example = "1")
Long clubMemberId,
@Schema(description = "동호회 이름", example = "동호회이름")
String clubName,
@Schema(description = "역할", example = "ROLE_USER")
ClubMemberRole role,
@Schema(description = "전적", example = "\"league_record_info_response\": {\n"
+ " \"win_count\": 0,\n"
+ " \"lose_count\": 0,\n"
+ " \"draw_count\": 0,\n"
+ " \"match_count\": 0,\n"
+ " \"tier\": \"BRONZE\"\n"
+ " }")
LeagueRecordInfoResponse leagueRecordInfoResponse

) implements MemberDetailResponse {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,4 +60,8 @@ public List<ClubMemberEntity> findAllClubMembersByMemberId(Long memberId) {
return clubMemberRepository.findAllByMember_MemberId(memberId);
}

public boolean isMemberOfClub(Long memberId, Long clubId) {
return clubMemberRepository.existsByMember_MemberIdAndClub_ClubId(memberId, clubId);
}

}
Loading

0 comments on commit 8acf0a0

Please sign in to comment.