Skip to content

Commit a29548a

Browse files
committed
refactor: 코드 스타일 리팩토링
1 parent 4a1193d commit a29548a

File tree

16 files changed

+335
-286
lines changed

16 files changed

+335
-286
lines changed
Lines changed: 26 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,39 @@
11
package com.example.log4u.domain.reports.controller;
22

3+
import org.springframework.http.HttpStatus;
4+
import org.springframework.http.ResponseEntity;
5+
import org.springframework.web.bind.annotation.PathVariable;
6+
import org.springframework.web.bind.annotation.PostMapping;
7+
import org.springframework.web.bind.annotation.RequestBody;
8+
import org.springframework.web.bind.annotation.RequestMapping;
9+
import org.springframework.web.bind.annotation.RestController;
10+
311
import com.example.log4u.domain.reports.dto.ReportCreateRequestDto;
4-
import com.example.log4u.domain.reports.entity.Report;
512
import com.example.log4u.domain.reports.service.ReportService;
13+
614
import lombok.RequiredArgsConstructor;
7-
import org.springframework.http.HttpStatus;
8-
import org.springframework.http.ResponseEntity;
9-
import org.springframework.web.bind.annotation.*;
1015

1116
@RestController
1217
@RequiredArgsConstructor
1318
@RequestMapping("/reports")
1419
public class ReportsController {
15-
private final ReportService reportService;
20+
private final ReportService reportService;
1621

17-
@PostMapping("/diaries/{diaryId}")
18-
public ResponseEntity<Void> createReportForDiary(
19-
@RequestBody ReportCreateRequestDto reportCreateRequestDto,
20-
@PathVariable Long diaryId) {
21-
long reporterId = 1L; // SecurityContextHolder 에서 온다고 가정
22-
reportService.createDiaryReport(reporterId, reportCreateRequestDto, diaryId);
23-
return new ResponseEntity<>(HttpStatus.CREATED);
24-
}
22+
@PostMapping("/diaries/{diaryId}")
23+
public ResponseEntity<Void> createReportForDiary(
24+
@RequestBody ReportCreateRequestDto reportCreateRequestDto,
25+
@PathVariable Long diaryId) {
26+
long reporterId = 1L; // SecurityContextHolder 에서 온다고 가정
27+
reportService.createDiaryReport(reporterId, reportCreateRequestDto, diaryId);
28+
return new ResponseEntity<>(HttpStatus.CREATED);
29+
}
2530

26-
@PostMapping("/comments/{commentId}")
27-
public ResponseEntity<Void> createReport(
28-
@RequestBody ReportCreateRequestDto reportCreateRequestDto,
29-
@PathVariable Long commentId) {
30-
long reporterId = 1L;
31-
reportService.createCommentReport(reporterId, reportCreateRequestDto, commentId);
32-
return new ResponseEntity<>(HttpStatus.CREATED);
33-
}
31+
@PostMapping("/comments/{commentId}")
32+
public ResponseEntity<Void> createReport(
33+
@RequestBody ReportCreateRequestDto reportCreateRequestDto,
34+
@PathVariable Long commentId) {
35+
long reporterId = 1L;
36+
reportService.createCommentReport(reporterId, reportCreateRequestDto, commentId);
37+
return new ResponseEntity<>(HttpStatus.CREATED);
38+
}
3439
}
Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,28 @@
11
package com.example.log4u.domain.reports.dto;
22

3+
import org.hibernate.validator.constraints.Length;
4+
35
import com.example.log4u.domain.reports.entity.Report;
46
import com.example.log4u.domain.reports.reportType.ReportType;
7+
58
import jakarta.validation.constraints.NotBlank;
69
import jakarta.validation.constraints.NotNull;
7-
import org.hibernate.validator.constraints.Length;
810

