Skip to content

Commit

Permalink
feat: 모임 전체 리스트 조회 기능 구현
Browse files Browse the repository at this point in the history
  • Loading branch information
oosedus committed Jul 25, 2024
1 parent 48afe04 commit 7d05ae9
Show file tree
Hide file tree
Showing 10 changed files with 171 additions and 4 deletions.
Binary file modified .gradle/8.8/executionHistory/executionHistory.lock
Binary file not shown.
Binary file modified .gradle/8.8/fileHashes/fileHashes.lock
Binary file not shown.
Binary file modified .gradle/buildOutputCleanup/buildOutputCleanup.lock
Binary file not shown.
29 changes: 26 additions & 3 deletions src/main/java/likelion/MZConnent/api/club/ClubController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,28 @@

import jakarta.validation.Valid;
import likelion.MZConnent.domain.member.Member;
import likelion.MZConnent.dto.club.request.ClubSimpleRequest;
import likelion.MZConnent.dto.club.request.CreateClubRequest;
import likelion.MZConnent.dto.club.response.ClubDetailResponse;
import likelion.MZConnent.dto.club.response.CreateClubResponse;
import likelion.MZConnent.dto.club.response.RegionCategoryResponse;
import likelion.MZConnent.dto.club.response.*;
import likelion.MZConnent.jwt.principle.UserPrinciple;
import likelion.MZConnent.repository.member.MemberRepository;
import likelion.MZConnent.service.club.ClubInfoService;
import likelion.MZConnent.service.club.ClubService;
import likelion.MZConnent.service.club.RegionCategoryService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.PageRequest;
import org.springframework.data.domain.Pageable;
import org.springframework.data.domain.Sort;
import org.springframework.data.web.PageableDefault;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;

@Slf4j
Expand Down Expand Up @@ -73,4 +78,22 @@ public ResponseEntity<ClubDetailResponse> getClubDetail(@PathVariable Long clubI

return ResponseEntity.ok(clubDetail);
}

