-
Notifications
You must be signed in to change notification settings - Fork 0
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 #13 from GDSC-Hongik/feature/round
round 전체 완성
- Loading branch information
Showing
11 changed files
with
339 additions
and
22 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
66 changes: 66 additions & 0 deletions
66
src/main/java/com/gdgoc/study_group/round/controller/RoundController.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,66 @@ | ||
package com.gdgoc.study_group.round.controller; | ||
|
||
import com.gdgoc.study_group.round.dto.CreateRoundRequest; | ||
import com.gdgoc.study_group.round.dto.RoundDTO; | ||
import com.gdgoc.study_group.round.dto.RoundThumbnailDTO; | ||
import com.gdgoc.study_group.round.dto.UpdateRoundRequest; | ||
import com.gdgoc.study_group.round.service.RoundService; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.Parameter; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
@RestController | ||
@RequestMapping("/studies/{studyId}/rounds") | ||
@RequiredArgsConstructor | ||
@Tag(name = "Round API", description = "스터디 회차 관련 API") | ||
public class RoundController { | ||
|
||
private final RoundService roundService; | ||
|
||
@GetMapping | ||
@Operation(summary = "특정 스터디의 모든 회차 조회", description = "특정 스터디의 모든 회차 정보를 조회합니다.") | ||
public ResponseEntity<List<RoundDTO>> getRoundsByStudy( | ||
@Parameter(description = "스터디 ID", required = true) @PathVariable Long studyId) { | ||
return ResponseEntity.ok(roundService.getRoundsByStudyId(studyId)); | ||
} | ||
|
||
@GetMapping("/{roundId}") | ||
@Operation(summary = "특정 회차 정보 조회", description = "특정 회차의 정보를 조회합니다.") | ||
public ResponseEntity<RoundDTO> getRound( | ||
@Parameter(description = "스터디 ID", required = true) @PathVariable Long studyId, | ||
@Parameter(description = "회차 ID", required = true) @PathVariable Long roundId) { | ||
return ResponseEntity.ok(roundService.getRound(roundId)); | ||
} | ||
|
||
@PostMapping | ||
@Operation(summary = "회차 생성", description = "새로운 회차를 생성합니다.") | ||
public ResponseEntity<RoundDTO> createRound( | ||
@Parameter(description = "스터디 ID", required = true) @PathVariable Long studyId, | ||
@RequestBody CreateRoundRequest request) { | ||
return ResponseEntity.ok(roundService.createRound(studyId, request)); | ||
} | ||
|
||
@PatchMapping("/{roundId}") | ||
@Operation(summary = "회차 수정", description = "기존 회차의 정보를 수정합니다.") | ||
public ResponseEntity<RoundDTO> updateRound( | ||
@Parameter(description = "스터디 ID", required = true) @PathVariable Long studyId, | ||
@Parameter(description = "회차 ID", required = true) @PathVariable Long roundId, | ||
@RequestBody UpdateRoundRequest request) { | ||
return ResponseEntity.ok(roundService.updateRound(roundId, request)); | ||
} | ||
|
||
@DeleteMapping("/{roundId}") | ||
@Operation(summary = "회차 삭제", description = "기존 회차를 삭제합니다.") | ||
public ResponseEntity<Void> deleteRound( | ||
@Parameter(description = "스터디 ID", required = true) @PathVariable Long studyId, | ||
@Parameter(description = "회차 ID", required = true) @PathVariable Long roundId) { | ||
roundService.deleteRound(roundId); | ||
return ResponseEntity.noContent().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
11 changes: 11 additions & 0 deletions
11
src/main/java/com/gdgoc/study_group/round/dto/CreateRoundRequest.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,11 @@ | ||
package com.gdgoc.study_group.round.dto; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
public record CreateRoundRequest( | ||
String goal, | ||
String studyDetail, | ||
LocalDate roundDate, | ||
List<RoundThumbnailDTO> thumbnails | ||
) {} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/gdgoc/study_group/round/dto/RoundDTO.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,29 @@ | ||
package com.gdgoc.study_group.round.dto; | ||
|
||
import com.fasterxml.jackson.annotation.JsonFormat; | ||
import com.gdgoc.study_group.round.domain.Round; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
import java.util.stream.Collectors; | ||
|
||
public record RoundDTO( | ||
Long id, | ||
String goal, | ||
String studyDetail, | ||
@JsonFormat(pattern = "yyyy-MM-dd") | ||
LocalDate roundDate, | ||
List<RoundThumbnailDTO> thumbnails | ||
) { | ||
public static RoundDTO from(Round round) { | ||
return new RoundDTO( | ||
round.getId(), | ||
round.getGoal(), | ||
round.getStudyDetail(), | ||
round.getRoundDate(), | ||
round.getImages().stream() | ||
.map(RoundThumbnailDTO::from) | ||
.collect(Collectors.toList()) | ||
); | ||
} | ||
} |
19 changes: 19 additions & 0 deletions
19
src/main/java/com/gdgoc/study_group/round/dto/RoundThumbnailDTO.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.gdgoc.study_group.round.dto; | ||
|
||
import com.gdgoc.study_group.round.domain.RoundThumbnail; | ||
|
||
public record RoundThumbnailDTO( | ||
Long id, | ||
String fileName, | ||
String filePath, | ||
String type | ||
) { | ||
public static RoundThumbnailDTO from(RoundThumbnail thumbnail) { | ||
return new RoundThumbnailDTO( | ||
thumbnail.getId(), | ||
thumbnail.getFileName(), | ||
thumbnail.getFilePath(), | ||
thumbnail.getType() | ||
); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/gdgoc/study_group/round/dto/UpdateRoundRequest.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,11 @@ | ||
package com.gdgoc.study_group.round.dto; | ||
|
||
import java.time.LocalDate; | ||
import java.util.List; | ||
|
||
public record UpdateRoundRequest( | ||
String goal, | ||
String studyDetail, | ||
LocalDate roundDate, | ||
List<RoundThumbnailDTO> thumbnails | ||
) {} |
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
31 changes: 31 additions & 0 deletions
31
src/main/java/com/gdgoc/study_group/round/repository/RoundThumbnailRepository.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,31 @@ | ||
package com.gdgoc.study_group.round.repository; | ||
|
||
import com.gdgoc.study_group.round.domain.RoundThumbnail; | ||
import java.util.List; | ||
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 RoundThumbnailRepository extends JpaRepository<RoundThumbnail, Long> { | ||
|
||
// ================ ROUND THUMBNAIL ================ // | ||
/** | ||
* 특정 회차의 모든 썸네일을 조회합니다 | ||
* | ||
* @param roundId 회차 아이디 | ||
* @return 해당 회차의 모든 썸네일 List | ||
*/ | ||
@Query("SELECT rt FROM RoundThumbnail rt WHERE rt.round.id = :roundId") | ||
List<RoundThumbnail> findThumbnailsByRoundId(@Param("roundId") Long roundId); | ||
|
||
/** | ||
* 특정 회원이 업로드한 모든 썸네일을 조회합니다 | ||
* | ||
* @param memberId 회원 아이디 | ||
* @return 해당 회원이 업로드한 모든 썸네일 List | ||
*/ | ||
@Query("SELECT rt FROM RoundThumbnail rt WHERE rt.member.id = :memberId") | ||
List<RoundThumbnail> findThumbnailsByMemberId(@Param("memberId") Long memberId); | ||
} |
Oops, something went wrong.