911
public record ReportCreateRequestDto(
10-
@NotNull
11-
ReportType reportType,
12+
@NotNull
13+
ReportType reportType,
1214

13-
@NotBlank
14-
@Length(min = 2)
15-
String content
15+
@NotBlank
16+
@Length(min = 2)
17+
String content
1618
) {
17-
public Report toEntity(long reporterId, Report.ReportTargetType reportTargetType, Long targetId){
18-
return Report.builder()
19-
.reporterId(reporterId)
20-
.reportTargetType(reportTargetType)
21-
.reportType(reportType)
22-
.reportTargetId(targetId)
23-
.content(content)
24-
.build();
25-
}
19+
public Report toEntity(long reporterId, Report.ReportTargetType reportTargetType, Long targetId) {
20+
return Report.builder()
21+
.reporterId(reporterId)
22+
.reportTargetType(reportTargetType)
23+
.reportType(reportType)
24+
.reportTargetId(targetId)
25+
.content(content)
26+
.build();
27+
}
2628
}
Lines changed: 33 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,24 @@
11
package com.example.log4u.domain.reports.entity;
22

3-
import com.example.log4u.domain.reports.reportType.ReportType;
4-
import jakarta.persistence.*;
5-
import lombok.*;
3+
import java.time.LocalDateTime;
4+
65
import org.springframework.data.annotation.CreatedDate;
76
import org.springframework.data.jpa.domain.support.AuditingEntityListener;
8-
import java.time.LocalDateTime;
7+
8+
import com.example.log4u.domain.reports.reportType.ReportType;
9+
10+
import jakarta.persistence.Entity;
11+
import jakarta.persistence.EntityListeners;
12+
import jakarta.persistence.EnumType;
13+
import jakarta.persistence.Enumerated;
14+
import jakarta.persistence.GeneratedValue;
15+
import jakarta.persistence.GenerationType;
16+
import jakarta.persistence.Id;
17+
import lombok.AccessLevel;
18+
import lombok.AllArgsConstructor;
19+
import lombok.Builder;
20+
import lombok.Getter;
21+
import lombok.NoArgsConstructor;
922

1023
@Builder
1124
@Getter
@@ -15,27 +28,27 @@
1528
@Entity
1629
@EntityListeners(AuditingEntityListener.class)
1730
public class Report {
18-
public enum ReportTargetType{
19-
DIARY,
20-
COMMENT
21-
}
31+
public enum ReportTargetType {
32+
DIARY,
33+
COMMENT
34+
}
2235

23-
@Id
24-
@GeneratedValue(strategy = GenerationType.IDENTITY)
25-
private Long id;
36+
@Id
37+
@GeneratedValue(strategy = GenerationType.IDENTITY)
38+
private Long id;
2639

27-
private long reporterId;
40+
private long reporterId;
2841

29-
@Enumerated(EnumType.STRING)
30-
private ReportTargetType reportTargetType;
42+
@Enumerated(EnumType.STRING)
43+
private ReportTargetType reportTargetType;
3144

32-
@Enumerated(EnumType.STRING)
33-
private ReportType reportType;
45+
@Enumerated(EnumType.STRING)
46+
private ReportType reportType;
3447

35-
private Long reportTargetId;
48+
private Long reportTargetId;
3649

37-
private String content;
50+
private String content;
3851

39-
@CreatedDate
40-
private LocalDateTime createdAt;
52+
@CreatedDate
53+
private LocalDateTime createdAt;
4154
}
Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
package com.example.log4u.domain.reports.reportType;
22

