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

round 전체 완성 #13

Merged
merged 2 commits into from
Feb 4, 2025
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
38 changes: 19 additions & 19 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -40,25 +40,25 @@ tasks.named('test') {
useJUnitPlatform()
}

spotless {
java {
importOrder(
'java|javax|jakarta',
'org.springframework',
'lombok',
'',
'org.junit|org.mockito',
'\\#',
'\\#org.junit'
)

googleJavaFormat()
formatAnnotations()
removeUnusedImports()
trimTrailingWhitespace()
endWithNewline()
}
}
//spotless {
// java {
// importOrder(
// 'java|javax|jakarta',
// 'org.springframework',
// 'lombok',
// '',
// 'org.junit|org.mockito',
// '\\#',
// '\\#org.junit'
// )
//
// googleJavaFormat()
// formatAnnotations()
// removeUnusedImports()
// trimTrailingWhitespace()
// endWithNewline()
// }
//}

tasks.register("updateGitHooks", Copy) {
from "./scripts/pre-commit"
Expand Down
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();
}
}
22 changes: 21 additions & 1 deletion src/main/java/com/gdgoc/study_group/round/domain/Round.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,17 @@
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import lombok.*;

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

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder
public class Round {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
Expand All @@ -36,4 +42,18 @@ public class Round {
private String goal; // 학습 목표
private String studyDetail; // 학습 내용
private LocalDate roundDate; // 회차 진행한 날짜
}

@Builder
public Round(Study study, String goal, String studyDetail, LocalDate roundDate) {
this.study = study;
this.goal = goal;
this.studyDetail = studyDetail;
this.roundDate = roundDate;
}

public void updateDetails(String goal, String studyDetail, LocalDate roundDate) {
this.goal = goal;
this.studyDetail = studyDetail;
this.roundDate = roundDate;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,8 +9,13 @@
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import lombok.*;

@Entity
@Getter
@NoArgsConstructor(access = AccessLevel.PROTECTED)
@AllArgsConstructor(access = AccessLevel.PRIVATE)
@Builder
@Table(name = "ROUND_THUMBNAIL")
public class RoundThumbnail {
@Id
Expand All @@ -28,4 +33,12 @@ public class RoundThumbnail {
private String fileName;
private String filePath; // 파일의 이름을 제외한 저장 위치
private String type; // jpeg, png...
}

@Builder
public RoundThumbnail(Round round, String fileName, String filePath, String type) {
this.round = round;
this.fileName = fileName;
this.filePath = filePath;
this.type = type;
}
}
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 src/main/java/com/gdgoc/study_group/round/dto/RoundDTO.java
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())
);
}
}
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()
);
}
}
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
) {}
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package com.gdgoc.study_group.round.dao;
package com.gdgoc.study_group.round.repository;

import com.gdgoc.study_group.comment.domain.Comment;
import com.gdgoc.study_group.round.domain.Round;

import java.time.LocalDate;
import java.util.List;
import java.util.Optional;
import org.springframework.data.jpa.repository.JpaRepository;
Expand All @@ -11,6 +13,25 @@

@Repository
public interface RoundRepository extends JpaRepository<Round, Long> {
// ================ ROUND ================ //
/**
* 특정 스터디의 모든 회차를 조회합니다
*
* @param studyId 스터디 아이디
* @return 해당 스터디의 모든 회차 List
*/
@Query("SELECT r FROM Round r WHERE r.study.id = :studyId")
List<Round> findRoundsByStudyId(@Param("studyId") Long studyId);

/**
* 특정 날짜에 진행되는 회차를 조회합니다
*
* @param roundDate 조회할 날짜
* @return 해당 날짜에 진행되는 회차 List
*/
@Query("SELECT r FROM Round r WHERE r.roundDate = :roundDate")
List<Round> findRoundsByDate(@Param("roundDate") LocalDate roundDate);

// ================ COMMENT ================ //
/**
* 회차의 모든 댓글 조회
Expand Down
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);
}
Loading
Loading