From b497d385f2b65862b939c67a9fdb1ff01e873bb4 Mon Sep 17 00:00:00 2001 From: KyungsooLee Date: Mon, 9 Sep 2024 01:19:16 +0900 Subject: [PATCH 1/7] =?UTF-8?q?feat:=20#142=20BoardReport=20=EC=97=94?= =?UTF-8?q?=ED=8B=B0=ED=8B=B0=20&=20BoardReportType=20Enum=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../boardReport/entity/BoardReport.java | 33 +++++++++++++++++++ .../boardReport/entity/BoardReportType.java | 17 ++++++++++ 2 files changed, 50 insertions(+) create mode 100644 src/main/java/com/server/capple/domain/boardReport/entity/BoardReport.java create mode 100644 src/main/java/com/server/capple/domain/boardReport/entity/BoardReportType.java diff --git a/src/main/java/com/server/capple/domain/boardReport/entity/BoardReport.java b/src/main/java/com/server/capple/domain/boardReport/entity/BoardReport.java new file mode 100644 index 00000000..b7414428 --- /dev/null +++ b/src/main/java/com/server/capple/domain/boardReport/entity/BoardReport.java @@ -0,0 +1,33 @@ +package com.server.capple.domain.boardReport.entity; + +import com.server.capple.domain.board.entity.Board; +import com.server.capple.domain.member.entity.Member; +import com.server.capple.global.common.BaseEntity; +import jakarta.persistence.*; +import lombok.*; +import org.hibernate.annotations.DynamicInsert; +import org.hibernate.annotations.SQLRestriction; + +@Getter +@Builder +@Entity +@NoArgsConstructor(access = AccessLevel.PROTECTED) +@AllArgsConstructor +@SQLRestriction("deleted_at is null") +@DynamicInsert +public class BoardReport extends BaseEntity { + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private Long id; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "member_id", nullable = false) + private Member member; + + @ManyToOne(fetch = FetchType.LAZY) + @JoinColumn(name = "board_id") + private Board board; + + @Column(nullable = false) + private BoardReportType reportType; +} diff --git a/src/main/java/com/server/capple/domain/boardReport/entity/BoardReportType.java b/src/main/java/com/server/capple/domain/boardReport/entity/BoardReportType.java new file mode 100644 index 00000000..9fe6a799 --- /dev/null +++ b/src/main/java/com/server/capple/domain/boardReport/entity/BoardReportType.java @@ -0,0 +1,17 @@ +package com.server.capple.domain.boardReport.entity; + +import lombok.RequiredArgsConstructor; + +@RequiredArgsConstructor +public enum BoardReportType { + + BOARD_DISTRIBUTION_OF_ILLEGAL_PHOTOGRAPHS("불법촬영물 등의 유통"), + BOARD_COMMERCIAL_ADVERTISING_AND_SALES("상업적 광고 및 판매"), + BOARD_INADEQUATE_BOARD_CHARACTER("게시판 성격에 부적절함"), + BOARD_ABUSIVE_LANGUAGE_AND_DISPARAGEMENT("욕설/비하"), + BOARD_POLITICAL_PARTY_OR_POLITICIAN_DEMEANING_AND_CAMPAIGNING("정당/정치인 비하 및 선거운동"), + BOARD_LEAK_IMPERSONATION_FRAUD("욕설/사칭/사기"), + BOARD_TRICK_TEASING_PLASTERED("낚시, 놀림, 도배"); + + private final String toKorean; +} From 053c04db80de4470c2ac928308103cbb61fa1dd2 Mon Sep 17 00:00:00 2001 From: KyungsooLee Date: Mon, 9 Sep 2024 01:48:29 +0900 Subject: [PATCH 2/7] =?UTF-8?q?feat:=20#142=20BoardReport=20=EC=BB=A8?= =?UTF-8?q?=ED=8A=B8=EB=A1=A4=EB=9F=AC=20&=20=EA=B8=B0=EB=B3=B8=20?= =?UTF-8?q?=EA=B5=AC=EC=A1=B0=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BoardReportController.java | 71 +++++++++++++++++++ .../boardReport/dto/BoardReportRequest.java | 29 ++++++++ .../boardReport/dto/BoardReportResponse.java | 37 ++++++++++ .../boardReport/mapper/BoardReportMapper.java | 8 +++ .../repository/BoardReportRepository.java | 7 ++ .../service/BoardReportService.java | 18 +++++ .../service/BoardReportServiceImpl.java | 31 ++++++++ 7 files changed, 201 insertions(+) create mode 100644 src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java create mode 100644 src/main/java/com/server/capple/domain/boardReport/dto/BoardReportRequest.java create mode 100644 src/main/java/com/server/capple/domain/boardReport/dto/BoardReportResponse.java create mode 100644 src/main/java/com/server/capple/domain/boardReport/mapper/BoardReportMapper.java create mode 100644 src/main/java/com/server/capple/domain/boardReport/repository/BoardReportRepository.java create mode 100644 src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java create mode 100644 src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java diff --git a/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java b/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java new file mode 100644 index 00000000..79e1dcef --- /dev/null +++ b/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java @@ -0,0 +1,71 @@ +package com.server.capple.domain.boardReport.controller; + +import com.server.capple.config.security.AuthMember; +import com.server.capple.domain.boardReport.dto.BoardReportRequest; +import com.server.capple.domain.boardReport.dto.BoardReportResponse; +import com.server.capple.domain.boardReport.service.BoardReportService; +import com.server.capple.domain.member.entity.Member; +import com.server.capple.domain.report.dto.reponse.ReportResponse; +import com.server.capple.global.common.BaseResponse; +import io.swagger.v3.oas.annotations.Operation; +import io.swagger.v3.oas.annotations.responses.ApiResponse; +import io.swagger.v3.oas.annotations.responses.ApiResponses; +import io.swagger.v3.oas.annotations.tags.Tag; +import jakarta.validation.Valid; +import lombok.RequiredArgsConstructor; +import org.springframework.web.bind.annotation.*; + +@Tag(name = "게시판 신고 API", description = "게시판 신고 관련 API") +@RestController +@RequiredArgsConstructor +@RequestMapping("/board-reports") +public class BoardReportController { + + private final BoardReportService boardReportService; + + @Operation(summary = "게시판 신고함 작성 API", description = "게시판 신고를 작성합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "COMMON200", description = "성공"), + }) + @PostMapping + private BaseResponse createBoardReport( + @AuthMember Member member, + @RequestBody BoardReportRequest.BoardReportCreate request) { + return BaseResponse.onSuccess(boardReportService.createReport(member, request.getBoardReportType())); + } + + @Operation(summary = "게시판 신고함 조회 API", description = "게시판 신고함을 조회합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "COMMON200", description = "성공"), + }) + @GetMapping + private BaseResponse getBoardReports( + @AuthMember Member member) { + return BaseResponse.onSuccess(boardReportService.getBoardReports(member)); + } + + @Operation(summary = "게시판 신고함 수정 API", description = "게시판 신고함을 수정합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "COMMON200", description = "성공"), + }) + @PostMapping("/{boardReportId}") + private BaseResponse updateBoardReport( + @AuthMember Member member, + @PathVariable(value = "boardReportId") Long reportId, + @RequestBody @Valid BoardReportRequest.BoardReportUpdate request) { + + return BaseResponse.onSuccess(boardReportService.updateBoardReport(member, reportId, request.getBoardReportType())); + } + + @Operation(summary = "게시판 신고함 삭제 API", description = "게시판 신고를 삭제합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "COMMON200", description = "성공"), + }) + @DeleteMapping("/{boardReportId}") + private BaseResponse resignBoardReport( + @AuthMember Member member, + @PathVariable(value = "boardReportId") Long boardReportId) { + + return BaseResponse.onSuccess(boardReportService.resignBoardReport(member, boardReportId)); + } +} \ No newline at end of file diff --git a/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportRequest.java b/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportRequest.java new file mode 100644 index 00000000..fb58ae2b --- /dev/null +++ b/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportRequest.java @@ -0,0 +1,29 @@ +package com.server.capple.domain.boardReport.dto; + +import com.server.capple.domain.board.entity.BoardType; +import com.server.capple.domain.boardReport.entity.BoardReportType; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +public class BoardReportRequest { + + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class BoardReportCreate { + Long memberId; + Long boardId; + BoardReportType boardReportType; + } + + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class BoardReportUpdate { + BoardReportType boardReportType; + } +} diff --git a/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportResponse.java b/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportResponse.java new file mode 100644 index 00000000..bb3aeeb8 --- /dev/null +++ b/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportResponse.java @@ -0,0 +1,37 @@ +package com.server.capple.domain.boardReport.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +public class BoardReportResponse { + + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class BoardReportCreate { + } + + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class BoardReportsGet { + } + + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class BoardReportUpdate { + } + + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class BoardReportResign { + } +} diff --git a/src/main/java/com/server/capple/domain/boardReport/mapper/BoardReportMapper.java b/src/main/java/com/server/capple/domain/boardReport/mapper/BoardReportMapper.java new file mode 100644 index 00000000..990d3863 --- /dev/null +++ b/src/main/java/com/server/capple/domain/boardReport/mapper/BoardReportMapper.java @@ -0,0 +1,8 @@ +package com.server.capple.domain.boardReport.mapper; + +import org.springframework.stereotype.Component; + +@Component +public class BoardReportMapper { + +} diff --git a/src/main/java/com/server/capple/domain/boardReport/repository/BoardReportRepository.java b/src/main/java/com/server/capple/domain/boardReport/repository/BoardReportRepository.java new file mode 100644 index 00000000..d64392e1 --- /dev/null +++ b/src/main/java/com/server/capple/domain/boardReport/repository/BoardReportRepository.java @@ -0,0 +1,7 @@ +package com.server.capple.domain.boardReport.repository; + +import com.server.capple.domain.boardReport.entity.BoardReport; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface BoardReportRepository extends JpaRepository { +} diff --git a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java new file mode 100644 index 00000000..12ea71bd --- /dev/null +++ b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java @@ -0,0 +1,18 @@ +package com.server.capple.domain.boardReport.service; + +import com.server.capple.domain.board.entity.BoardType; +import com.server.capple.domain.boardReport.dto.BoardReportRequest; +import com.server.capple.domain.boardReport.dto.BoardReportResponse; +import com.server.capple.domain.boardReport.entity.BoardReportType; +import com.server.capple.domain.member.entity.Member; + +public interface BoardReportService { + BoardReportResponse.BoardReportsGet getBoardReports(Member member); + + BoardReportResponse.BoardReportCreate createReport(Member member, BoardReportType boardReportType); + + BoardReportResponse.BoardReportUpdate updateBoardReport(Member member, Long reportId, BoardReportType boardReportType); + + BoardReportResponse.BoardReportResign resignBoardReport(Member member, Long boardReportId); + +} diff --git a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java new file mode 100644 index 00000000..f4ec3a30 --- /dev/null +++ b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java @@ -0,0 +1,31 @@ +package com.server.capple.domain.boardReport.service; + +import com.server.capple.domain.board.entity.BoardType; +import com.server.capple.domain.boardReport.dto.BoardReportRequest; +import com.server.capple.domain.boardReport.dto.BoardReportResponse; +import com.server.capple.domain.boardReport.entity.BoardReportType; +import com.server.capple.domain.member.entity.Member; +import org.springframework.stereotype.Service; + +@Service +public class BoardReportServiceImpl implements BoardReportService{ + @Override + public BoardReportResponse.BoardReportsGet getBoardReports(Member member) { + return null; + } + + @Override + public BoardReportResponse.BoardReportCreate createReport(Member member, BoardReportType boardReportType) { + return null; + } + + @Override + public BoardReportResponse.BoardReportUpdate updateBoardReport(Member member, Long reportId, BoardReportType boardReportType) { + return null; + } + + @Override + public BoardReportResponse.BoardReportResign resignBoardReport(Member member, Long boardReportId) { + return null; + } +} From c3206b5f2f570f7d1558da4ee4a7012d19af464a Mon Sep 17 00:00:00 2001 From: KyungsooLee Date: Mon, 9 Sep 2024 15:15:44 +0900 Subject: [PATCH 3/7] =?UTF-8?q?feat:=20#142=20BoardReportErrorCode=20?= =?UTF-8?q?=EA=B5=AC=ED=98=84=20=EB=B0=8F=20findBoardReport=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BoardReportController.java | 2 +- .../service/BoardReportService.java | 8 ++++-- .../service/BoardReportServiceImpl.java | 23 ++++++++++++++-- .../errorCode/BoardReportErrorCode.java | 26 +++++++++++++++++++ 4 files changed, 54 insertions(+), 5 deletions(-) create mode 100644 src/main/java/com/server/capple/global/exception/errorCode/BoardReportErrorCode.java diff --git a/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java b/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java index 79e1dcef..ebb6a2d0 100644 --- a/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java +++ b/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java @@ -31,7 +31,7 @@ public class BoardReportController { private BaseResponse createBoardReport( @AuthMember Member member, @RequestBody BoardReportRequest.BoardReportCreate request) { - return BaseResponse.onSuccess(boardReportService.createReport(member, request.getBoardReportType())); + return BaseResponse.onSuccess(boardReportService.createBoardReport(member, request.getBoardReportType())); } @Operation(summary = "게시판 신고함 조회 API", description = "게시판 신고함을 조회합니다.") diff --git a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java index 12ea71bd..a18ddeaf 100644 --- a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java +++ b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java @@ -3,15 +3,19 @@ import com.server.capple.domain.board.entity.BoardType; import com.server.capple.domain.boardReport.dto.BoardReportRequest; import com.server.capple.domain.boardReport.dto.BoardReportResponse; +import com.server.capple.domain.boardReport.entity.BoardReport; import com.server.capple.domain.boardReport.entity.BoardReportType; import com.server.capple.domain.member.entity.Member; +import com.server.capple.domain.report.entity.Report; public interface BoardReportService { + + BoardReport findBoardReport(Long boardReportId); BoardReportResponse.BoardReportsGet getBoardReports(Member member); - BoardReportResponse.BoardReportCreate createReport(Member member, BoardReportType boardReportType); + BoardReportResponse.BoardReportCreate createBoardReport(Member member, BoardReportType boardReportType); - BoardReportResponse.BoardReportUpdate updateBoardReport(Member member, Long reportId, BoardReportType boardReportType); + BoardReportResponse.BoardReportUpdate updateBoardReport(Member member, Long boardReportId, BoardReportType boardReportType); BoardReportResponse.BoardReportResign resignBoardReport(Member member, Long boardReportId); diff --git a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java index f4ec3a30..f87b9f25 100644 --- a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java +++ b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java @@ -3,19 +3,38 @@ import com.server.capple.domain.board.entity.BoardType; import com.server.capple.domain.boardReport.dto.BoardReportRequest; import com.server.capple.domain.boardReport.dto.BoardReportResponse; +import com.server.capple.domain.boardReport.entity.BoardReport; import com.server.capple.domain.boardReport.entity.BoardReportType; +import com.server.capple.domain.boardReport.repository.BoardReportRepository; import com.server.capple.domain.member.entity.Member; +import com.server.capple.domain.report.entity.Report; +import com.server.capple.global.exception.RestApiException; +import com.server.capple.global.exception.errorCode.BoardReportErrorCode; +import com.server.capple.global.exception.errorCode.ReportErrorCode; +import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; @Service -public class BoardReportServiceImpl implements BoardReportService{ +@RequiredArgsConstructor +@Transactional(readOnly = true) +public class BoardReportServiceImpl implements BoardReportService { + + private final BoardReportRepository boardReportRepository; + + @Override + public BoardReport findBoardReport(Long boardReportId) { + return boardReportRepository.findById(boardReportId).orElseThrow(() + -> new RestApiException(BoardReportErrorCode.BOARD_REPORT_NOT_FOUND)); + } + @Override public BoardReportResponse.BoardReportsGet getBoardReports(Member member) { return null; } @Override - public BoardReportResponse.BoardReportCreate createReport(Member member, BoardReportType boardReportType) { + public BoardReportResponse.BoardReportCreate createBoardReport(Member member, BoardReportType boardReportType) { return null; } diff --git a/src/main/java/com/server/capple/global/exception/errorCode/BoardReportErrorCode.java b/src/main/java/com/server/capple/global/exception/errorCode/BoardReportErrorCode.java new file mode 100644 index 00000000..a9b84e9a --- /dev/null +++ b/src/main/java/com/server/capple/global/exception/errorCode/BoardReportErrorCode.java @@ -0,0 +1,26 @@ +package com.server.capple.global.exception.errorCode; + +import com.server.capple.global.exception.ErrorCode; +import com.server.capple.global.exception.ErrorCodeInterface; +import lombok.AllArgsConstructor; +import lombok.Getter; +import org.springframework.http.HttpStatus; + +@Getter +@AllArgsConstructor +public enum BoardReportErrorCode implements ErrorCodeInterface { + BOARD_REPORT_NOT_FOUND("BOARDREPORT001", "게시글 신고가 존재하지 않습니다.", HttpStatus.NOT_FOUND), + ; + private final String code; + private final String message; + private final HttpStatus httpStatus; + + @Override + public ErrorCode getErrorCode() { + return ErrorCode.builder() + .code(code) + .message(message) + .httpStatus(httpStatus) + .build(); + } +} \ No newline at end of file From c2f84f2aa78c20ef1facf11ab8cf535fd747c69e Mon Sep 17 00:00:00 2001 From: KyungsooLee Date: Mon, 9 Sep 2024 15:16:14 +0900 Subject: [PATCH 4/7] =?UTF-8?q?feat:=20#142=20=EA=B2=8C=EC=8B=9C=EA=B8=80?= =?UTF-8?q?=20=EC=8B=A0=EA=B3=A0=20API=20=EA=B5=AC=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/security/SecurityConfig.java | 1 + .../controller/BoardReportController.java | 70 +++++++++---------- .../boardReport/dto/BoardReportRequest.java | 1 - .../boardReport/dto/BoardReportResponse.java | 41 +++++------ .../boardReport/mapper/BoardReportMapper.java | 18 +++++ .../repository/BoardReportRepository.java | 8 +++ .../service/BoardReportService.java | 12 ++-- .../service/BoardReportServiceImpl.java | 48 ++++++++----- .../errorCode/BoardReportErrorCode.java | 1 + 9 files changed, 121 insertions(+), 79 deletions(-) diff --git a/src/main/java/com/server/capple/config/security/SecurityConfig.java b/src/main/java/com/server/capple/config/security/SecurityConfig.java index 2410ca51..b5485a3f 100644 --- a/src/main/java/com/server/capple/config/security/SecurityConfig.java +++ b/src/main/java/com/server/capple/config/security/SecurityConfig.java @@ -58,6 +58,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .requestMatchers("/reports", "/reports/**").authenticated() .requestMatchers("/boards", "/boards/**").authenticated() .requestMatchers("/boardComments", "/boardComments/**").authenticated() + .requestMatchers("/board-reports", "board-reports/**").authenticated() .anyRequest().denyAll()); http .addFilterBefore(new JwtFilter(jwtService), UsernamePasswordAuthenticationFilter.class); diff --git a/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java b/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java index ebb6a2d0..593261dd 100644 --- a/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java +++ b/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java @@ -31,41 +31,41 @@ public class BoardReportController { private BaseResponse createBoardReport( @AuthMember Member member, @RequestBody BoardReportRequest.BoardReportCreate request) { - return BaseResponse.onSuccess(boardReportService.createBoardReport(member, request.getBoardReportType())); + return BaseResponse.onSuccess(boardReportService.createBoardReport(member, request.getBoardId(), request.getBoardReportType())); } - @Operation(summary = "게시판 신고함 조회 API", description = "게시판 신고함을 조회합니다.") - @ApiResponses(value = { - @ApiResponse(responseCode = "COMMON200", description = "성공"), - }) - @GetMapping - private BaseResponse getBoardReports( - @AuthMember Member member) { - return BaseResponse.onSuccess(boardReportService.getBoardReports(member)); - } - - @Operation(summary = "게시판 신고함 수정 API", description = "게시판 신고함을 수정합니다.") - @ApiResponses(value = { - @ApiResponse(responseCode = "COMMON200", description = "성공"), - }) - @PostMapping("/{boardReportId}") - private BaseResponse updateBoardReport( - @AuthMember Member member, - @PathVariable(value = "boardReportId") Long reportId, - @RequestBody @Valid BoardReportRequest.BoardReportUpdate request) { - - return BaseResponse.onSuccess(boardReportService.updateBoardReport(member, reportId, request.getBoardReportType())); - } - - @Operation(summary = "게시판 신고함 삭제 API", description = "게시판 신고를 삭제합니다.") - @ApiResponses(value = { - @ApiResponse(responseCode = "COMMON200", description = "성공"), - }) - @DeleteMapping("/{boardReportId}") - private BaseResponse resignBoardReport( - @AuthMember Member member, - @PathVariable(value = "boardReportId") Long boardReportId) { - - return BaseResponse.onSuccess(boardReportService.resignBoardReport(member, boardReportId)); - } +// @Operation(summary = "게시판 신고함 조회 API", description = "게시판 신고함을 조회합니다.") +// @ApiResponses(value = { +// @ApiResponse(responseCode = "COMMON200", description = "성공"), +// }) +// @GetMapping +// private BaseResponse getBoardReports( +// @AuthMember Member member) { +// return BaseResponse.onSuccess(boardReportService.getBoardReports(member)); +// } +// +// @Operation(summary = "게시판 신고함 수정 API", description = "게시판 신고함을 수정합니다.") +// @ApiResponses(value = { +// @ApiResponse(responseCode = "COMMON200", description = "성공"), +// }) +// @PostMapping("/{boardReportId}") +// private BaseResponse updateBoardReport( +// @AuthMember Member member, +// @PathVariable(value = "boardReportId") Long reportId, +// @RequestBody @Valid BoardReportRequest.BoardReportUpdate request) { +// +// return BaseResponse.onSuccess(boardReportService.updateBoardReport(member, reportId, request.getBoardReportType())); +// } +// +// @Operation(summary = "게시판 신고함 삭제 API", description = "게시판 신고를 삭제합니다.") +// @ApiResponses(value = { +// @ApiResponse(responseCode = "COMMON200", description = "성공"), +// }) +// @DeleteMapping("/{boardReportId}") +// private BaseResponse resignBoardReport( +// @AuthMember Member member, +// @PathVariable(value = "boardReportId") Long boardReportId) { +// +// return BaseResponse.onSuccess(boardReportService.resignBoardReport(member, boardReportId)); +// } } \ No newline at end of file diff --git a/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportRequest.java b/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportRequest.java index fb58ae2b..a1fe543c 100644 --- a/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportRequest.java +++ b/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportRequest.java @@ -14,7 +14,6 @@ public class BoardReportRequest { @AllArgsConstructor @NoArgsConstructor public static class BoardReportCreate { - Long memberId; Long boardId; BoardReportType boardReportType; } diff --git a/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportResponse.java b/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportResponse.java index bb3aeeb8..6db6c089 100644 --- a/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportResponse.java +++ b/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportResponse.java @@ -12,26 +12,27 @@ public class BoardReportResponse { @AllArgsConstructor @NoArgsConstructor public static class BoardReportCreate { + Long boardReportId; } - @Getter - @Builder - @AllArgsConstructor - @NoArgsConstructor - public static class BoardReportsGet { - } - - @Getter - @Builder - @AllArgsConstructor - @NoArgsConstructor - public static class BoardReportUpdate { - } - - @Getter - @Builder - @AllArgsConstructor - @NoArgsConstructor - public static class BoardReportResign { - } +// @Getter +// @Builder +// @AllArgsConstructor +// @NoArgsConstructor +// public static class BoardReportsGet { +// } +// +// @Getter +// @Builder +// @AllArgsConstructor +// @NoArgsConstructor +// public static class BoardReportUpdate { +// } +// +// @Getter +// @Builder +// @AllArgsConstructor +// @NoArgsConstructor +// public static class BoardReportResign { +// } } diff --git a/src/main/java/com/server/capple/domain/boardReport/mapper/BoardReportMapper.java b/src/main/java/com/server/capple/domain/boardReport/mapper/BoardReportMapper.java index 990d3863..3212794d 100644 --- a/src/main/java/com/server/capple/domain/boardReport/mapper/BoardReportMapper.java +++ b/src/main/java/com/server/capple/domain/boardReport/mapper/BoardReportMapper.java @@ -1,8 +1,26 @@ package com.server.capple.domain.boardReport.mapper; +import com.server.capple.domain.board.entity.Board; +import com.server.capple.domain.boardReport.dto.BoardReportResponse; +import com.server.capple.domain.boardReport.entity.BoardReport; +import com.server.capple.domain.boardReport.entity.BoardReportType; +import com.server.capple.domain.member.entity.Member; import org.springframework.stereotype.Component; @Component public class BoardReportMapper { + public BoardReport toBoardReport(Member member, Board board, BoardReportType boardReportType) { + return BoardReport.builder() + .member(member) + .board(board) + .reportType(boardReportType) + .build(); + } + + public BoardReportResponse.BoardReportCreate toBoardReportCreate(BoardReport boardReport) { + return BoardReportResponse.BoardReportCreate.builder() + .boardReportId(boardReport.getId()) + .build(); + } } diff --git a/src/main/java/com/server/capple/domain/boardReport/repository/BoardReportRepository.java b/src/main/java/com/server/capple/domain/boardReport/repository/BoardReportRepository.java index d64392e1..4f5a683a 100644 --- a/src/main/java/com/server/capple/domain/boardReport/repository/BoardReportRepository.java +++ b/src/main/java/com/server/capple/domain/boardReport/repository/BoardReportRepository.java @@ -1,7 +1,15 @@ package com.server.capple.domain.boardReport.repository; +import com.server.capple.domain.board.entity.Board; import com.server.capple.domain.boardReport.entity.BoardReport; +import com.server.capple.domain.member.entity.Member; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.Optional; + public interface BoardReportRepository extends JpaRepository { + + Boolean existsByMemberAndBoard(Member member, Board board); + + Optional findByMemberAndBoard(Member member, Board board); } diff --git a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java index a18ddeaf..b58e6562 100644 --- a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java +++ b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java @@ -11,12 +11,12 @@ public interface BoardReportService { BoardReport findBoardReport(Long boardReportId); - BoardReportResponse.BoardReportsGet getBoardReports(Member member); +// BoardReportResponse.BoardReportsGet getBoardReports(Member member); +// + BoardReportResponse.BoardReportCreate createBoardReport(Member member, Long boardId, BoardReportType boardReportType); - BoardReportResponse.BoardReportCreate createBoardReport(Member member, BoardReportType boardReportType); - - BoardReportResponse.BoardReportUpdate updateBoardReport(Member member, Long boardReportId, BoardReportType boardReportType); - - BoardReportResponse.BoardReportResign resignBoardReport(Member member, Long boardReportId); +// BoardReportResponse.BoardReportUpdate updateBoardReport(Member member, Long boardReportId, BoardReportType boardReportType); +// +// BoardReportResponse.BoardReportResign resignBoardReport(Member member, Long boardReportId); } diff --git a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java index f87b9f25..da78b7b2 100644 --- a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java +++ b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java @@ -1,26 +1,31 @@ package com.server.capple.domain.boardReport.service; +import com.server.capple.domain.board.entity.Board; import com.server.capple.domain.board.entity.BoardType; +import com.server.capple.domain.board.service.BoardService; import com.server.capple.domain.boardReport.dto.BoardReportRequest; import com.server.capple.domain.boardReport.dto.BoardReportResponse; import com.server.capple.domain.boardReport.entity.BoardReport; import com.server.capple.domain.boardReport.entity.BoardReportType; +import com.server.capple.domain.boardReport.mapper.BoardReportMapper; import com.server.capple.domain.boardReport.repository.BoardReportRepository; import com.server.capple.domain.member.entity.Member; -import com.server.capple.domain.report.entity.Report; +import com.server.capple.domain.member.service.MemberService; import com.server.capple.global.exception.RestApiException; import com.server.capple.global.exception.errorCode.BoardReportErrorCode; -import com.server.capple.global.exception.errorCode.ReportErrorCode; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @Service @RequiredArgsConstructor -@Transactional(readOnly = true) +@Transactional public class BoardReportServiceImpl implements BoardReportService { private final BoardReportRepository boardReportRepository; + private final MemberService memberService; + private final BoardService boardService; + private final BoardReportMapper boardReportMapper; @Override public BoardReport findBoardReport(Long boardReportId) { @@ -28,23 +33,32 @@ public BoardReport findBoardReport(Long boardReportId) { -> new RestApiException(BoardReportErrorCode.BOARD_REPORT_NOT_FOUND)); } - @Override - public BoardReportResponse.BoardReportsGet getBoardReports(Member member) { - return null; - } +// @Override +// public BoardReportResponse.BoardReportsGet getBoardReports(Member member) { +// return null; +// } @Override - public BoardReportResponse.BoardReportCreate createBoardReport(Member member, BoardReportType boardReportType) { - return null; - } + public BoardReportResponse.BoardReportCreate createBoardReport(Member member, Long boardId, BoardReportType boardReportType) { + Member reportMember = memberService.findMember(member.getId()); - @Override - public BoardReportResponse.BoardReportUpdate updateBoardReport(Member member, Long reportId, BoardReportType boardReportType) { - return null; - } + Board board = boardService.findBoard(boardId); - @Override - public BoardReportResponse.BoardReportResign resignBoardReport(Member member, Long boardReportId) { - return null; + if (boardReportRepository.existsByMemberAndBoard(reportMember, board)) { + throw new RestApiException(BoardReportErrorCode.BOARD_REPORT_ALREADY_EXIST); + } + BoardReport boardReport = boardReportRepository.save(boardReportMapper.toBoardReport(reportMember, board, boardReportType)); + + return boardReportMapper.toBoardReportCreate(boardReport); } + +// @Override +// public BoardReportResponse.BoardReportUpdate updateBoardReport(Member member, Long reportId, BoardReportType boardReportType) { +// return null; +// } +// +// @Override +// public BoardReportResponse.BoardReportResign resignBoardReport(Member member, Long boardReportId) { +// return null; +// } } diff --git a/src/main/java/com/server/capple/global/exception/errorCode/BoardReportErrorCode.java b/src/main/java/com/server/capple/global/exception/errorCode/BoardReportErrorCode.java index a9b84e9a..773ddfd7 100644 --- a/src/main/java/com/server/capple/global/exception/errorCode/BoardReportErrorCode.java +++ b/src/main/java/com/server/capple/global/exception/errorCode/BoardReportErrorCode.java @@ -10,6 +10,7 @@ @AllArgsConstructor public enum BoardReportErrorCode implements ErrorCodeInterface { BOARD_REPORT_NOT_FOUND("BOARDREPORT001", "게시글 신고가 존재하지 않습니다.", HttpStatus.NOT_FOUND), + BOARD_REPORT_ALREADY_EXIST("BOARDREPORT002", "이미 신고한 게시글입니다.", HttpStatus.ALREADY_REPORTED), ; private final String code; private final String message; From 16168160a0972199079b998db04da301351420d6 Mon Sep 17 00:00:00 2001 From: KyungsooLee Date: Mon, 9 Sep 2024 15:47:48 +0900 Subject: [PATCH 5/7] =?UTF-8?q?feat:=20#142=20=EB=82=B4=20=EC=8B=A0?= =?UTF-8?q?=EA=B3=A0=ED=95=A8=20=EC=A1=B0=ED=9A=8C=20API=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BoardReportController.java | 20 ++++++------ .../boardReport/dto/BoardReportResponse.java | 31 ++++++++++++++----- .../boardReport/mapper/BoardReportMapper.java | 17 ++++++++++ .../repository/BoardReportRepository.java | 3 ++ .../service/BoardReportService.java | 4 +-- .../service/BoardReportServiceImpl.java | 19 ++++++++---- .../report/repository/ReportRepository.java | 6 ++++ 7 files changed, 75 insertions(+), 25 deletions(-) diff --git a/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java b/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java index 593261dd..a09d5c19 100644 --- a/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java +++ b/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java @@ -34,16 +34,16 @@ private BaseResponse createBoardReport( return BaseResponse.onSuccess(boardReportService.createBoardReport(member, request.getBoardId(), request.getBoardReportType())); } -// @Operation(summary = "게시판 신고함 조회 API", description = "게시판 신고함을 조회합니다.") -// @ApiResponses(value = { -// @ApiResponse(responseCode = "COMMON200", description = "성공"), -// }) -// @GetMapping -// private BaseResponse getBoardReports( -// @AuthMember Member member) { -// return BaseResponse.onSuccess(boardReportService.getBoardReports(member)); -// } -// + @Operation(summary = "내 게시판 신고함 조회 API", description = "내가 신고한 게시판을 조회합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "COMMON200", description = "성공"), + }) + @GetMapping("/mine") + private BaseResponse getMyBoardReports( + @AuthMember Member member) { + return BaseResponse.onSuccess(boardReportService.getMyBoardReports(member)); + } + // @Operation(summary = "게시판 신고함 수정 API", description = "게시판 신고함을 수정합니다.") // @ApiResponses(value = { // @ApiResponse(responseCode = "COMMON200", description = "성공"), diff --git a/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportResponse.java b/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportResponse.java index 6db6c089..eb041706 100644 --- a/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportResponse.java +++ b/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportResponse.java @@ -1,10 +1,15 @@ package com.server.capple.domain.boardReport.dto; +import com.server.capple.domain.boardReport.entity.BoardReport; +import com.server.capple.domain.boardReport.entity.BoardReportType; +import com.server.capple.global.exception.errorCode.BoardReportErrorCode; import lombok.AllArgsConstructor; import lombok.Builder; import lombok.Getter; import lombok.NoArgsConstructor; +import java.util.List; + public class BoardReportResponse { @Getter @@ -15,13 +20,25 @@ public static class BoardReportCreate { Long boardReportId; } -// @Getter -// @Builder -// @AllArgsConstructor -// @NoArgsConstructor -// public static class BoardReportsGet { -// } -// + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class BoardReportsGet { + List boardReportInfos; + } + + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class BoardReportInfo { + Long boardReportId; + Long reporterId; + Long boardId; + BoardReportType boardReportType; + } + // @Getter // @Builder // @AllArgsConstructor diff --git a/src/main/java/com/server/capple/domain/boardReport/mapper/BoardReportMapper.java b/src/main/java/com/server/capple/domain/boardReport/mapper/BoardReportMapper.java index 3212794d..9d87fcf6 100644 --- a/src/main/java/com/server/capple/domain/boardReport/mapper/BoardReportMapper.java +++ b/src/main/java/com/server/capple/domain/boardReport/mapper/BoardReportMapper.java @@ -7,6 +7,8 @@ import com.server.capple.domain.member.entity.Member; import org.springframework.stereotype.Component; +import java.util.List; + @Component public class BoardReportMapper { @@ -23,4 +25,19 @@ public BoardReportResponse.BoardReportCreate toBoardReportCreate(BoardReport boa .boardReportId(boardReport.getId()) .build(); } + + public BoardReportResponse.BoardReportsGet toBoardReportsGet(List boardReportInfos) { + return BoardReportResponse.BoardReportsGet.builder() + .boardReportInfos(boardReportInfos) + .build(); + } + + public BoardReportResponse.BoardReportInfo toBoardReportInfo(BoardReport boardReport) { + return BoardReportResponse.BoardReportInfo.builder() + .boardReportId(boardReport.getId()) + .reporterId(boardReport.getMember().getId()) + .boardId(boardReport.getBoard().getId()) + .boardReportType(boardReport.getReportType()) + .build(); + } } diff --git a/src/main/java/com/server/capple/domain/boardReport/repository/BoardReportRepository.java b/src/main/java/com/server/capple/domain/boardReport/repository/BoardReportRepository.java index 4f5a683a..4e4cfb76 100644 --- a/src/main/java/com/server/capple/domain/boardReport/repository/BoardReportRepository.java +++ b/src/main/java/com/server/capple/domain/boardReport/repository/BoardReportRepository.java @@ -5,6 +5,7 @@ import com.server.capple.domain.member.entity.Member; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; import java.util.Optional; public interface BoardReportRepository extends JpaRepository { @@ -12,4 +13,6 @@ public interface BoardReportRepository extends JpaRepository Boolean existsByMemberAndBoard(Member member, Board board); Optional findByMemberAndBoard(Member member, Board board); + + List findByMember(Member member); } diff --git a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java index b58e6562..4470a6d5 100644 --- a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java +++ b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java @@ -11,8 +11,8 @@ public interface BoardReportService { BoardReport findBoardReport(Long boardReportId); -// BoardReportResponse.BoardReportsGet getBoardReports(Member member); -// + BoardReportResponse.BoardReportsGet getMyBoardReports(Member member); + BoardReportResponse.BoardReportCreate createBoardReport(Member member, Long boardId, BoardReportType boardReportType); // BoardReportResponse.BoardReportUpdate updateBoardReport(Member member, Long boardReportId, BoardReportType boardReportType); diff --git a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java index da78b7b2..3829ac78 100644 --- a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java +++ b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java @@ -1,9 +1,7 @@ package com.server.capple.domain.boardReport.service; import com.server.capple.domain.board.entity.Board; -import com.server.capple.domain.board.entity.BoardType; import com.server.capple.domain.board.service.BoardService; -import com.server.capple.domain.boardReport.dto.BoardReportRequest; import com.server.capple.domain.boardReport.dto.BoardReportResponse; import com.server.capple.domain.boardReport.entity.BoardReport; import com.server.capple.domain.boardReport.entity.BoardReportType; @@ -17,6 +15,8 @@ import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; +import java.util.List; + @Service @RequiredArgsConstructor @Transactional @@ -33,10 +33,17 @@ public BoardReport findBoardReport(Long boardReportId) { -> new RestApiException(BoardReportErrorCode.BOARD_REPORT_NOT_FOUND)); } -// @Override -// public BoardReportResponse.BoardReportsGet getBoardReports(Member member) { -// return null; -// } + @Override + public BoardReportResponse.BoardReportsGet getMyBoardReports(Member member) { + Member findMember = memberService.findMember(member.getId()); + + List boardReports = boardReportRepository.findByMember(member); + + return boardReportMapper.toBoardReportsGet(boardReports + .stream() + .map(boardReportMapper::toBoardReportInfo) + .toList()); + } @Override public BoardReportResponse.BoardReportCreate createBoardReport(Member member, Long boardId, BoardReportType boardReportType) { diff --git a/src/main/java/com/server/capple/domain/report/repository/ReportRepository.java b/src/main/java/com/server/capple/domain/report/repository/ReportRepository.java index 362dc45f..278addcb 100644 --- a/src/main/java/com/server/capple/domain/report/repository/ReportRepository.java +++ b/src/main/java/com/server/capple/domain/report/repository/ReportRepository.java @@ -1,10 +1,16 @@ package com.server.capple.domain.report.repository; import com.server.capple.domain.answer.entity.Answer; +import com.server.capple.domain.member.entity.Member; import com.server.capple.domain.question.entity.Question; import com.server.capple.domain.report.entity.Report; import org.springframework.data.jpa.repository.JpaRepository; +import java.util.List; +import java.util.Optional; + public interface ReportRepository extends JpaRepository { Boolean existsReportByAnswer(Answer answer); + + List findByMember(Member member); } From 3935fd632c332ce7f65198b68d089e0234ff55fc Mon Sep 17 00:00:00 2001 From: KyungsooLee Date: Mon, 9 Sep 2024 23:09:31 +0900 Subject: [PATCH 6/7] =?UTF-8?q?feat:=20#142=20=EC=8B=A0=EA=B3=A0=ED=95=A8?= =?UTF-8?q?=20=EC=88=98=EC=A0=95,=20=EC=82=AD=EC=A0=9C=20API=20=EA=B5=AC?= =?UTF-8?q?=ED=98=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controller/BoardReportController.java | 48 +++++++++---------- .../boardReport/dto/BoardReportResponse.java | 29 ++++++----- .../boardReport/entity/BoardReport.java | 6 ++- .../boardReport/mapper/BoardReportMapper.java | 16 ++++++- .../service/BoardReportService.java | 5 +- .../service/BoardReportServiceImpl.java | 44 +++++++++++++---- .../errorCode/BoardReportErrorCode.java | 1 + 7 files changed, 97 insertions(+), 52 deletions(-) diff --git a/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java b/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java index a09d5c19..e7d4672d 100644 --- a/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java +++ b/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java @@ -44,28 +44,28 @@ private BaseResponse getMyBoardReports( return BaseResponse.onSuccess(boardReportService.getMyBoardReports(member)); } -// @Operation(summary = "게시판 신고함 수정 API", description = "게시판 신고함을 수정합니다.") -// @ApiResponses(value = { -// @ApiResponse(responseCode = "COMMON200", description = "성공"), -// }) -// @PostMapping("/{boardReportId}") -// private BaseResponse updateBoardReport( -// @AuthMember Member member, -// @PathVariable(value = "boardReportId") Long reportId, -// @RequestBody @Valid BoardReportRequest.BoardReportUpdate request) { -// -// return BaseResponse.onSuccess(boardReportService.updateBoardReport(member, reportId, request.getBoardReportType())); -// } -// -// @Operation(summary = "게시판 신고함 삭제 API", description = "게시판 신고를 삭제합니다.") -// @ApiResponses(value = { -// @ApiResponse(responseCode = "COMMON200", description = "성공"), -// }) -// @DeleteMapping("/{boardReportId}") -// private BaseResponse resignBoardReport( -// @AuthMember Member member, -// @PathVariable(value = "boardReportId") Long boardReportId) { -// -// return BaseResponse.onSuccess(boardReportService.resignBoardReport(member, boardReportId)); -// } + @Operation(summary = "게시판 신고함 수정 API", description = "게시판 신고함을 수정합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "COMMON200", description = "성공"), + }) + @PostMapping("/{boardReportId}") + private BaseResponse updateBoardReport( + @AuthMember Member member, + @PathVariable(value = "boardReportId") Long reportId, + @RequestBody @Valid BoardReportRequest.BoardReportUpdate request) { + + return BaseResponse.onSuccess(boardReportService.updateBoardReport(member, reportId, request.getBoardReportType())); + } + + @Operation(summary = "게시판 신고함 삭제 API", description = "게시판 신고를 삭제합니다.") + @ApiResponses(value = { + @ApiResponse(responseCode = "COMMON200", description = "성공"), + }) + @DeleteMapping("/{boardReportId}") + private BaseResponse resignBoardReport( + @AuthMember Member member, + @PathVariable(value = "boardReportId") Long boardReportId) { + + return BaseResponse.onSuccess(boardReportService.resignBoardReport(member, boardReportId)); + } } \ No newline at end of file diff --git a/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportResponse.java b/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportResponse.java index eb041706..22e66156 100644 --- a/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportResponse.java +++ b/src/main/java/com/server/capple/domain/boardReport/dto/BoardReportResponse.java @@ -39,17 +39,20 @@ public static class BoardReportInfo { BoardReportType boardReportType; } -// @Getter -// @Builder -// @AllArgsConstructor -// @NoArgsConstructor -// public static class BoardReportUpdate { -// } -// -// @Getter -// @Builder -// @AllArgsConstructor -// @NoArgsConstructor -// public static class BoardReportResign { -// } + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class BoardReportUpdate { + Long boardReportId; + } + + @Getter + @Builder + @AllArgsConstructor + @NoArgsConstructor + public static class BoardReportResign { + Long boardReportId; + } + } diff --git a/src/main/java/com/server/capple/domain/boardReport/entity/BoardReport.java b/src/main/java/com/server/capple/domain/boardReport/entity/BoardReport.java index b7414428..91da561b 100644 --- a/src/main/java/com/server/capple/domain/boardReport/entity/BoardReport.java +++ b/src/main/java/com/server/capple/domain/boardReport/entity/BoardReport.java @@ -29,5 +29,9 @@ public class BoardReport extends BaseEntity { private Board board; @Column(nullable = false) - private BoardReportType reportType; + private BoardReportType boardReportType; + + public void updateBoardReportType(BoardReportType boardReportType) { + this.boardReportType = boardReportType; + } } diff --git a/src/main/java/com/server/capple/domain/boardReport/mapper/BoardReportMapper.java b/src/main/java/com/server/capple/domain/boardReport/mapper/BoardReportMapper.java index 9d87fcf6..79b53e34 100644 --- a/src/main/java/com/server/capple/domain/boardReport/mapper/BoardReportMapper.java +++ b/src/main/java/com/server/capple/domain/boardReport/mapper/BoardReportMapper.java @@ -16,7 +16,7 @@ public BoardReport toBoardReport(Member member, Board board, BoardReportType boa return BoardReport.builder() .member(member) .board(board) - .reportType(boardReportType) + .boardReportType(boardReportType) .build(); } @@ -37,7 +37,19 @@ public BoardReportResponse.BoardReportInfo toBoardReportInfo(BoardReport boardRe .boardReportId(boardReport.getId()) .reporterId(boardReport.getMember().getId()) .boardId(boardReport.getBoard().getId()) - .boardReportType(boardReport.getReportType()) + .boardReportType(boardReport.getBoardReportType()) + .build(); + } + + public BoardReportResponse.BoardReportUpdate toBoardReportUpdate(BoardReport boardReport) { + return BoardReportResponse.BoardReportUpdate.builder() + .boardReportId(boardReport.getId()) + .build(); + } + + public BoardReportResponse.BoardReportResign toBoardReportResign(BoardReport boardReport) { + return BoardReportResponse.BoardReportResign.builder() + .boardReportId(boardReport.getId()) .build(); } } diff --git a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java index 4470a6d5..255afa10 100644 --- a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java +++ b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java @@ -15,8 +15,7 @@ public interface BoardReportService { BoardReportResponse.BoardReportCreate createBoardReport(Member member, Long boardId, BoardReportType boardReportType); -// BoardReportResponse.BoardReportUpdate updateBoardReport(Member member, Long boardReportId, BoardReportType boardReportType); -// -// BoardReportResponse.BoardReportResign resignBoardReport(Member member, Long boardReportId); + BoardReportResponse.BoardReportUpdate updateBoardReport(Member member, Long reportId, BoardReportType boardReportType); + BoardReportResponse.BoardReportResign resignBoardReport(Member member, Long boardReportId); } diff --git a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java index 3829ac78..6e3d61b8 100644 --- a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java +++ b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java @@ -9,13 +9,16 @@ import com.server.capple.domain.boardReport.repository.BoardReportRepository; import com.server.capple.domain.member.entity.Member; import com.server.capple.domain.member.service.MemberService; +import com.server.capple.domain.report.entity.Report; import com.server.capple.global.exception.RestApiException; import com.server.capple.global.exception.errorCode.BoardReportErrorCode; +import com.server.capple.global.exception.errorCode.ReportErrorCode; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; +import java.util.Optional; @Service @RequiredArgsConstructor @@ -59,13 +62,36 @@ public BoardReportResponse.BoardReportCreate createBoardReport(Member member, Lo return boardReportMapper.toBoardReportCreate(boardReport); } -// @Override -// public BoardReportResponse.BoardReportUpdate updateBoardReport(Member member, Long reportId, BoardReportType boardReportType) { -// return null; -// } -// -// @Override -// public BoardReportResponse.BoardReportResign resignBoardReport(Member member, Long boardReportId) { -// return null; -// } + @Override + public BoardReportResponse.BoardReportUpdate updateBoardReport(Member member, Long boardReportId, BoardReportType boardReportType) { + Member reportMember = memberService.findMember(member.getId()); + + BoardReport boardReport = boardReportRepository.findById(boardReportId) + .orElseThrow(() -> new RestApiException(BoardReportErrorCode.BOARD_REPORT_NOT_FOUND)); + + // 만약 본인이 작성자가 아니면 + if (!reportMember.getId().equals(boardReport.getBoard().getWriter().getId())) { + throw new RestApiException(BoardReportErrorCode.BOARD_REPORT_NO_AUTHORIZATION); + } + + boardReport.updateBoardReportType(boardReportType); + + return boardReportMapper.toBoardReportUpdate(boardReport); + } + + @Override + public BoardReportResponse.BoardReportResign resignBoardReport(Member member, Long boardReportId) { + Member reportMember = memberService.findMember(member.getId()); + + BoardReport boardReport = boardReportRepository.findById(boardReportId) + .orElseThrow(() -> new RestApiException(BoardReportErrorCode.BOARD_REPORT_NOT_FOUND)); + + // 만약 본인이 작성자가 아니면 + if (!reportMember.getId().equals(boardReport.getBoard().getWriter().getId())) { + throw new RestApiException(BoardReportErrorCode.BOARD_REPORT_NO_AUTHORIZATION); + } + + boardReport.delete(); + return boardReportMapper.toBoardReportResign(boardReport); + } } diff --git a/src/main/java/com/server/capple/global/exception/errorCode/BoardReportErrorCode.java b/src/main/java/com/server/capple/global/exception/errorCode/BoardReportErrorCode.java index 773ddfd7..7863a856 100644 --- a/src/main/java/com/server/capple/global/exception/errorCode/BoardReportErrorCode.java +++ b/src/main/java/com/server/capple/global/exception/errorCode/BoardReportErrorCode.java @@ -11,6 +11,7 @@ public enum BoardReportErrorCode implements ErrorCodeInterface { BOARD_REPORT_NOT_FOUND("BOARDREPORT001", "게시글 신고가 존재하지 않습니다.", HttpStatus.NOT_FOUND), BOARD_REPORT_ALREADY_EXIST("BOARDREPORT002", "이미 신고한 게시글입니다.", HttpStatus.ALREADY_REPORTED), + BOARD_REPORT_NO_AUTHORIZATION("BOARDREPORT003", "해당 신고를 삭제할 권한이 없습니다.", HttpStatus.FORBIDDEN) ; private final String code; private final String message; From 5f17b6cb301efb74ffcfe8d2eacced43d4a64771 Mon Sep 17 00:00:00 2001 From: KyungsooLee Date: Tue, 10 Sep 2024 00:21:54 +0900 Subject: [PATCH 7/7] =?UTF-8?q?fix:=20#142=20=EC=A4=91=EB=B3=B5=20?= =?UTF-8?q?=EC=BD=94=EB=93=9C=20=EC=82=AD=EC=A0=9C=20&=20board=20nullable?= =?UTF-8?q?=20=EC=98=B5=EC=85=98=20=EB=B3=80=EA=B2=BD=20&=20=EC=97=94?= =?UTF-8?q?=EB=93=9C=ED=8F=AC=EC=9D=B8=ED=8A=B8=20=EB=B3=80=EA=B2=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../config/security/SecurityConfig.java | 2 +- .../controller/BoardReportController.java | 2 +- .../boardReport/entity/BoardReport.java | 2 +- .../service/BoardReportService.java | 3 ++ .../service/BoardReportServiceImpl.java | 35 +++++++++---------- 5 files changed, 22 insertions(+), 22 deletions(-) diff --git a/src/main/java/com/server/capple/config/security/SecurityConfig.java b/src/main/java/com/server/capple/config/security/SecurityConfig.java index b5485a3f..20003667 100644 --- a/src/main/java/com/server/capple/config/security/SecurityConfig.java +++ b/src/main/java/com/server/capple/config/security/SecurityConfig.java @@ -58,7 +58,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception { .requestMatchers("/reports", "/reports/**").authenticated() .requestMatchers("/boards", "/boards/**").authenticated() .requestMatchers("/boardComments", "/boardComments/**").authenticated() - .requestMatchers("/board-reports", "board-reports/**").authenticated() + .requestMatchers("/boardReports", "boardReports/**").authenticated() .anyRequest().denyAll()); http .addFilterBefore(new JwtFilter(jwtService), UsernamePasswordAuthenticationFilter.class); diff --git a/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java b/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java index e7d4672d..6a37960a 100644 --- a/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java +++ b/src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.java @@ -18,7 +18,7 @@ @Tag(name = "게시판 신고 API", description = "게시판 신고 관련 API") @RestController @RequiredArgsConstructor -@RequestMapping("/board-reports") +@RequestMapping("/boardReports") public class BoardReportController { private final BoardReportService boardReportService; diff --git a/src/main/java/com/server/capple/domain/boardReport/entity/BoardReport.java b/src/main/java/com/server/capple/domain/boardReport/entity/BoardReport.java index 91da561b..4d062968 100644 --- a/src/main/java/com/server/capple/domain/boardReport/entity/BoardReport.java +++ b/src/main/java/com/server/capple/domain/boardReport/entity/BoardReport.java @@ -25,7 +25,7 @@ public class BoardReport extends BaseEntity { private Member member; @ManyToOne(fetch = FetchType.LAZY) - @JoinColumn(name = "board_id") + @JoinColumn(name = "board_id", nullable = false) private Board board; @Column(nullable = false) diff --git a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java index 255afa10..03913fe5 100644 --- a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java +++ b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.java @@ -11,6 +11,9 @@ public interface BoardReportService { BoardReport findBoardReport(Long boardReportId); + + Boolean isReporter(Long reporterId, Long memberId); + BoardReportResponse.BoardReportsGet getMyBoardReports(Member member); BoardReportResponse.BoardReportCreate createBoardReport(Member member, Long boardId, BoardReportType boardReportType); diff --git a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java index 6e3d61b8..6f038a73 100644 --- a/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java +++ b/src/main/java/com/server/capple/domain/boardReport/service/BoardReportServiceImpl.java @@ -9,16 +9,13 @@ import com.server.capple.domain.boardReport.repository.BoardReportRepository; import com.server.capple.domain.member.entity.Member; import com.server.capple.domain.member.service.MemberService; -import com.server.capple.domain.report.entity.Report; import com.server.capple.global.exception.RestApiException; import com.server.capple.global.exception.errorCode.BoardReportErrorCode; -import com.server.capple.global.exception.errorCode.ReportErrorCode; import lombok.RequiredArgsConstructor; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; import java.util.List; -import java.util.Optional; @Service @RequiredArgsConstructor @@ -36,9 +33,13 @@ public BoardReport findBoardReport(Long boardReportId) { -> new RestApiException(BoardReportErrorCode.BOARD_REPORT_NOT_FOUND)); } + @Override + public Boolean isReporter(Long reporterId, Long memberId) { + return reporterId.equals(memberId); + } + @Override public BoardReportResponse.BoardReportsGet getMyBoardReports(Member member) { - Member findMember = memberService.findMember(member.getId()); List boardReports = boardReportRepository.findByMember(member); @@ -50,48 +51,44 @@ public BoardReportResponse.BoardReportsGet getMyBoardReports(Member member) { @Override public BoardReportResponse.BoardReportCreate createBoardReport(Member member, Long boardId, BoardReportType boardReportType) { - Member reportMember = memberService.findMember(member.getId()); Board board = boardService.findBoard(boardId); - if (boardReportRepository.existsByMemberAndBoard(reportMember, board)) { + if (boardReportRepository.existsByMemberAndBoard(member, board)) { throw new RestApiException(BoardReportErrorCode.BOARD_REPORT_ALREADY_EXIST); } - BoardReport boardReport = boardReportRepository.save(boardReportMapper.toBoardReport(reportMember, board, boardReportType)); + BoardReport boardReport = boardReportRepository.save(boardReportMapper.toBoardReport(member, board, boardReportType)); return boardReportMapper.toBoardReportCreate(boardReport); } @Override public BoardReportResponse.BoardReportUpdate updateBoardReport(Member member, Long boardReportId, BoardReportType boardReportType) { - Member reportMember = memberService.findMember(member.getId()); - BoardReport boardReport = boardReportRepository.findById(boardReportId) - .orElseThrow(() -> new RestApiException(BoardReportErrorCode.BOARD_REPORT_NOT_FOUND)); + BoardReport boardReport = findBoardReport(boardReportId); // 만약 본인이 작성자가 아니면 - if (!reportMember.getId().equals(boardReport.getBoard().getWriter().getId())) { - throw new RestApiException(BoardReportErrorCode.BOARD_REPORT_NO_AUTHORIZATION); + if (isReporter(member.getId(), boardReport.getMember().getId())) { + boardReport.updateBoardReportType(boardReportType); + } else { + throw new RestApiException(BoardReportErrorCode.BOARD_REPORT_NO_AUTHORIZATION); } - boardReport.updateBoardReportType(boardReportType); - return boardReportMapper.toBoardReportUpdate(boardReport); } @Override public BoardReportResponse.BoardReportResign resignBoardReport(Member member, Long boardReportId) { - Member reportMember = memberService.findMember(member.getId()); - BoardReport boardReport = boardReportRepository.findById(boardReportId) - .orElseThrow(() -> new RestApiException(BoardReportErrorCode.BOARD_REPORT_NOT_FOUND)); + BoardReport boardReport = findBoardReport(boardReportId); // 만약 본인이 작성자가 아니면 - if (!reportMember.getId().equals(boardReport.getBoard().getWriter().getId())) { + if (isReporter(member.getId(), boardReport.getMember().getId())) { + boardReport.delete(); + } else { throw new RestApiException(BoardReportErrorCode.BOARD_REPORT_NO_AUTHORIZATION); } - boardReport.delete(); return boardReportMapper.toBoardReportResign(boardReport); } }