Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/club simple #52

Merged
merged 4 commits into from
Jul 25, 2024
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
Binary file modified .gradle/8.8/checksums/checksums.lock
Binary file not shown.
Binary file modified .gradle/8.8/checksums/md5-checksums.bin
Binary file not shown.
Binary file modified .gradle/8.8/checksums/sha1-checksums.bin
Binary file not shown.
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.
8 changes: 8 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,14 @@ dependencies {

// swagger
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.0.2'

// s3
implementation 'org.springframework.cloud:spring-cloud-starter-aws:2.2.6.RELEASE'

// 파일 업로드
implementation 'commons-io:commons-io:2.6'
implementation 'commons-fileupload:commons-fileupload:1.4'

}

tasks.named('test') {
Expand Down
44 changes: 42 additions & 2 deletions src/main/java/likelion/MZConnent/api/club/ClubController.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,28 +2,36 @@

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.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
@RestController
@RequiredArgsConstructor
public class ClubController {
private final ClubService clubService;
private final ClubInfoService clubInfoService;
private final MemberRepository memberRepository;
private final RegionCategoryService regionCategoryService;

Expand Down Expand Up @@ -56,4 +64,36 @@ public ResponseEntity joinClub(@PathVariable Long clubId, @AuthenticationPrincip
clubService.joinClub(clubId, member);
return ResponseEntity.ok(Map.of("message","모임 가입 성공"));
}

@GetMapping("/api/clubs/{clubId}")
public ResponseEntity<ClubDetailResponse> getClubDetail(@PathVariable Long clubId, @AuthenticationPrincipal UserPrinciple userPrinciple) {
ClubDetailResponse clubDetail;
if (userPrinciple == null) {
clubDetail = clubInfoService.getClubDetail(clubId);
} else {
Member member = memberRepository.findByEmail(userPrinciple.getEmail())
.orElseThrow(() -> new IllegalArgumentException("존재하지 않는 사용자입니다."));
clubDetail = clubInfoService.getClubDetail(clubId, member);
}

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 @@ -25,7 +25,7 @@ public ResponseEntity<MemberInfoResponse> getMyInfo(@AuthenticationPrincipal Use
MemberInfoResponse memberInfo = memberService.getMemberInfoByEmail(email);

log.info("멤버 정보 조회 성공: {}", memberInfo.getUsername());

return ResponseEntity.ok(memberInfo);
}

Expand All @@ -38,4 +38,4 @@ public ResponseEntity<MemberInfoResponse> getMemberInfo(@PathVariable("userId")

return ResponseEntity.ok(memberInfo);
}
}
}
31 changes: 31 additions & 0 deletions src/main/java/likelion/MZConnent/config/S3Config.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package likelion.MZConnent.config;


import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.AWSStaticCredentialsProvider;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.s3.AmazonS3;
import com.amazonaws.services.s3.AmazonS3Client;
import com.amazonaws.services.s3.AmazonS3ClientBuilder;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
public class S3Config {
@Value("${cloud.aws.credentials.access-key}")
private String accessKey;
@Value("${cloud.aws.credentials.secret-key}")
private String secretKey;
@Value("${cloud.aws.region.static}")
private String region;

@Bean
public AmazonS3Client amazonS3Client(){
BasicAWSCredentials awsCreds = new BasicAWSCredentials(accessKey, secretKey);
return (AmazonS3Client) AmazonS3ClientBuilder.standard()
.withRegion(region)
.withCredentials(new AWSStaticCredentialsProvider(awsCreds))
.build();
}
}
3 changes: 2 additions & 1 deletion src/main/java/likelion/MZConnent/config/SecurityConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,11 @@ public class SecurityConfig {
"/api/auth/login", "/api/auth/logout", // 회원
"/api/categories/culture", // 문화
"/api/clubs", "/api/clubs/*/join", // 동아리
"/api/clubs/*",
"/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/auth/signup", "/api/categories/region", "/api/clubs/*", "/api/clubs/list"
};


Expand Down
22 changes: 22 additions & 0 deletions src/main/java/likelion/MZConnent/dto/club/LeaderDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package likelion.MZConnent.dto.club;

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

import java.util.List;

@Getter
@NoArgsConstructor
public class LeaderDto {
private String username;
private String profileImageUrl;
private List<SelfIntroductionDto> selfIntroductions;

@Builder
public LeaderDto(String username, String profileImageUrl, List<SelfIntroductionDto> selfIntroductions) {
this.username = username;
this.profileImageUrl = profileImageUrl;
this.selfIntroductions = selfIntroductions;
}
}
18 changes: 18 additions & 0 deletions src/main/java/likelion/MZConnent/dto/club/SelfIntroductionDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package likelion.MZConnent.dto.club;

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

@Getter
@NoArgsConstructor
public class SelfIntroductionDto {
private Long cultureCategoryId;
private String name;

@Builder
public SelfIntroductionDto(Long cultureCategoryId, String name) {
this.cultureCategoryId = cultureCategoryId;
this.name = name;
}
}
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,55 @@
package likelion.MZConnent.dto.club.response;

import likelion.MZConnent.domain.club.AgeRestriction;
import likelion.MZConnent.domain.club.GenderRestriction;
import likelion.MZConnent.dto.club.LeaderDto;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.extern.slf4j.Slf4j;

import java.time.LocalDate;
import java.time.LocalDateTime;
import java.util.List;

@Slf4j
@Getter
@NoArgsConstructor
public class ClubDetailResponse {
private Long clubId;
private String title;
private LocalDate meetingDate;
private LocalDateTime createdDate;
private String content;
private GenderRestriction genderRestriction;
private AgeRestriction ageRestriction;
private String cultureImageUrl;
private String cultureName;
private String regionName;
private int currentParticipant;
private int maxParticipant;
private String registrationStatus;
private List<LeaderDto> leader;

@Builder
public ClubDetailResponse(Long clubId, String title, LocalDate meetingDate, LocalDateTime createdDate, String content,
GenderRestriction genderRestriction, AgeRestriction ageRestriction, String cultureImageUrl,
String cultureName, String regionName, int currentParticipant, int maxParticipant,
String registrationStatus, List<LeaderDto> leader) {
this.clubId = clubId;
this.title = title;
this.meetingDate = meetingDate;
this.createdDate = createdDate;
this.content = content;
this.genderRestriction = genderRestriction;
this.ageRestriction = ageRestriction;
this.cultureImageUrl = cultureImageUrl;
this.cultureName = cultureName;
this.regionName = regionName;
this.currentParticipant = currentParticipant;
this.maxParticipant = maxParticipant;
this.registrationStatus = registrationStatus;
this.leader = leader;
}

}
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);
}

Loading
Loading