-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
[FEAT] 신고함 기능 구현(게시판)
- Loading branch information
Showing
12 changed files
with
437 additions
and
0 deletions.
There are no files selected for viewing
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
71 changes: 71 additions & 0 deletions
71
src/main/java/com/server/capple/domain/boardReport/controller/BoardReportController.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,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("/boardReports") | ||
public class BoardReportController { | ||
|
||
private final BoardReportService boardReportService; | ||
|
||
@Operation(summary = "게시판 신고함 작성 API", description = "게시판 신고를 작성합니다.") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "COMMON200", description = "성공"), | ||
}) | ||
@PostMapping | ||
private BaseResponse<BoardReportResponse.BoardReportCreate> createBoardReport( | ||
@AuthMember Member member, | ||
@RequestBody BoardReportRequest.BoardReportCreate request) { | ||
return BaseResponse.onSuccess(boardReportService.createBoardReport(member, request.getBoardId(), request.getBoardReportType())); | ||
} | ||
|
||
@Operation(summary = "내 게시판 신고함 조회 API", description = "내가 신고한 게시판을 조회합니다.") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "COMMON200", description = "성공"), | ||
}) | ||
@GetMapping("/mine") | ||
private BaseResponse<BoardReportResponse.BoardReportsGet> getMyBoardReports( | ||
@AuthMember Member member) { | ||
return BaseResponse.onSuccess(boardReportService.getMyBoardReports(member)); | ||
} | ||
|
||
@Operation(summary = "게시판 신고함 수정 API", description = "게시판 신고함을 수정합니다.") | ||
@ApiResponses(value = { | ||
@ApiResponse(responseCode = "COMMON200", description = "성공"), | ||
}) | ||
@PostMapping("/{boardReportId}") | ||
private BaseResponse<BoardReportResponse.BoardReportUpdate> 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<BoardReportResponse.BoardReportResign> resignBoardReport( | ||
@AuthMember Member member, | ||
@PathVariable(value = "boardReportId") Long boardReportId) { | ||
|
||
return BaseResponse.onSuccess(boardReportService.resignBoardReport(member, boardReportId)); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/main/java/com/server/capple/domain/boardReport/dto/BoardReportRequest.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.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 boardId; | ||
BoardReportType boardReportType; | ||
} | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class BoardReportUpdate { | ||
BoardReportType boardReportType; | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
src/main/java/com/server/capple/domain/boardReport/dto/BoardReportResponse.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.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 | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class BoardReportCreate { | ||
Long boardReportId; | ||
} | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class BoardReportsGet { | ||
List<BoardReportInfo> boardReportInfos; | ||
} | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class BoardReportInfo { | ||
Long boardReportId; | ||
Long reporterId; | ||
Long boardId; | ||
BoardReportType boardReportType; | ||
} | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class BoardReportUpdate { | ||
Long boardReportId; | ||
} | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public static class BoardReportResign { | ||
Long boardReportId; | ||
} | ||
|
||
} |
37 changes: 37 additions & 0 deletions
37
src/main/java/com/server/capple/domain/boardReport/entity/BoardReport.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,37 @@ | ||
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", nullable = false) | ||
private Board board; | ||
|
||
@Column(nullable = false) | ||
private BoardReportType boardReportType; | ||
|
||
public void updateBoardReportType(BoardReportType boardReportType) { | ||
this.boardReportType = boardReportType; | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/server/capple/domain/boardReport/entity/BoardReportType.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,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; | ||
} |
55 changes: 55 additions & 0 deletions
55
src/main/java/com/server/capple/domain/boardReport/mapper/BoardReportMapper.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,55 @@ | ||
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; | ||
|
||
import java.util.List; | ||
|
||
@Component | ||
public class BoardReportMapper { | ||
|
||
public BoardReport toBoardReport(Member member, Board board, BoardReportType boardReportType) { | ||
return BoardReport.builder() | ||
.member(member) | ||
.board(board) | ||
.boardReportType(boardReportType) | ||
.build(); | ||
} | ||
|
||
public BoardReportResponse.BoardReportCreate toBoardReportCreate(BoardReport boardReport) { | ||
return BoardReportResponse.BoardReportCreate.builder() | ||
.boardReportId(boardReport.getId()) | ||
.build(); | ||
} | ||
|
||
public BoardReportResponse.BoardReportsGet toBoardReportsGet(List<BoardReportResponse.BoardReportInfo> 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.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(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/com/server/capple/domain/boardReport/repository/BoardReportRepository.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.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.List; | ||
import java.util.Optional; | ||
|
||
public interface BoardReportRepository extends JpaRepository<BoardReport, Long> { | ||
|
||
Boolean existsByMemberAndBoard(Member member, Board board); | ||
|
||
Optional<BoardReport> findByMemberAndBoard(Member member, Board board); | ||
|
||
List<BoardReport> findByMember(Member member); | ||
} |
24 changes: 24 additions & 0 deletions
24
src/main/java/com/server/capple/domain/boardReport/service/BoardReportService.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,24 @@ | ||
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.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); | ||
|
||
Boolean isReporter(Long reporterId, Long memberId); | ||
|
||
BoardReportResponse.BoardReportsGet getMyBoardReports(Member member); | ||
|
||
BoardReportResponse.BoardReportCreate createBoardReport(Member member, Long boardId, BoardReportType boardReportType); | ||
|
||
BoardReportResponse.BoardReportUpdate updateBoardReport(Member member, Long reportId, BoardReportType boardReportType); | ||
|
||
BoardReportResponse.BoardReportResign resignBoardReport(Member member, Long boardReportId); | ||
} |
Oops, something went wrong.