@GetMapping("/api/clubs/list")
public ResponseEntity<PageContentResponse<ClubSimpleResponse>> getClubList(
@RequestParam(value = "page", defaultValue = "0") int pageNumber,
@RequestParam(value = "sort", defaultValue = "createdDate") String sortWay,
@RequestBody ClubSimpleRequest request) {

Pageable pageable;
if(sortWay.equals("meetingDate")){
pageable = PageRequest.of(pageNumber, 6, Sort.by(sortWay).ascending());
}
else {
pageable = PageRequest.of(pageNumber, 6, Sort.by(sortWay).descending());
}

PageContentResponse<ClubSimpleResponse> clubList = clubInfoService.getClubList(request, pageable);
return ResponseEntity.ok(clubList);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public class SecurityConfig {
"/swagger", "/swagger-ui.html", "/swagger-ui/**", "/api-docs", "/api-docs/**", "/v3/api-docs/**", //swagger
};
private final String[] anonymousUrl = {
"/api/auth/signup", "/api/categories/region", "/api/clubs/*"
"/api/auth/signup", "/api/categories/region", "/api/clubs/*", "/api/clubs/list"
};


Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package likelion.MZConnent.dto.club.request;

import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class ClubSimpleRequest {
private Long cultureId;
private Long regionId;

@Builder
public ClubSimpleRequest(Long cultureId, Long regionId) {
this.cultureId = cultureId;
this.regionId = regionId;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package likelion.MZConnent.dto.club.response;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

import java.time.LocalDate;
import java.time.LocalDateTime;

@Getter
@NoArgsConstructor
public class ClubSimpleResponse {
private Long clubId;
private String title;
private Long regionId;
private String regionName;
private Long cultureCategoryId;
private String cultureName;
private String leaderProfileImage;
private LocalDate meetingDate;
private LocalDateTime createdDate;
private String genderRestriction;
private String ageRestriction;
private int currentParticipant;
private int maxParticipant;

@Builder
public ClubSimpleResponse(Long clubId, String title, Long regionId, String regionName, Long cultureCategoryId,
String cultureName, String leaderProfileImage, LocalDate meetingDate,
LocalDateTime createdDate, String genderRestriction, String ageRestriction,
int currentParticipant, int maxParticipant) {
this.clubId = clubId;
this.title = title;
this.regionId = regionId;
this.regionName = regionName;
this.cultureCategoryId = cultureCategoryId;
this.cultureName = cultureName;
this.leaderProfileImage = leaderProfileImage;
this.meetingDate = meetingDate;
this.createdDate = createdDate;
this.genderRestriction = genderRestriction;
this.ageRestriction = ageRestriction;
this.currentParticipant = currentParticipant;
this.maxParticipant = maxParticipant;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package likelion.MZConnent.dto.club.response;

import lombok.Getter;
import lombok.NoArgsConstructor;

import java.util.List;

@Getter
@NoArgsConstructor
public class PageContentResponse<T> {
private List<T> content;
private int totalPages;
private long totalElements;
private int size;

public PageContentResponse(List<T> content, int totalPages, long totalElements, int size) {
this.content = content;
this.totalPages = totalPages;
this.totalElements = totalElements;
this.size = size;
}
}
Original file line number Diff line number Diff line change
@@ -1,10 +1,24 @@
package likelion.MZConnent.repository.club;

import likelion.MZConnent.domain.club.Club;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

@Repository
public interface ClubRepository extends JpaRepository<Club, Long> {

// status가 OPEN인 클럽만 조회
// cultureId와 regionId가 0이면 무시
// cultureId와 regionId가 0이 아니면 해당 cultureId와 regionId에 맞는 클럽만 조회
@Query("SELECT c FROM Club c WHERE c.status = 'OPEN' " +
"AND (:cultureId = 0 OR c.culture.cultureId = :cultureId) " +
"AND (:regionId = 0 OR c.region.regionId = :regionId)")
Page<Club> findAllByFilters(@Param("cultureId") Long cultureId,
@Param("regionId") Long regionId,
Pageable pageable);
}

43 changes: 43 additions & 0 deletions src/main/java/likelion/MZConnent/service/club/ClubInfoService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,15 @@
import likelion.MZConnent.domain.member.Member;
import likelion.MZConnent.dto.club.LeaderDto;
import likelion.MZConnent.dto.club.SelfIntroductionDto;
import likelion.MZConnent.dto.club.request.ClubSimpleRequest;
import likelion.MZConnent.dto.club.response.ClubDetailResponse;
import likelion.MZConnent.dto.club.response.ClubSimpleResponse;
import likelion.MZConnent.dto.club.response.PageContentResponse;
import likelion.MZConnent.repository.club.ClubRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import likelion.MZConnent.domain.club.Club;

Expand Down Expand Up @@ -77,4 +82,42 @@ private ClubDetailResponse buildClubDetailResponse(Long clubId, Member member) {
.leader(leaderResponses)
.build();
}

public PageContentResponse<ClubSimpleResponse> getClubList(ClubSimpleRequest request, Pageable pageable) {
Page<Club> clubs = clubRepository.findAllByFilters(
request.getCultureId(),
request.getRegionId(),
pageable);

return new PageContentResponse<>(
clubs.stream()
.map(club -> ClubSimpleResponse.builder()
.clubId(club.getClubId())
.title(club.getTitle())
.regionId(club.getRegion().getRegionId())
.regionName(club.getRegion().getName())
.cultureCategoryId(club.getCulture().getCultureCategory().getId())
.cultureName(club.getCulture().getName())
.leaderProfileImage(getLeaderProfileImage(club))
.meetingDate(club.getMeetingDate())
.createdDate(club.getCreatedDate())
.genderRestriction(club.getGenderRestriction().name())
.ageRestriction(club.getAgeRestriction().name())
.currentParticipant(club.getCurrentParticipant())
.maxParticipant(club.getMaxParticipant())
.build())
.collect(Collectors.toList()),
clubs.getTotalPages(),
clubs.getTotalElements(),
pageable.getPageSize()
);
}

private String getLeaderProfileImage(Club club) {
return club.getClubMembers().stream()
.filter(cm -> cm.getClubRole() == ClubRole.LEADER)
.findFirst()
.map(cm -> cm.getMember().getProfileImageUrl())
.orElse(null);
}
}

0 comments on commit 7d05ae9

Please sign in to comment.