forked from kookmin-sw/cap-template
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
19 changed files
with
364 additions
and
17 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
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
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
73 changes: 73 additions & 0 deletions
73
backend/src/main/java/com/project/capstone/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 |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package com.project.capstone.club.controller; | ||
|
||
import com.project.capstone.auth.domain.PrincipalDetails; | ||
import com.project.capstone.club.controller.dto.ClubCreateRequest; | ||
import com.project.capstone.club.controller.dto.ClubResponse; | ||
import com.project.capstone.club.service.ClubService; | ||
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.*; | ||
|
||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/club") | ||
@Slf4j | ||
public class ClubController { | ||
private final ClubService clubService; | ||
// 모임 불러오기 | ||
@GetMapping("/search/{id}") | ||
public ResponseEntity<?> getClub(@PathVariable Long id) { | ||
ClubResponse clubResponse = clubService.getClub(id); | ||
return ResponseEntity.ok().body(clubResponse); | ||
} | ||
|
||
// 모임 주제별 검색 | ||
@GetMapping("/search/topic") | ||
public ResponseEntity<List<ClubResponse>> searchByTopic(@RequestParam String topic) { | ||
List<ClubResponse> clubResponseList = clubService.searchByTopic(topic); | ||
return ResponseEntity.ok().body(clubResponseList); | ||
} | ||
// 모임 이름으로 검색 | ||
@GetMapping("/search/name") | ||
public ResponseEntity<?> searchByName(@RequestParam String name) { | ||
List<ClubResponse> clubResponseList = clubService.searchByName(name); | ||
return ResponseEntity.ok().body(clubResponseList); | ||
} | ||
// 모임 생성하기 | ||
@PostMapping("/create") | ||
public ResponseEntity<?> createClub(@RequestBody ClubCreateRequest request, @AuthenticationPrincipal PrincipalDetails details) { | ||
clubService.createClub(request, details.getUserId()); | ||
return ResponseEntity.ok().body("모임 생성 완료"); | ||
} | ||
// 모임 가입하기 | ||
@GetMapping("/join") | ||
public ResponseEntity<?> join(@AuthenticationPrincipal PrincipalDetails details, @RequestParam Long clubId) { | ||
clubService.join(details.getUserId(), clubId); | ||
return ResponseEntity.ok().body("모임 가입 완료"); | ||
} | ||
// 모임 탈퇴하기 | ||
@GetMapping("/out") | ||
public ResponseEntity<?> out(@AuthenticationPrincipal PrincipalDetails details, @RequestParam Long clubId) { | ||
clubService.out(details.getUserId(), clubId); | ||
return ResponseEntity.ok().body("모임 탈퇴 완료"); | ||
} | ||
// 모임장 위임하기 | ||
@PutMapping("/delegate") | ||
public ResponseEntity<?> delegateManager(@AuthenticationPrincipal PrincipalDetails details, | ||
@RequestParam UUID memberId, @RequestParam Long clubId) { | ||
clubService.delegateManager(details, memberId, clubId); | ||
return ResponseEntity.ok().body("위임 완료"); | ||
} | ||
// 멤버 추방하기 | ||
@GetMapping("/expel") | ||
public ResponseEntity<?> expelMember(@AuthenticationPrincipal PrincipalDetails details, | ||
@RequestParam UUID memberId, @RequestParam Long clubId) { | ||
clubService.expelMember(details, memberId, clubId); | ||
return ResponseEntity.ok().body("추방 완료"); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
backend/src/main/java/com/project/capstone/club/controller/dto/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,12 @@ | ||
package com.project.capstone.club.controller.dto; | ||
|
||
import com.project.capstone.club.domain.PublicStatus; | ||
|
||
public record ClubCreateRequest( | ||
String topic, | ||
String name, | ||
int maximum, | ||
PublicStatus publicStatus, | ||
Integer password | ||
) { | ||
} |
20 changes: 20 additions & 0 deletions
20
backend/src/main/java/com/project/capstone/club/controller/dto/ClubResponse.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,20 @@ | ||
package com.project.capstone.club.controller.dto; | ||
|
||
import com.project.capstone.club.domain.Club; | ||
import com.project.capstone.club.domain.PublicStatus; | ||
|
||
import java.time.LocalDateTime; | ||
|
||
public record ClubResponse ( | ||
Long id, | ||
Long bookId, | ||
String topic, | ||
String name, | ||
LocalDateTime createdAt, | ||
int maximum, | ||
PublicStatus publicstatus | ||
) { | ||
public ClubResponse(Club club) { | ||
this(club.getId(), club.getBook() == null ? null : club.getBook().getId(), club.getTopic(), club.getName(), club.getCreatedAt(), club.getMaximum(), club.getPublicStatus()); | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
backend/src/main/java/com/project/capstone/club/domain/ClubRepository.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,18 @@ | ||
package com.project.capstone.club.domain; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import java.util.UUID; | ||
|
||
public interface ClubRepository extends JpaRepository<Club, Long> { | ||
List<Club> findClubsByTopic(String topic); | ||
List<Club> findClubsByNameContaining(String name); | ||
Optional<Club> findClubById(Long id); | ||
@Modifying(clearAutomatically = true) | ||
@Query("update Club c set c.managerId = :id") | ||
void updateManager(UUID id); | ||
} |
25 changes: 25 additions & 0 deletions
25
backend/src/main/java/com/project/capstone/club/domain/PublicStatus.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,25 @@ | ||
package com.project.capstone.club.domain; | ||
|
||
import com.fasterxml.jackson.annotation.JsonCreator; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@AllArgsConstructor | ||
public enum PublicStatus { | ||
PUBLIC("공개"), | ||
PRIVATE("비공개"); | ||
|
||
private final String description; | ||
|
||
|
||
@JsonCreator | ||
public static PublicStatus from(String status) { | ||
for (PublicStatus publicStatus : PublicStatus.values()) { | ||
if (publicStatus.getDescription().equals(status)) { | ||
return publicStatus; | ||
} | ||
} | ||
throw new RuntimeException("잘못된 공개 여부입니다."); | ||
} | ||
} |
Oops, something went wrong.