Skip to content

Commit 4a1193d

Browse files
committed
refactor: userId 가 있다는 가정 하에 코드 변경
1 parent 1e5a8b7 commit 4a1193d

File tree

12 files changed

+46
-18
lines changed

12 files changed

+46
-18
lines changed

src/main/java/com/example/log4u/domain/reports/controller/ReportsController.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,17 @@ public class ReportsController {
1818
public ResponseEntity<Void> createReportForDiary(
1919
@RequestBody ReportCreateRequestDto reportCreateRequestDto,
2020
@PathVariable Long diaryId) {
21-
reportService.createDiaryReport(reportCreateRequestDto, diaryId);
21+
long reporterId = 1L; // SecurityContextHolder 에서 온다고 가정
22+
reportService.createDiaryReport(reporterId, reportCreateRequestDto, diaryId);
2223
return new ResponseEntity<>(HttpStatus.CREATED);
2324
}
2425

2526
@PostMapping("/comments/{commentId}")
2627
public ResponseEntity<Void> createReport(
2728
@RequestBody ReportCreateRequestDto reportCreateRequestDto,
2829
@PathVariable Long commentId) {
29-
reportService.createCommentReport(reportCreateRequestDto, commentId);
30+
long reporterId = 1L;
31+
reportService.createCommentReport(reporterId, reportCreateRequestDto, commentId);
3032
return new ResponseEntity<>(HttpStatus.CREATED);
3133
}
3234
}

