Skip to content

Commit

Permalink
Merge pull request #144 from Team-Capple/feat/#142/boardReport
Browse files Browse the repository at this point in the history
[FEAT] 신고함 기능 구현(게시판)
  • Loading branch information
tnals2384 authored Sep 14, 2024
2 parents 5c09631 + 6261c16 commit 0cda7ef
Show file tree
Hide file tree
Showing 12 changed files with 437 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -58,6 +58,7 @@ public SecurityFilterChain filterChain(HttpSecurity http) throws Exception {
.requestMatchers("/reports", "/reports/**").authenticated()
.requestMatchers("/boards", "/boards/**").authenticated()
.requestMatchers("/boardComments", "/boardComments/**").authenticated()
.requestMatchers("/boardReports", "boardReports/**").authenticated()
.requestMatchers("/notifications", "/notifications/**").authenticated()
.requestMatchers("/dummy","/dummy/**").hasRole(Role.ROLE_ADMIN.getName())
.anyRequest().denyAll());
Expand Down
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));
}
}
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;
}
}
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;
}

}
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;
}
}
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;
}
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();
}
}
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);
}
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);
}
Loading

0 comments on commit 0cda7ef

Please sign in to comment.