-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
신고 조치 기능 구현 #770
신고 조치 기능 구현 #770
Changes from 3 commits
4692375
7dbc6a5
60854ef
7c6f88a
fa2a799
dd24e70
0539037
d02f877
3cddf6a
ac9eb4c
8b50710
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.votogether.domain.report.dto.request; | ||
|
||
import io.swagger.v3.oas.annotations.media.Schema; | ||
import jakarta.validation.constraints.NotNull; | ||
import jakarta.validation.constraints.Positive; | ||
|
||
@Schema(description = "신고 조치 요청") | ||
public record ReportActionRequest( | ||
@Schema(description = "신고 ID", example = "1") | ||
@NotNull(message = "신고 ID는 빈 값일 수 없습니다.") | ||
@Positive(message = "신고 ID는 양의 정수만 가능합니다.") | ||
Long id, | ||
|
||
@Schema(description = "신고 조치 여부", example = "true") | ||
boolean hasAction | ||
) { | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
package com.votogether.domain.report.repository; | ||
|
||
import com.votogether.domain.report.dto.ReportAggregateDto; | ||
import com.votogether.domain.report.entity.vo.ReportType; | ||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.domain.Pageable; | ||
|
||
public interface ReportCustomRepository { | ||
|
||
List<ReportAggregateDto> findReportsGroupedByReportTypeAndTargetId(final Pageable pageable); | ||
List<ReportAggregateDto> findReportAggregateDtosByReportTypeAndTargetId(final Pageable pageable); | ||
|
||
Optional<ReportAggregateDto> findReportAggregateDtoByReportTypeAndTargetId(ReportType reportType, Long targetId); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
|
||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,15 @@ | ||
package com.votogether.domain.report.service; | ||
|
||
import com.votogether.domain.member.entity.Member; | ||
import com.votogether.domain.report.dto.ReportAggregateDto; | ||
import com.votogether.domain.report.dto.request.ReportActionRequest; | ||
import com.votogether.domain.report.dto.request.ReportRequest; | ||
import com.votogether.domain.report.entity.Report; | ||
import com.votogether.domain.report.exception.ReportExceptionType; | ||
import com.votogether.domain.report.repository.ReportRepository; | ||
import com.votogether.domain.report.service.strategy.ReportActionProvider; | ||
import com.votogether.domain.report.service.strategy.ReportStrategy; | ||
import com.votogether.global.exception.NotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
@@ -14,10 +20,29 @@ | |
public class ReportCommandService { | ||
|
||
private final ReportActionProvider reportActionProvider; | ||
private final ReportRepository reportRepository; | ||
|
||
public void report(final Member reporter, final ReportRequest request) { | ||
final ReportStrategy reportStrategy = reportActionProvider.getStrategy(request.type()); | ||
reportStrategy.report(reporter, request); | ||
} | ||
|
||
public void reportAction(final ReportActionRequest request) { | ||
final Report report = reportRepository.findById(request.id()) | ||
.orElseThrow(() -> new NotFoundException(ReportExceptionType.NOT_FOUND)); | ||
|
||
final ReportAggregateDto reportAggregateDto = reportRepository | ||
.findReportAggregateDtoByReportTypeAndTargetId(report.getReportType(), report.getTargetId()) | ||
.orElseThrow(() -> new NotFoundException(ReportExceptionType.NOT_FOUND)); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 먼저 저 두 단계를 거칠 필요가 있었습니다. 결국 reportType과 targetId로 group by 해서 가져와야 해서요. 그래서 이처럼 2번 가져오게 되었는데, 결국 id로든 reportType과 targetId 로든 결국 찾아오려고 하는데 못찾아오는 거면 NotFoundException이 맞다고 판단했습니다. 또한 둘 다 Report에 관련한 것들이니 ReportExceptionType을 사용하였습니다. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 예외 메시지가 같은데, 예외가 발생한 경우 응답과 로그를 통해서 찾기 어렵지 않을까요? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 그러게요. ReportAggregateDto에 관한 message를 따로 만들어볼게요. |
||
|
||
reportRepository.deleteAllWithReportTypeAndTargetIdInBatch(report.getReportType(), report.getTargetId()); | ||
|
||
if (!request.hasAction()) { | ||
return; | ||
} | ||
|
||
final ReportStrategy strategy = reportActionProvider.getStrategy(reportAggregateDto.reportType()); | ||
strategy.reportAction(reportAggregateDto); | ||
} | ||
|
||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
신고 ID가 존재하지 않은 경우에도
400
예외가 발생할 수 있을 것 같아요 !