-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #67 from LIKELION-TEAM4-HACKATHON/feature/myclub
나의 모임 간단 및 상세 조회 기능
- Loading branch information
Showing
8 changed files
with
262 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
35 changes: 35 additions & 0 deletions
35
src/main/java/likelion/MZConnent/api/club/MyClubController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
package likelion.MZConnent.api.club; | ||
|
||
import likelion.MZConnent.dto.club.response.MyClubDetailResponse; | ||
import likelion.MZConnent.dto.club.response.MyClubSimpleResponse; | ||
import likelion.MZConnent.jwt.principle.UserPrinciple; | ||
import likelion.MZConnent.service.club.MyClubService; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Slf4j | ||
@RequiredArgsConstructor | ||
@RestController | ||
public class MyClubController { | ||
private final MyClubService myClubService; | ||
|
||
@GetMapping("/api/users/clubs") | ||
public ResponseEntity<MyClubSimpleResponse> getMyClubs(@AuthenticationPrincipal UserPrinciple userPrinciple) { | ||
MyClubSimpleResponse response = myClubService.getMyClubs(userPrinciple.getEmail()); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
@GetMapping("/api/users/clubs/{clubId}") | ||
public ResponseEntity<MyClubDetailResponse> getMyClubDetail(@AuthenticationPrincipal UserPrinciple userPrinciple, @PathVariable Long clubId) { | ||
MyClubDetailResponse response = myClubService.getMyClubDetail(userPrinciple.getEmail(), clubId); | ||
return ResponseEntity.ok(response); | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
src/main/java/likelion/MZConnent/dto/club/response/MyClubDetailResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package likelion.MZConnent.dto.club.response; | ||
|
||
import likelion.MZConnent.domain.club.ClubRole; | ||
import likelion.MZConnent.domain.member.Age; | ||
import likelion.MZConnent.domain.member.Gender; | ||
import likelion.MZConnent.dto.club.SelfIntroductionDto; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public class MyClubDetailResponse { | ||
private Long clubId; | ||
private String title; | ||
private LocalDate meetingDate; | ||
private String content; | ||
private int currentParticipant; | ||
private MyClubCultureDto culture; | ||
private List<MyClubMemberDto> members; | ||
|
||
@Builder | ||
public MyClubDetailResponse(Long clubId, String title, LocalDate meetingDate, String content, int currentParticipant, MyClubCultureDto culture, List<MyClubMemberDto> members) { | ||
this.clubId = clubId; | ||
this.title = title; | ||
this.meetingDate = meetingDate; | ||
this.content = content; | ||
this.currentParticipant = currentParticipant; | ||
this.culture = culture; | ||
this.members = members; | ||
} | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public static class MyClubCultureDto { | ||
private Long cultureId; | ||
private String name; | ||
|
||
@Builder | ||
public MyClubCultureDto(Long cultureId, String name) { | ||
this.cultureId = cultureId; | ||
this.name = name; | ||
} | ||
} | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public static class MyClubMemberDto { | ||
private Long userId; | ||
private String username; | ||
private String profileImageUrl; | ||
private Age age; | ||
private Gender gender; | ||
private ClubRole role; | ||
private List<SelfIntroductionDto> selfIntroductions; | ||
|
||
@Builder | ||
public MyClubMemberDto(Long userId, String username, String profileImageUrl, Age age, Gender gender, ClubRole role, List<SelfIntroductionDto> selfIntroductions) { | ||
this.userId = userId; | ||
this.username = username; | ||
this.profileImageUrl = profileImageUrl; | ||
this.age = age; | ||
this.gender = gender; | ||
this.role = role; | ||
this.selfIntroductions = selfIntroductions; | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/likelion/MZConnent/dto/club/response/MyClubSimpleResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package likelion.MZConnent.dto.club.response; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@Slf4j | ||
@Getter | ||
@NoArgsConstructor | ||
public class MyClubSimpleResponse { | ||
private List<MyClubSimpleDto> myClubs; | ||
|
||
@Builder | ||
public MyClubSimpleResponse(List<MyClubSimpleDto> myClubs) { | ||
this.myClubs = myClubs; | ||
} | ||
|
||
@Getter | ||
@NoArgsConstructor | ||
public static class MyClubSimpleDto { | ||
private Long clubId; | ||
private String title; | ||
private String cultureName; | ||
private LocalDate meetingDate; | ||
private int currentParticipant; | ||
private int maxParticipant; | ||
|
||
@Builder | ||
public MyClubSimpleDto(Long clubId, String title, String cultureName, LocalDate meetingDate, int currentParticipant, int maxParticipant) { | ||
this.clubId = clubId; | ||
this.title = title; | ||
this.cultureName = cultureName; | ||
this.meetingDate = meetingDate; | ||
this.currentParticipant = currentParticipant; | ||
this.maxParticipant = maxParticipant; | ||
} | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/main/java/likelion/MZConnent/service/club/MyClubService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
package likelion.MZConnent.service.club; | ||
|
||
import likelion.MZConnent.domain.club.Club; | ||
import likelion.MZConnent.domain.member.Member; | ||
import likelion.MZConnent.dto.club.SelfIntroductionDto; | ||
import likelion.MZConnent.dto.club.response.MyClubDetailResponse; | ||
import likelion.MZConnent.dto.club.response.MyClubSimpleResponse; | ||
import likelion.MZConnent.repository.member.MemberRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Slf4j | ||
public class MyClubService { | ||
private final MemberRepository memberRepository; | ||
|
||
public MyClubSimpleResponse getMyClubs(String email) { | ||
Member member = getMemberByEmail(email); | ||
List<Club> clubList = getClubsByMember(member); | ||
|
||
List<MyClubSimpleResponse.MyClubSimpleDto> myClubs = clubList.stream() | ||
.map(this::convertToSimpleDto) | ||
.collect(Collectors.toList()); | ||
|
||
return MyClubSimpleResponse.builder() | ||
.myClubs(myClubs) | ||
.build(); | ||
} | ||
|
||
private List<Club> getClubsByMember(Member member) { | ||
return member.getClubMembers().stream() | ||
.map(cm -> cm.getClub()) | ||
.collect(Collectors.toList()); | ||
} | ||
|
||
private MyClubSimpleResponse.MyClubSimpleDto convertToSimpleDto(Club club) { | ||
return MyClubSimpleResponse.MyClubSimpleDto.builder() | ||
.clubId(club.getClubId()) | ||
.title(club.getTitle()) | ||
.cultureName(club.getCulture().getName()) | ||
.meetingDate(club.getMeetingDate()) | ||
.currentParticipant(club.getClubMembers().size()) | ||
.maxParticipant(club.getMaxParticipant()) | ||
.build(); | ||
} | ||
|
||
public MyClubDetailResponse getMyClubDetail(String email, Long clubId) { | ||
Member member = getMemberByEmail(email); | ||
Club club = getClubByMemberAndId(member, clubId); | ||
|
||
MyClubDetailResponse.MyClubCultureDto cultureDto = convertToCultureDto(club); | ||
List<MyClubDetailResponse.MyClubMemberDto> memberDtos = convertToMemberDtos(club); | ||
|
||
return MyClubDetailResponse.builder() | ||
.clubId(club.getClubId()) | ||
.title(club.getTitle()) | ||
.meetingDate(club.getMeetingDate()) | ||
.content(club.getContent()) | ||
.currentParticipant(club.getClubMembers().size()) | ||
.culture(cultureDto) | ||
.members(memberDtos) | ||
.build(); | ||
} | ||
|
||
private Member getMemberByEmail(String email) { | ||
return memberRepository.findByEmail(email) | ||
.orElseThrow(() -> new IllegalArgumentException("존재하지 않는 사용자입니다.")); | ||
} | ||
|
||
private Club getClubByMemberAndId(Member member, Long clubId) { | ||
return member.getClubMembers().stream() | ||
.map(cm -> cm.getClub()) | ||
.filter(c -> c.getClubId().equals(clubId)) | ||
.findFirst() | ||
.orElseThrow(() -> new IllegalArgumentException("해당 클럽을 찾을 수 없습니다.")); | ||
} | ||
|
||
private MyClubDetailResponse.MyClubCultureDto convertToCultureDto(Club club) { | ||
return MyClubDetailResponse.MyClubCultureDto.builder() | ||
.cultureId(club.getCulture().getCultureId()) | ||
.name(club.getCulture().getName()) | ||
.build(); | ||
} | ||
|
||
private List<MyClubDetailResponse.MyClubMemberDto> convertToMemberDtos(Club club) { | ||
return club.getClubMembers().stream() | ||
.map(cm -> MyClubDetailResponse.MyClubMemberDto.builder() | ||
.userId(cm.getMember().getId()) | ||
.username(cm.getMember().getUsername()) | ||
.profileImageUrl(cm.getMember().getProfileImageUrl()) | ||
.age(cm.getMember().getAge()) | ||
.gender(cm.getMember().getGender()) | ||
.role(cm.getClubRole()) | ||
.selfIntroductions(cm.getMember().getSelfIntroductions().stream() | ||
.map(si -> SelfIntroductionDto.builder() | ||
.cultureCategoryId(si.getCultureCategory().getId()) | ||
.name(si.getCultureCategory().getName()) | ||
.build()) | ||
.collect(Collectors.toList())) | ||
.build()) | ||
.collect(Collectors.toList()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters