Skip to content

Commit

Permalink
피드 신고 기능 구현 (#285)
Browse files Browse the repository at this point in the history
* 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
dbscks97 authored Oct 1, 2024
1 parent 30e7e74 commit 37d2457
Show file tree
Hide file tree
Showing 7 changed files with 160 additions and 1 deletion.
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();
}
}
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);
}
}
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> {}
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();
}
}
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) {}
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) {}
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,10 @@ public enum ErrorCode {
// fcm
INVALID_FCM_TOKEN(HttpStatus.BAD_REQUEST, "FCM 토큰값이 비어있습니다."),
FAILED_TO_FIND_FCM_TOKEN(HttpStatus.NOT_FOUND, "해당 FCM 토큰을 찾을 수 없습니다."),
NOTIFICATION_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 알림을 찾을 수 없습니다.");
NOTIFICATION_NOT_FOUND(HttpStatus.NOT_FOUND, "해당 알림을 찾을 수 없습니다."),

// report
INVALID_REPORT_REASON(HttpStatus.NOT_FOUND, "해당 신고 사유를 찾을 수 없습니다.");
private final HttpStatus httpStatus;
private final String message;
}

0 comments on commit 37d2457

Please sign in to comment.