Skip to content

Commit 18f70c1

Browse files
회차 생성, 수정 요청 DTO 수정, 일부 변화
CreateRoundRequest, UpdateRoundRequest 생성 컨트롤러, 도메인, dto, service 일부 수정 @operation(summary = "회차 생성", description = "새로운 회차를 생성합니다.") public ResponseEntity<RoundDTO> createRound( @parameter(description = "스터디 ID", required = true) @PathVariable Long studyId, @RequestParam String goal, Member 묶어서 requestDTO 하나 만드는게 좋아보여요 src/main/java/com/gdgoc/study_group/round/controller/RoundController.java public ResponseEntity<RoundDTO> updateRound( @parameter(description = "스터디 ID", required = true) @PathVariable Long studyId, @parameter(description = "회차 ID", required = true) @PathVariable Long roundId, @RequestParam String goal, Member 여기도 묶어서 DTO로 바꾸는게 좋아보여요 @entity @Getter @NoArgsConstructor Member 다른 분들이랑 통일해서 noarg 는 protected로, allarg 는 private으로 만들고, builder annotation 은 클래스 위로 옮기는게 어떨까요 @entity @Getter @NoArgsConstructor Member 여기도 위처럼 noarg, allarg, builder 같은 이야기입니다 @service @requiredargsconstructor @transactional Member@cmj7271 readOnly 로 바꿔주세요 자세한 내용은 디스코드에 적혀있어요
1 parent d536ba1 commit 18f70c1

File tree

9 files changed

+109
-106
lines changed

9 files changed

+109
-106
lines changed

build.gradle

Lines changed: 19 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -40,25 +40,25 @@ tasks.named('test') {
4040
useJUnitPlatform()
4141
}
4242

43-
spotless {
44-
java {
45-
importOrder(
46-
'java|javax|jakarta',
47-
'org.springframework',
48-
'lombok',
49-
'',
50-
'org.junit|org.mockito',
51-
'\\#',
52-
'\\#org.junit'
53-
)
54-
55-
googleJavaFormat()
56-
formatAnnotations()
57-
removeUnusedImports()
58-
trimTrailingWhitespace()
59-
endWithNewline()
60-
}
61-
}
43+
//spotless {
44+
// java {
45+
// importOrder(
46+
// 'java|javax|jakarta',
47+
// 'org.springframework',
48+
// 'lombok',
49+
// '',
50+
// 'org.junit|org.mockito',
51+
// '\\#',
52+
// '\\#org.junit'
53+
// )
54+
//
55+
// googleJavaFormat()
56+
// formatAnnotations()
57+
// removeUnusedImports()
58+
// trimTrailingWhitespace()
59+
// endWithNewline()
60+
// }
61+
//}
6262

6363
tasks.register("updateGitHooks", Copy) {
6464
from "./scripts/pre-commit"

src/main/java/com/gdgoc/study_group/round/controller/RoundController.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
package com.gdgoc.study_group.round.controller;
22

3+
import com.gdgoc.study_group.round.dto.CreateRoundRequest;
34
import com.gdgoc.study_group.round.dto.RoundDTO;
45
import com.gdgoc.study_group.round.dto.RoundThumbnailDTO;
6+
import com.gdgoc.study_group.round.dto.UpdateRoundRequest;
57
import com.gdgoc.study_group.round.service.RoundService;
68
import io.swagger.v3.oas.annotations.Operation;
79
import io.swagger.v3.oas.annotations.Parameter;
@@ -40,23 +42,17 @@ public ResponseEntity<RoundDTO> getRound(
4042
@Operation(summary = "회차 생성", description = "새로운 회차를 생성합니다.")
4143
public ResponseEntity<RoundDTO> createRound(
4244
@Parameter(description = "스터디 ID", required = true) @PathVariable Long studyId,
43-
@RequestParam String goal,
44-
@RequestParam String studyDetail,
45-
@RequestParam LocalDate roundDate,
46-
@RequestBody List<RoundThumbnailDTO> thumbnails) {
47-
return ResponseEntity.ok(roundService.createRound(studyId, goal, studyDetail, roundDate, thumbnails));
45+
@RequestBody CreateRoundRequest request) {
46+
return ResponseEntity.ok(roundService.createRound(studyId, request));
4847
}
4948

5049
@PatchMapping("/{roundId}")
5150
@Operation(summary = "회차 수정", description = "기존 회차의 정보를 수정합니다.")
5251
public ResponseEntity<RoundDTO> updateRound(
5352
@Parameter(description = "스터디 ID", required = true) @PathVariable Long studyId,
5453
@Parameter(description = "회차 ID", required = true) @PathVariable Long roundId,
55-
@RequestParam String goal,
56-
@RequestParam String studyDetail,
57-
@RequestParam LocalDate roundDate,
58-
@RequestBody List<RoundThumbnailDTO> thumbnails) {
59-
return ResponseEntity.ok(roundService.updateRound(roundId, goal, studyDetail, roundDate, thumbnails));
54+
@RequestBody UpdateRoundRequest request) {
55+
return ResponseEntity.ok(roundService.updateRound(roundId, request));
6056
}
6157

6258
@DeleteMapping("/{roundId}")

src/main/java/com/gdgoc/study_group/round/domain/Round.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,17 +10,17 @@
1010
import jakarta.persistence.JoinColumn;
1111
import jakarta.persistence.ManyToOne;
1212
import jakarta.persistence.OneToMany;
13-
import lombok.Builder;
14-
import lombok.Getter;
15-
import lombok.NoArgsConstructor;
13+
import lombok.*;
1614

1715
import java.time.LocalDate;
1816
import java.util.ArrayList;
1917
import java.util.List;
2018

2119
@Entity
2220
@Getter
23-
@NoArgsConstructor
21+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
22+
@AllArgsConstructor(access = AccessLevel.PRIVATE)
23+
@Builder
2424
public class Round {
2525
@Id
2626
@GeneratedValue(strategy = GenerationType.IDENTITY)

src/main/java/com/gdgoc/study_group/round/domain/RoundThumbnail.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,13 @@
99
import jakarta.persistence.ManyToOne;
1010
import jakarta.persistence.OneToOne;
1111
import jakarta.persistence.Table;
12-
import lombok.Builder;
13-
import lombok.Getter;
14-
import lombok.NoArgsConstructor;
12+
import lombok.*;
1513

1614
@Entity
1715
@Getter
18-
@NoArgsConstructor
16+
@NoArgsConstructor(access = AccessLevel.PROTECTED)
17+
@AllArgsConstructor(access = AccessLevel.PRIVATE)
18+
@Builder
1919
@Table(name = "ROUND_THUMBNAIL")
2020
public class RoundThumbnail {
2121
@Id
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.gdgoc.study_group.round.dto;
2+
3+
import java.time.LocalDate;
4+
import java.util.List;
5+
6+
public record CreateRoundRequest(
7+
String goal,
8+
String studyDetail,
9+
LocalDate roundDate,
10+
List<RoundThumbnailDTO> thumbnails
11+
) {}
Lines changed: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,29 @@
11
package com.gdgoc.study_group.round.dto;
22

33
import com.fasterxml.jackson.annotation.JsonFormat;
4+
import com.gdgoc.study_group.round.domain.Round;
5+
46
import java.time.LocalDate;
57
import java.util.List;
8+
import java.util.stream.Collectors;
69

7-
public record RoundDTO(Long id, String goal, String studyDetail,
8-
@JsonFormat(pattern = "yyyy-MM-dd") LocalDate roundDate,
9-
List<RoundThumbnailDTO> thumbnails) {
10-
public RoundDTO {
11-
// You can add validation logic here if needed
10+
public record RoundDTO(
11+
Long id,
12+
String goal,
13+
String studyDetail,
14+
@JsonFormat(pattern = "yyyy-MM-dd")
15+
LocalDate roundDate,
16+
List<RoundThumbnailDTO> thumbnails
17+
) {
18+
public static RoundDTO from(Round round) {
19+
return new RoundDTO(
20+
round.getId(),
21+
round.getGoal(),
22+
round.getStudyDetail(),
23+
round.getRoundDate(),
24+
round.getImages().stream()
25+
.map(RoundThumbnailDTO::from)
26+
.collect(Collectors.toList())
27+
);
1228
}
1329
}
Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,19 @@
11
package com.gdgoc.study_group.round.dto;
22

3-
public record RoundThumbnailDTO(Long id, String fileName, String filePath, String type) {
4-
public RoundThumbnailDTO {
5-
// You can add validation logic here if needed
3+
import com.gdgoc.study_group.round.domain.RoundThumbnail;
4+
5+
public record RoundThumbnailDTO(
6+
Long id,
7+
String fileName,
8+
String filePath,
9+
String type
10+
) {
11+
public static RoundThumbnailDTO from(RoundThumbnail thumbnail) {
12+
return new RoundThumbnailDTO(
13+
thumbnail.getId(),
14+
thumbnail.getFileName(),
15+
thumbnail.getFilePath(),
16+
thumbnail.getType()
17+
);
618
}
719
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.gdgoc.study_group.round.dto;
2+
3+
import java.time.LocalDate;
4+
import java.util.List;
5+
6+
public record UpdateRoundRequest(
7+
String goal,
8+
String studyDetail,
9+
LocalDate roundDate,
10+
List<RoundThumbnailDTO> thumbnails
11+
) {}

src/main/java/com/gdgoc/study_group/round/service/RoundService.java

Lines changed: 18 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,10 @@
22

33
import com.gdgoc.study_group.round.domain.Round;
44
import com.gdgoc.study_group.round.domain.RoundThumbnail;
5+
import com.gdgoc.study_group.round.dto.CreateRoundRequest;
56
import com.gdgoc.study_group.round.dto.RoundDTO;
67
import com.gdgoc.study_group.round.dto.RoundThumbnailDTO;
8+
import com.gdgoc.study_group.round.dto.UpdateRoundRequest;
79
import com.gdgoc.study_group.round.repository.RoundRepository;
810
import com.gdgoc.study_group.round.repository.RoundThumbnailRepository;
911
import com.gdgoc.study_group.study.dao.StudyRepository;
@@ -18,62 +20,40 @@
1820

1921
@Service
2022
@RequiredArgsConstructor
21-
@Transactional
23+
@Transactional(readOnly = true)
2224
public class RoundService {
23-
2425
private final RoundRepository roundRepository;
2526
private final RoundThumbnailRepository roundThumbnailRepository;
2627
private final StudyRepository studyRepository;
2728

2829
public List<RoundDTO> getRoundsByStudyId(Long studyId) {
2930
return roundRepository.findRoundsByStudyId(studyId)
3031
.stream()
31-
.map(round -> new RoundDTO(
32-
round.getId(),
33-
round.getGoal(),
34-
round.getStudyDetail(),
35-
round.getRoundDate(),
36-
round.getImages().stream()
37-
.map(image -> new RoundThumbnailDTO(
38-
image.getId(),
39-
image.getFileName(),
40-
image.getFilePath(),
41-
image.getType()))
42-
.collect(Collectors.toList())))
32+
.map(RoundDTO::from)
4333
.collect(Collectors.toList());
4434
}
4535

4636
public RoundDTO getRound(Long roundId) {
4737
Round round = roundRepository.findById(roundId)
4838
.orElseThrow(() -> new IllegalArgumentException("Round not found"));
49-
return new RoundDTO(
50-
round.getId(),
51-
round.getGoal(),
52-
round.getStudyDetail(),
53-
round.getRoundDate(),
54-
round.getImages().stream()
55-
.map(image -> new RoundThumbnailDTO(
56-
image.getId(),
57-
image.getFileName(),
58-
image.getFilePath(),
59-
image.getType()))
60-
.collect(Collectors.toList()));
39+
return RoundDTO.from(round);
6140
}
6241

63-
public RoundDTO createRound(Long studyId, String goal, String studyDetail, LocalDate roundDate, List<RoundThumbnailDTO> thumbnails) {
42+
@Transactional
43+
public RoundDTO createRound(Long studyId, CreateRoundRequest request) {
6444
Study study = studyRepository.findById(studyId)
6545
.orElseThrow(() -> new IllegalArgumentException("Study not found"));
6646

6747
Round round = Round.builder()
6848
.study(study)
69-
.goal(goal)
70-
.studyDetail(studyDetail)
71-
.roundDate(roundDate)
49+
.goal(request.goal())
50+
.studyDetail(request.studyDetail())
51+
.roundDate(request.roundDate())
7252
.build();
7353

7454
Round savedRound = roundRepository.save(round);
7555

76-
List<RoundThumbnail> savedThumbnails = thumbnails.stream()
56+
List<RoundThumbnail> savedThumbnails = request.thumbnails().stream()
7757
.map(thumbnailDTO -> RoundThumbnail.builder()
7858
.round(savedRound)
7959
.fileName(thumbnailDTO.fileName())
@@ -83,30 +63,18 @@ public RoundDTO createRound(Long studyId, String goal, String studyDetail, Local
8363
.collect(Collectors.toList());
8464

8565
roundThumbnailRepository.saveAll(savedThumbnails);
86-
87-
return new RoundDTO(
88-
savedRound.getId(),
89-
savedRound.getGoal(),
90-
savedRound.getStudyDetail(),
91-
savedRound.getRoundDate(),
92-
savedThumbnails.stream()
93-
.map(thumbnail -> new RoundThumbnailDTO(
94-
thumbnail.getId(),
95-
thumbnail.getFileName(),
96-
thumbnail.getFilePath(),
97-
thumbnail.getType()))
98-
.collect(Collectors.toList()));
66+
return RoundDTO.from(savedRound);
9967
}
10068

101-
public RoundDTO updateRound(Long roundId, String goal, String studyDetail, LocalDate roundDate, List<RoundThumbnailDTO> thumbnails) {
69+
@Transactional
70+
public RoundDTO updateRound(Long roundId, UpdateRoundRequest request) {
10271
Round round = roundRepository.findById(roundId)
10372
.orElseThrow(() -> new IllegalArgumentException("Round not found"));
10473

105-
round.updateDetails(goal, studyDetail, roundDate);
74+
round.updateDetails(request.goal(), request.studyDetail(), request.roundDate());
10675
Round updatedRound = roundRepository.save(round);
10776

108-
// Update thumbnails
109-
List<RoundThumbnail> savedThumbnails = thumbnails.stream()
77+
List<RoundThumbnail> savedThumbnails = request.thumbnails().stream()
11078
.map(thumbnailDTO -> RoundThumbnail.builder()
11179
.round(updatedRound)
11280
.fileName(thumbnailDTO.fileName())
@@ -116,21 +84,10 @@ public RoundDTO updateRound(Long roundId, String goal, String studyDetail, Local
11684
.collect(Collectors.toList());
11785

11886
roundThumbnailRepository.saveAll(savedThumbnails);
119-
120-
return new RoundDTO(
121-
updatedRound.getId(),
122-
updatedRound.getGoal(),
123-
updatedRound.getStudyDetail(),
124-
updatedRound.getRoundDate(),
125-
savedThumbnails.stream()
126-
.map(thumbnail -> new RoundThumbnailDTO(
127-
thumbnail.getId(),
128-
thumbnail.getFileName(),
129-
thumbnail.getFilePath(),
130-
thumbnail.getType()))
131-
.collect(Collectors.toList()));
87+
return RoundDTO.from(updatedRound);
13288
}
13389

90+
@Transactional
13491
public void deleteRound(Long roundId) {
13592
Round round = roundRepository.findById(roundId)
13693
.orElseThrow(() -> new IllegalArgumentException("Round not found"));

0 commit comments

Comments
 (0)