-
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.
Showing
21 changed files
with
344 additions
and
149 deletions.
There are no files selected for viewing
76 changes: 62 additions & 14 deletions
76
src/main/java/com/core/linkup/club/controller/ClubController.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 |
---|---|---|
@@ -1,34 +1,82 @@ | ||
package com.core.linkup.club.controller; | ||
|
||
import com.core.linkup.club.request.ClubRequest; | ||
import com.core.linkup.club.response.ClubsResponse; | ||
import com.core.linkup.club.requset.ClubCreateRequest; | ||
import com.core.linkup.club.requset.ClubSearchRequest; | ||
import com.core.linkup.club.requset.ClubUpdateRequest; | ||
import com.core.linkup.club.response.ClubSearchResponse; | ||
import com.core.linkup.club.service.ClubService; | ||
import com.core.linkup.common.response.BaseResponse; | ||
import com.core.linkup.security.MemberDetails; | ||
import jakarta.validation.Valid; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.data.domain.Sort; | ||
import org.springframework.data.web.PageableDefault; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.stereotype.Controller; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@Controller | ||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1/club") | ||
public class ClubController { | ||
|
||
private final ClubService clubService; | ||
|
||
//소모임 개별조회 | ||
@GetMapping("/{clubId}") | ||
public BaseResponse<ClubSearchResponse> findClub( | ||
@AuthenticationPrincipal MemberDetails member, | ||
@PathVariable Long clubId | ||
) { | ||
ClubSearchResponse response = clubService.findClub(clubId); | ||
return BaseResponse.response(response); | ||
} | ||
|
||
//소모임 필터링으로 조회 (ClubType으로 조회 가능) | ||
//TODO : OfficeBuilding으로 조회 가능 하도록 할 예정 | ||
@GetMapping("/search") | ||
public BaseResponse<Page<ClubSearchResponse>> findClubs( | ||
@PageableDefault(sort = "id", direction = Sort.Direction.ASC) Pageable pageable, | ||
@ModelAttribute ClubSearchRequest request | ||
) { | ||
Page<ClubSearchResponse> searchResponse = clubService.findClubs(pageable, request); | ||
return BaseResponse.response(searchResponse); | ||
} | ||
|
||
//소모임 등록 | ||
@PostMapping | ||
public BaseResponse<List<ClubsResponse>> clubRegister( | ||
public BaseResponse<ClubSearchResponse> create( | ||
@AuthenticationPrincipal MemberDetails member, | ||
@RequestBody ClubCreateRequest request | ||
) { | ||
ClubSearchResponse response = clubService.createClub(member, request); | ||
return BaseResponse.response(response); | ||
} | ||
|
||
//소모임 수정 | ||
@PutMapping("/{club_id}") | ||
public BaseResponse<ClubSearchResponse> update( | ||
@AuthenticationPrincipal MemberDetails member, | ||
@PathVariable("club_id") Long clubId, | ||
@RequestBody ClubUpdateRequest updateRequest | ||
) { | ||
ClubSearchResponse updatedClub = clubService.updateClub(member, clubId, updateRequest); | ||
return BaseResponse.response(updatedClub); | ||
} | ||
|
||
//소모임 삭제 | ||
@DeleteMapping("/{club_id}") | ||
public BaseResponse<String> delete( | ||
@AuthenticationPrincipal MemberDetails member, | ||
@Valid @RequestBody ClubRequest clubRequest | ||
@PathVariable("club_id") Long clubId | ||
) { | ||
List<ClubsResponse> clubsResponses = clubService.clubRegister(member, clubRequest); | ||
return BaseResponse.response(clubsResponses); | ||
clubService.delete(member, clubId); | ||
return BaseResponse.response("OK"); | ||
} | ||
|
||
// @GetMapping("/member/{memberId}") | ||
// public ResponseEntity<List<ClubSearchResponse28>> getClubsByMemberId(@PathVariable Long memberId) { | ||
// List<ClubSearchResponse28> response = clubService.getClubsByMemberId(memberId); | ||
// return ResponseEntity.ok(response); | ||
// } | ||
} |
66 changes: 66 additions & 0 deletions
66
src/main/java/com/core/linkup/club/converter/ClubConverter.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 |
---|---|---|
@@ -1,8 +1,74 @@ | ||
package com.core.linkup.club.converter; | ||
|
||
import com.core.linkup.club.entity.Club; | ||
import com.core.linkup.club.requset.ClubCreateRequest; | ||
import com.core.linkup.club.requset.ClubUpdateRequest; | ||
import com.core.linkup.club.response.ClubSearchResponse; | ||
import com.core.linkup.common.annotation.Converter; | ||
import com.core.linkup.common.entity.enums.ClubType; | ||
import com.core.linkup.common.exception.BaseException; | ||
import com.core.linkup.common.response.BaseResponseStatus; | ||
import com.core.linkup.member.entity.Member; | ||
|
||
@Converter | ||
public class ClubConverter { | ||
|
||
public ClubSearchResponse toClubResponse(Club club) { | ||
return ClubSearchResponse.builder() | ||
.id(club.getId()) | ||
.title(club.getTitle()) | ||
.introduction(club.getIntroduction()) | ||
.clubType(club.getCategory()) | ||
.recruitCount(club.getRecruitCount()) | ||
.build(); | ||
} | ||
|
||
|
||
public Club toClubEntity(ClubCreateRequest request, Long memberId) { | ||
ClubType category; | ||
try { | ||
category = ClubType.fromKor(String.valueOf(request.clubType())); | ||
} catch (IllegalArgumentException e) { | ||
throw new BaseException(BaseResponseStatus.INVALID_REQUEST); | ||
} | ||
Club club = Club.builder() | ||
.category(String.valueOf(category)) | ||
.clubAccessibility(request.clubAccessibility()) | ||
.title(request.title()) | ||
.introduction(request.introduction()) | ||
.recruitCount(request.recruitCount()) | ||
.detailedIntroduction(request.detailedIntroduction()) | ||
.applicationIntroduction(request.applicationIntroduction()) | ||
.clubThumbnail(request.clubThumbnail()) | ||
.member( | ||
Member.builder().id(memberId).build()) | ||
.build(); | ||
|
||
//TODO : list로 question 받는거 해야 함, clubid르 null로 받아옴 | ||
// Optional.ofNullable(request.clubQuestions()).orElse(List.of()).forEach(q -> { | ||
// ClubQuestion clubQuestion = ClubQuestion.builder() | ||
// .question(q.getQuestion()) | ||
// .qorders(q.getQorders()) | ||
// .build(); | ||
// clubQuestion.setClub(club); | ||
// club.getClubQuestions().add(clubQuestion); | ||
// }); | ||
|
||
return club; | ||
} | ||
|
||
public Club updateClubEntity(Club updateClub, ClubUpdateRequest updateRequest) { | ||
ClubType category = ClubType.fromKor(String.valueOf(updateRequest.clubType())); | ||
return Club.builder() | ||
.id(updateClub.getId()) | ||
.category(String.valueOf(category)) | ||
.title(updateRequest.title()) | ||
.introduction(updateRequest.introduction()) | ||
.recruitCount(updateRequest.recruitCount()) | ||
.detailedIntroduction(updateRequest.detailedIntroduction()) | ||
.applicationIntroduction(updateRequest.applicationIntroduction()) | ||
.clubThumbnail(updateRequest.clubThumbnail()) | ||
.build(); | ||
} | ||
|
||
} |
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
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
13 changes: 13 additions & 0 deletions
13
src/main/java/com/core/linkup/club/repository/ClubCustomRepository.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,13 @@ | ||
package com.core.linkup.club.repository; | ||
|
||
import com.core.linkup.club.entity.Club; | ||
import com.core.linkup.club.requset.ClubSearchRequest; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
import java.util.List; | ||
|
||
public interface ClubCustomRepository { | ||
|
||
Page<Club> findSearchClubs(ClubSearchRequest request, Pageable pageable); | ||
} |
49 changes: 49 additions & 0 deletions
49
src/main/java/com/core/linkup/club/repository/ClubCustomRepositoryImpl.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,49 @@ | ||
package com.core.linkup.club.repository; | ||
|
||
import com.core.linkup.club.entity.Club; | ||
import com.core.linkup.club.entity.QClub; | ||
import com.core.linkup.club.requset.ClubSearchRequest; | ||
import com.core.linkup.common.entity.enums.ClubType; | ||
import com.querydsl.core.BooleanBuilder; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageImpl; | ||
import org.springframework.data.domain.Pageable; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class ClubCustomRepositoryImpl implements ClubCustomRepository { | ||
|
||
private final JPAQueryFactory queryFactory; | ||
|
||
@Override | ||
public Page<Club> findSearchClubs(ClubSearchRequest request, Pageable pageable) { | ||
QClub club = QClub.club; | ||
|
||
BooleanBuilder booleanBuilder = new BooleanBuilder(); | ||
|
||
// if (request.getOfficeBuildingId() != null) { | ||
// booleanBuilder.and(club.officeBuilding.id.eq(request.getOfficeBuildingId())); | ||
// } | ||
if (request.getClubType() != null && !request.getClubType().isEmpty()) { | ||
ClubType clubType = ClubType.fromKor(request.getClubType()); | ||
booleanBuilder.and(club.category.eq(String.valueOf(clubType))); | ||
} | ||
|
||
List<Club> clubs = queryFactory.selectFrom(club) | ||
.where(booleanBuilder) | ||
.offset(pageable.getOffset()) | ||
.limit(pageable.getPageSize()) | ||
.fetch(); | ||
|
||
long total = queryFactory.selectFrom(club) | ||
.where(booleanBuilder) | ||
.fetchCount(); | ||
|
||
return new PageImpl<>(clubs, pageable, total); | ||
} | ||
} |
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
10 changes: 10 additions & 0 deletions
10
src/main/java/com/core/linkup/club/request/ClubQuestionRequest.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,10 @@ | ||
package com.core.linkup.club.request; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ClubQuestionRequest( | ||
String question, | ||
Integer orders | ||
) { | ||
} |
20 changes: 0 additions & 20 deletions
20
src/main/java/com/core/linkup/club/request/ClubRequest.java
This file was deleted.
Oops, something went wrong.
19 changes: 19 additions & 0 deletions
19
src/main/java/com/core/linkup/club/requset/ClubCreateRequest.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,19 @@ | ||
package com.core.linkup.club.requset; | ||
|
||
import com.fasterxml.jackson.annotation.JsonProperty; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record ClubCreateRequest( | ||
String title, | ||
String introduction, | ||
@JsonProperty("category") | ||
String clubType, | ||
Integer recruitCount, | ||
Boolean clubAccessibility, | ||
String detailedIntroduction, | ||
String clubThumbnail, | ||
String applicationIntroduction | ||
// List<ClubQuestion> clubQuestions | ||
) { | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/core/linkup/club/requset/ClubSearchRequest.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,14 @@ | ||
package com.core.linkup.club.requset; | ||
|
||
import lombok.*; | ||
|
||
@Getter | ||
@RequiredArgsConstructor | ||
@AllArgsConstructor | ||
@Setter | ||
public class ClubSearchRequest { | ||
|
||
private Long officeBuildingId; | ||
private String clubType; | ||
|
||
} |
Oops, something went wrong.