-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* feature: 피드 신고 기록 기능 구현 * fix: 필요없는 메서드 삭제 * fix: Report 엔티티에 BaseTimeEntity추가 * fix: /reports/ 엔드포인트 제거 * fix: ErrorCode message수정 * fix: 정적 팩토리 메서드 사용 * fix: DTO에 Swagger Schema 어노테이션추가 * fix: reportReason을 request에서 String으로 요청 * fix: response example 수정
- Loading branch information
Showing
7 changed files
with
160 additions
and
1 deletion.
There are no files selected for viewing
28 changes: 28 additions & 0 deletions
28
src/main/java/com/depromeet/stonebed/domain/report/api/ReportController.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,28 @@ | ||
package com.depromeet.stonebed.domain.report.api; | ||
|
||
import com.depromeet.stonebed.domain.report.application.ReportService; | ||
import com.depromeet.stonebed.domain.report.dto.request.ReportRequest; | ||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
@Tag(name = "8. [신고]", description = "신고 기능 관련 API입니다.") | ||
@RestController | ||
@RequestMapping("/reports") | ||
@RequiredArgsConstructor | ||
public class ReportController { | ||
private final ReportService reportService; | ||
|
||
@Operation(summary = "신고하기", description = "특정 피드를 신고한다.") | ||
@PostMapping | ||
public ResponseEntity<Void> reportFeed(@RequestBody ReportRequest reportRequest) { | ||
reportService.reportFeed(reportRequest); | ||
return ResponseEntity.status(HttpStatus.CREATED).build(); | ||
} | ||
} |
38 changes: 38 additions & 0 deletions
38
src/main/java/com/depromeet/stonebed/domain/report/application/ReportService.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,38 @@ | ||
package com.depromeet.stonebed.domain.report.application; | ||
|
||
import com.depromeet.stonebed.domain.member.domain.Member; | ||
import com.depromeet.stonebed.domain.missionRecord.dao.MissionRecordRepository; | ||
import com.depromeet.stonebed.domain.missionRecord.domain.MissionRecord; | ||
import com.depromeet.stonebed.domain.report.dao.ReportRepository; | ||
import com.depromeet.stonebed.domain.report.domain.Report; | ||
import com.depromeet.stonebed.domain.report.dto.request.ReportRequest; | ||
import com.depromeet.stonebed.global.error.ErrorCode; | ||
import com.depromeet.stonebed.global.error.exception.CustomException; | ||
import com.depromeet.stonebed.global.util.MemberUtil; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class ReportService { | ||
private final ReportRepository reportRepository; | ||
private final MissionRecordRepository missionRecordRepository; | ||
private final MemberUtil memberUtil; | ||
|
||
public void reportFeed(ReportRequest reportRequest) { | ||
final Member member = memberUtil.getCurrentMember(); | ||
|
||
MissionRecord missionRecord = | ||
missionRecordRepository | ||
.findById(reportRequest.recordId()) | ||
.orElseThrow(() -> new CustomException(ErrorCode.MISSION_RECORD_NOT_FOUND)); | ||
|
||
Report report = | ||
Report.createReport( | ||
missionRecord, member, reportRequest.reason(), reportRequest.details()); | ||
|
||
reportRepository.save(report); | ||
} | ||
} |
6 changes: 6 additions & 0 deletions
6
src/main/java/com/depromeet/stonebed/domain/report/dao/ReportRepository.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,6 @@ | ||
package com.depromeet.stonebed.domain.report.dao; | ||
|
||
import com.depromeet.stonebed.domain.report.domain.Report; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface ReportRepository extends JpaRepository<Report, Long> {} |
58 changes: 58 additions & 0 deletions
58
src/main/java/com/depromeet/stonebed/domain/report/domain/Report.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,58 @@ | ||
package com.depromeet.stonebed.domain.report.domain; | ||
|
||
import com.depromeet.stonebed.domain.common.BaseTimeEntity; | ||
import com.depromeet.stonebed.domain.member.domain.Member; | ||
import com.depromeet.stonebed.domain.missionRecord.domain.MissionRecord; | ||
import jakarta.persistence.Entity; | ||
import jakarta.persistence.FetchType; | ||
import jakarta.persistence.GeneratedValue; | ||
import jakarta.persistence.GenerationType; | ||
import jakarta.persistence.Id; | ||
import jakarta.persistence.JoinColumn; | ||
import jakarta.persistence.ManyToOne; | ||
import jakarta.persistence.Table; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
@Table(name = "feed_report") | ||
public class Report extends BaseTimeEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
private Long id; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "mission_record_id", nullable = false) | ||
private MissionRecord missionRecord; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id", nullable = false) | ||
private Member member; | ||
|
||
private String reason; | ||
|
||
private String details; | ||
|
||
@Builder(access = AccessLevel.PRIVATE) | ||
private Report(MissionRecord missionRecord, Member member, String reason, String details) { | ||
this.missionRecord = missionRecord; | ||
this.member = member; | ||
this.reason = reason; | ||
this.details = details; | ||
} | ||
|
||
public static Report createReport( | ||
MissionRecord missionRecord, Member member, String reportReason, String details) { | ||
return Report.builder() | ||
.missionRecord(missionRecord) | ||
.member(member) | ||
.reason(reportReason) | ||
.details(details) | ||
.build(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/depromeet/stonebed/domain/report/dto/request/ReportRequest.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,18 @@ | ||
package com.depromeet.stonebed.domain.report.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Size; | ||
|
||
@Schema(description = "신고 요청 정보") | ||
public record ReportRequest( | ||
@Schema(description = "신고할 대상 기록의 ID", example = "123", required = true) @NotNull | ||
Long recordId, | ||
@Schema(description = "신고 사유", example = "사기 또는 사칭", required = true) @NotNull | ||
String reason, | ||
@Schema( | ||
description = "신고 상세 내용 (최대 500자)", | ||
example = "해당 게시물은 부적절한 내용을 포함하고 있습니다.", | ||
maxLength = 500) | ||
@Size(max = 500) | ||
String details) {} |
8 changes: 8 additions & 0 deletions
8
src/main/java/com/depromeet/stonebed/domain/report/dto/response/ReportReasonResponse.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,8 @@ | ||
package com.depromeet.stonebed.domain.report.dto.response; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
|
||
@Schema(description = "신고 사유 응답 정보") | ||
public record ReportReasonResponse( | ||
@Schema(description = "신고 사유", example = "HARASSMENT") String enumValue, | ||
@Schema(description = "신고 사유 설명", example = "사기 또는 사칭") String description) {} |
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