33
public enum ReportType {
4-
INAPPROPRIATE_CONTENT,
5-
FALSE_INFORMATION,
6-
SPAM,
7-
COPYRIGHT_INFRINGEMENT,
8-
PRIVACY_VIOLATION,
9-
ETC
4+
INAPPROPRIATE_CONTENT,
5+
FALSE_INFORMATION,
6+
SPAM,
7+
COPYRIGHT_INFRINGEMENT,
8+
PRIVACY_VIOLATION,
9+
ETC
1010
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
package com.example.log4u.domain.reports.repository;
22

3-
import com.example.log4u.domain.reports.entity.Report;
43
import org.springframework.data.jpa.repository.JpaRepository;
54

5+
import com.example.log4u.domain.reports.entity.Report;
6+
67
public interface ReportRepository extends JpaRepository<Report, Long> {
78
}
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,33 @@
11
package com.example.log4u.domain.reports.service;
22

3+
import org.springframework.stereotype.Service;
4+
import org.springframework.transaction.annotation.Transactional;
5+
36
import com.example.log4u.domain.reports.dto.ReportCreateRequestDto;
47
import com.example.log4u.domain.reports.entity.Report;
58
import com.example.log4u.domain.reports.repository.ReportRepository;
9+
610
import lombok.RequiredArgsConstructor;
7-
import org.springframework.stereotype.Service;
8-
import org.springframework.transaction.annotation.Transactional;
911

1012
@Service
1113
@Transactional
1214
@RequiredArgsConstructor
1315
public class ReportService {
14-
private final ReportRepository reportRepository;
16+
private final ReportRepository reportRepository;
1517

16-
public void createDiaryReport(
17-
long reporterId,
18-
ReportCreateRequestDto reportCreateRequestDto,
19-
Long diaryId) {
20-
Report report = reportCreateRequestDto.toEntity(reporterId, Report.ReportTargetType.DIARY, diaryId);
21-
reportRepository.save(report);
22-
}
18+
public void createDiaryReport(
19+
long reporterId,
20+
ReportCreateRequestDto reportCreateRequestDto,
21+
Long diaryId) {
22+
Report report = reportCreateRequestDto.toEntity(reporterId, Report.ReportTargetType.DIARY, diaryId);
23+
reportRepository.save(report);
24+
}
2325

24-
public void createCommentReport(
25-
long reporterId,
26-
ReportCreateRequestDto reportCreateRequestDto,
27-
Long commentId) {
28-
Report report = reportCreateRequestDto.toEntity(reporterId, Report.ReportTargetType.COMMENT, commentId);
29-
reportRepository.save(report);
30-
}
26+
public void createCommentReport(
27+
long reporterId,
28+
ReportCreateRequestDto reportCreateRequestDto,
29+
Long commentId) {
30+
Report report = reportCreateRequestDto.toEntity(reporterId, Report.ReportTargetType.COMMENT, commentId);
31+
reportRepository.save(report);
32+
}
3133
}
Lines changed: 38 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -1,48 +1,56 @@
11
package com.example.log4u.domain.supports.controller;
22

3+
import org.springframework.data.domain.Page;
4+
import org.springframework.http.HttpStatus;
5+
import org.springframework.http.ResponseEntity;
6+
import org.springframework.web.bind.annotation.GetMapping;
7+
import org.springframework.web.bind.annotation.PathVariable;
8+
import org.springframework.web.bind.annotation.PostMapping;
9+
import org.springframework.web.bind.annotation.RequestBody;
10+
import org.springframework.web.bind.annotation.RequestMapping;
11+
import org.springframework.web.bind.annotation.RequestParam;
12+
import org.springframework.web.bind.annotation.RestController;
13+
314
import com.example.log4u.domain.supports.dto.SupportCreateRequestDto;
415
import com.example.log4u.domain.supports.dto.SupportGetResponseDto;
516
import com.example.log4u.domain.supports.dto.SupportOverviewGetResponseDto;
617
import com.example.log4u.domain.supports.service.SupportService;
718
import com.example.log4u.domain.supports.supportType.SupportType;
19+
820
import jakarta.validation.Valid;
921
import lombok.RequiredArgsConstructor;
10-
import org.springframework.data.domain.Page;
11-
import org.springframework.http.HttpStatus;
12-
import org.springframework.http.ResponseEntity;
13-
import org.springframework.web.bind.annotation.*;
14-
1522

1623
@RestController
1724
@RequiredArgsConstructor
1825
@RequestMapping("/supports")
1926
public class SupportController {
20-
private final SupportService supportService;
27+
private final SupportService supportService;
2128

22-
@PostMapping
23-
public ResponseEntity<Void> createSupport(
24-
@RequestBody @Valid SupportCreateRequestDto supportCreateRequestDto
25-
){
26-
long requesterId = 1L;
27-
supportService.createSupport(requesterId, supportCreateRequestDto);
28-
return new ResponseEntity<>(HttpStatus.CREATED);
29-
}
29+
@PostMapping
30+
public ResponseEntity<Void> createSupport(
31+
@RequestBody @Valid SupportCreateRequestDto supportCreateRequestDto
32+
) {
33+
long requesterId = 1L;
34+
supportService.createSupport(requesterId, supportCreateRequestDto);
35+
return new ResponseEntity<>(HttpStatus.CREATED);
36+
}
3037

31-
@GetMapping
32-
public ResponseEntity<Page<SupportOverviewGetResponseDto>> getSupportOverviewPage(
33-
@RequestParam(required = false) Integer page,
34-
@RequestParam(required = false) SupportType supportType
35-
){
36-
long requesterId = 1L;
37-
Page<SupportOverviewGetResponseDto> supportOverviewPage = supportService.getSupportPage(requesterId, page, supportType);
38-
return ResponseEntity.ok().body(supportOverviewPage);
39-
}
38+
@GetMapping
39+
public ResponseEntity<Page<SupportOverviewGetResponseDto>> getSupportOverviewPage(
40+
@RequestParam(required = false) Integer page,
41+
@RequestParam(required = false) SupportType supportType
42+
) {
43+
long requesterId = 1L;
44+
Page<SupportOverviewGetResponseDto> supportOverviewPage = supportService.getSupportPage(requesterId, page,
45+
supportType);
46+
return ResponseEntity.ok().body(supportOverviewPage);
47+
}
4048

41-
@GetMapping("/{supportId}")
42-
public ResponseEntity<SupportGetResponseDto> getSupportBySupportId(
43-
@PathVariable Long supportId){
44-
long requesterId = 1L;
45-
SupportGetResponseDto supportGetResponseDto = supportService.getSupportById(requesterId, supportId);
46-
return ResponseEntity.ok().body(supportGetResponseDto);
47-
}
49+
@GetMapping("/{supportId}")
50+
public ResponseEntity<SupportGetResponseDto> getSupportBySupportId(
51+
@PathVariable Long supportId) {
52+
long requesterId = 1L;
53+
SupportGetResponseDto supportGetResponseDto = supportService.getSupportById(requesterId, supportId);
54+
return ResponseEntity.ok().body(supportGetResponseDto);
55+
}
4856
}
Lines changed: 19 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
package com.example.log4u.domain.supports.dto;
22

3+
import org.hibernate.validator.constraints.Length;
4+
35
import com.example.log4u.domain.supports.entity.Support;
46
import com.example.log4u.domain.supports.supportType.SupportType;
7+
58
import jakarta.validation.constraints.NotBlank;
69
import jakarta.validation.constraints.NotNull;
7-
import org.hibernate.validator.constraints.Length;
810

911
public record SupportCreateRequestDto(
10-
@NotNull
11-
SupportType supportType,
12+
@NotNull
13+
SupportType supportType,
1214

13-
@NotBlank
14-
@Length(min = 2)
15-
String title,
15+
@NotBlank
16+
@Length(min = 2)
17+
String title,
1618

17-
@NotBlank
18-
@Length(min = 2)
19-
String content
19+
@NotBlank
20+
@Length(min = 2)
21+
String content
2022
) {
21-
public Support toEntity(long requesterId){
22-
return Support.builder()
23-
.requesterId(requesterId)
24-
.supportType(supportType)
25-
.title(title)
26-
.content(content)
27-
.build();
28-
}
23+
public Support toEntity(long requesterId) {
24+
return Support.builder()
25+
.requesterId(requesterId)
26+
.supportType(supportType)
27+
.title(title)
28+
.content(content)
29+
.build();
30+
}
2931
}

0 commit comments

Comments
 (0)