src/main/java/com/example/log4u/domain/reports/dto/ReportCreateRequestDto.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,8 +14,9 @@ public record ReportCreateRequestDto(
1414
@Length(min = 2)
1515
String content
1616
) {
17-
public Report toEntity(Report.ReportTargetType reportTargetType, Long targetId){
17+
public Report toEntity(long reporterId, Report.ReportTargetType reportTargetType, Long targetId){
1818
return Report.builder()
19+
.reporterId(reporterId)
1920
.reportTargetType(reportTargetType)
2021
.reportType(reportType)
2122
.reportTargetId(targetId)

src/main/java/com/example/log4u/domain/reports/entity/Report.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ public enum ReportTargetType{
2424
@GeneratedValue(strategy = GenerationType.IDENTITY)
2525
private Long id;
2626

27+
private long reporterId;
28+
2729
@Enumerated(EnumType.STRING)
2830
private ReportTargetType reportTargetType;
2931

src/main/java/com/example/log4u/domain/reports/service/ReportService.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,18 @@ public class ReportService {
1414
private final ReportRepository reportRepository;
1515

1616
public void createDiaryReport(
17+
long reporterId,
1718
ReportCreateRequestDto reportCreateRequestDto,
1819
Long diaryId) {
19-
Report report = reportCreateRequestDto.toEntity(Report.ReportTargetType.DIARY, diaryId);
20+
Report report = reportCreateRequestDto.toEntity(reporterId, Report.ReportTargetType.DIARY, diaryId);
2021
reportRepository.save(report);
2122
}
2223

2324
public void createCommentReport(
25+
long reporterId,
2426
ReportCreateRequestDto reportCreateRequestDto,
2527
Long commentId) {
26-
Report report = reportCreateRequestDto.toEntity(Report.ReportTargetType.DIARY, commentId);
28+
Report report = reportCreateRequestDto.toEntity(reporterId, Report.ReportTargetType.COMMENT, commentId);
2729
reportRepository.save(report);
2830
}
2931
}

src/main/java/com/example/log4u/domain/supports/controller/SupportController.java

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,8 @@ public class SupportController {
2323
public ResponseEntity<Void> createSupport(
2424
@RequestBody @Valid SupportCreateRequestDto supportCreateRequestDto
2525
){
26-
supportService.createSupport(supportCreateRequestDto);
26+
long requesterId = 1L;
27+
supportService.createSupport(requesterId, supportCreateRequestDto);
2728
return new ResponseEntity<>(HttpStatus.CREATED);
2829
}
2930

@@ -32,14 +33,16 @@ public ResponseEntity<Page<SupportOverviewGetResponseDto>> getSupportOverviewPag
3233
@RequestParam(required = false) Integer page,
3334
@RequestParam(required = false) SupportType supportType
3435
){
35-
Page<SupportOverviewGetResponseDto> supportOverviewPage = supportService.getSupportPage(page, supportType);
36+
long requesterId = 1L;
37+
Page<SupportOverviewGetResponseDto> supportOverviewPage = supportService.getSupportPage(requesterId, page, supportType);
3638
return ResponseEntity.ok().body(supportOverviewPage);
3739
}
3840

3941
@GetMapping("/{supportId}")
4042
public ResponseEntity<SupportGetResponseDto> getSupportBySupportId(
4143
@PathVariable Long supportId){
42-
SupportGetResponseDto supportGetResponseDto = supportService.getSupportById(supportId);
44+
long requesterId = 1L;
45+
SupportGetResponseDto supportGetResponseDto = supportService.getSupportById(requesterId, supportId);
4346
return ResponseEntity.ok().body(supportGetResponseDto);
4447
}
4548
}

src/main/java/com/example/log4u/domain/supports/dto/SupportCreateRequestDto.java

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,8 +18,9 @@ public record SupportCreateRequestDto(
1818
@Length(min = 2)
1919
String content
2020
) {
21-
public Support toEntity(){
21+
public Support toEntity(long requesterId){
2222
return Support.builder()
23+
.requesterId(requesterId)
2324
.supportType(supportType)
2425
.title(title)
2526
.content(content)

src/main/java/com/example/log4u/domain/supports/dto/SupportGetResponseDto.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
@Builder
1010
public record SupportGetResponseDto (
1111
long id,
12+
long requesterId,
1213
SupportType supportType,
1314
String title,
1415
String content,

src/main/java/com/example/log4u/domain/supports/dto/SupportOverviewGetResponseDto.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88
@Builder
99
public record SupportOverviewGetResponseDto(
1010
long id,
11+
long requesterId,
1112
SupportType supportType,
1213
String title,
1314
LocalDateTime createdAt,

src/main/java/com/example/log4u/domain/supports/entity/Support.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,8 @@ public class Support {
2020
@GeneratedValue(strategy = GenerationType.IDENTITY)
2121
private Long id;
2222

23+
private long requesterId;
24+
2325
private SupportType supportType;
2426

2527
private String title;

src/main/java/com/example/log4u/domain/supports/repository/SupportQuerydsl.java

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,9 +24,12 @@ public SupportQuerydsl() {
2424
}
2525

2626
public Page<SupportOverviewGetResponseDto> getSupportOverviewGetResponseDtoPage(
27+
long requesterId,
2728
Pageable pageable,
2829
SupportType supportType) {
30+
2931
BooleanBuilder builder = new BooleanBuilder();
32+
builder.and(support.requesterId.eq(requesterId));
3033

3134
if (supportType != null){
3235
builder.and(support.supportType.eq(supportType));
@@ -35,6 +38,7 @@ public Page<SupportOverviewGetResponseDto> getSupportOverviewGetResponseDtoPage(
3538
List<SupportOverviewGetResponseDto> content = from(support)
3639
.select(Projections.constructor(SupportOverviewGetResponseDto.class,
3740
support.id,
41+
support.requesterId,
3842
support.supportType,
3943
support.title,
4044
support.createdAt,
@@ -50,17 +54,21 @@ public Page<SupportOverviewGetResponseDto> getSupportOverviewGetResponseDtoPage(
5054
.fetchCount());
5155
}
5256

53-
public SupportGetResponseDto getSupportGetResponseDtoById(Long supportId) {
57+
public SupportGetResponseDto getSupportGetResponseDtoById(
58+
long requesterId,
59+
Long supportId) {
5460
return from(support)
5561
.select(Projections.constructor(SupportGetResponseDto.class,
5662
support.id,
63+
support.requesterId,
5764
support.supportType,
5865
support.title,
5966
support.content,
6067
support.createdAt,
6168
support.answerContent,
6269
support.answeredAt))
63-
.where(support.id.eq(supportId))
70+
.where(support.id.eq(supportId)
71+
.and(support.requesterId.eq(requesterId)))
6472
.fetchOne();
6573
}
6674
}

0 commit comments

Comments
 (0)