From 90afc5c601f66c5cdc2540ae1b2b5dd9df6b64f9 Mon Sep 17 00:00:00 2001 From: Jung Seonghun <80201773+seonghun-dev@users.noreply.github.com> Date: Sat, 20 Jan 2024 17:11:06 +0900 Subject: [PATCH] :sparkles: feat: add admin banned word view (#426) --- .../item/controller/BannedWordController.java | 30 +++++++ .../item/dto/BannedWordAllResponseDto.java | 16 ++++ .../item/dto/BannedWordResponseDto.java | 17 ++++ .../item/repository/BannedWordRepository.java | 10 +++ .../item/service/BannedWordService.java | 39 ++++++++++ .../streetdrop-admin-web/src/App.js | 2 + .../src/api/domain/item/BannedWordApi.js | 15 ++++ .../src/components/items/BannedWordPage.js | 78 +++++++++++++++++++ .../src/layout/common/Menu.js | 3 + 9 files changed, 210 insertions(+) create mode 100644 backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/controller/BannedWordController.java create mode 100644 backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/dto/BannedWordAllResponseDto.java create mode 100644 backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/dto/BannedWordResponseDto.java create mode 100644 backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/repository/BannedWordRepository.java create mode 100644 backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/service/BannedWordService.java create mode 100644 backend/streetdrop-admin/streetdrop-admin-web/src/api/domain/item/BannedWordApi.js create mode 100644 backend/streetdrop-admin/streetdrop-admin-web/src/components/items/BannedWordPage.js diff --git a/backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/controller/BannedWordController.java b/backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/controller/BannedWordController.java new file mode 100644 index 00000000..c549ac38 --- /dev/null +++ b/backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/controller/BannedWordController.java @@ -0,0 +1,30 @@ +package com.depromeet.domains.item.controller; + + +import com.depromeet.domains.item.service.BannedWordService; +import com.depromeet.domains.user.dto.ResponseDto; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; +import org.springframework.data.domain.Sort; +import org.springframework.data.web.PageableDefault; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.GetMapping; +import org.springframework.web.bind.annotation.RequestMapping; +import org.springframework.web.bind.annotation.RestController; + +@RestController +@RequiredArgsConstructor +@RequestMapping("/banned-words") +public class BannedWordController { + private final BannedWordService bannedWordService; + + @GetMapping + public ResponseEntity getBannedWords( + @PageableDefault(size = 20, page = 0, sort = "id", + direction = Sort.Direction.DESC) Pageable pageable + ) { + var result = bannedWordService.getBannedWords(pageable); + return ResponseDto.ok(result); + } + +} diff --git a/backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/dto/BannedWordAllResponseDto.java b/backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/dto/BannedWordAllResponseDto.java new file mode 100644 index 00000000..9ec10b28 --- /dev/null +++ b/backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/dto/BannedWordAllResponseDto.java @@ -0,0 +1,16 @@ +package com.depromeet.domains.item.dto; + +import com.depromeet.common.dto.PageMetaData; +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +import java.util.List; + +@AllArgsConstructor +@NoArgsConstructor +@Getter +public class BannedWordAllResponseDto { + List data; + PageMetaData meta; +} diff --git a/backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/dto/BannedWordResponseDto.java b/backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/dto/BannedWordResponseDto.java new file mode 100644 index 00000000..90891b58 --- /dev/null +++ b/backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/dto/BannedWordResponseDto.java @@ -0,0 +1,17 @@ +package com.depromeet.domains.item.dto; + +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@AllArgsConstructor +@NoArgsConstructor +@Builder +@Getter +public class BannedWordResponseDto { + + private Long id; + private String word; + +} diff --git a/backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/repository/BannedWordRepository.java b/backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/repository/BannedWordRepository.java new file mode 100644 index 00000000..cf05900e --- /dev/null +++ b/backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/repository/BannedWordRepository.java @@ -0,0 +1,10 @@ +package com.depromeet.domains.item.repository; + +import com.depromeet.common.entity.BannedWord; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; + +public interface BannedWordRepository extends JpaRepository { + Page findAll(Pageable pageable); +} diff --git a/backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/service/BannedWordService.java b/backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/service/BannedWordService.java new file mode 100644 index 00000000..6e995dd2 --- /dev/null +++ b/backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/service/BannedWordService.java @@ -0,0 +1,39 @@ +package com.depromeet.domains.item.service; + +import com.depromeet.common.dto.PageMetaData; +import com.depromeet.domains.item.dto.BannedWordAllResponseDto; +import com.depromeet.domains.item.dto.BannedWordResponseDto; +import com.depromeet.domains.item.repository.BannedWordRepository; +import lombok.RequiredArgsConstructor; +import org.springframework.data.domain.Pageable; +import org.springframework.stereotype.Service; + +import java.util.List; + +@Service +@RequiredArgsConstructor +public class BannedWordService { + + private final BannedWordRepository bannedWordRepository; + + public BannedWordAllResponseDto getBannedWords(Pageable pageable) { + var bannedWord = bannedWordRepository.findAll(pageable); + PageMetaData pageMetaData = new PageMetaData( + bannedWord.getNumber(), + bannedWord.getSize(), + (int) bannedWord.getTotalElements(), + bannedWord.getTotalPages() + ); + + List bannedWords = bannedWord.getContent() + .stream() + .map((word) -> { + return BannedWordResponseDto.builder() + .id(word.getId()) + .word(word.getWord()) + .build(); + }).toList(); + + return new BannedWordAllResponseDto(bannedWords, pageMetaData); + } +} diff --git a/backend/streetdrop-admin/streetdrop-admin-web/src/App.js b/backend/streetdrop-admin/streetdrop-admin-web/src/App.js index 6e88a93b..b1d4e227 100644 --- a/backend/streetdrop-admin/streetdrop-admin-web/src/App.js +++ b/backend/streetdrop-admin/streetdrop-admin-web/src/App.js @@ -19,6 +19,7 @@ import MemberListPage from "./components/member/MemberListPage"; import MemberLoginLogPage from "./components/member/MemberLoginLogPage"; import MemberSecuritySettingPage from "./components/member/MemberSecuritySettingPage"; import ItemReportPage from "./components/items/ItemReportPage"; +import BannedWordPage from "./components/items/BannedWordPage"; const App = () => { return ( @@ -30,6 +31,7 @@ const App = () => { }/> }/> }/> + }/> }/> }/> }/> diff --git a/backend/streetdrop-admin/streetdrop-admin-web/src/api/domain/item/BannedWordApi.js b/backend/streetdrop-admin/streetdrop-admin-web/src/api/domain/item/BannedWordApi.js new file mode 100644 index 00000000..1ccadb5c --- /dev/null +++ b/backend/streetdrop-admin/streetdrop-admin-web/src/api/domain/item/BannedWordApi.js @@ -0,0 +1,15 @@ +import {axiosAuthInstance} from "../../AxiosInstance"; + + +const BannedWordApi = { + getBannedWords: (page, size) => { + return axiosAuthInstance.get('/banned-words', { + params: { + page: page, + size: size + } + }) + }, +} + +export default BannedWordApi; \ No newline at end of file diff --git a/backend/streetdrop-admin/streetdrop-admin-web/src/components/items/BannedWordPage.js b/backend/streetdrop-admin/streetdrop-admin-web/src/components/items/BannedWordPage.js new file mode 100644 index 00000000..77d1ec6c --- /dev/null +++ b/backend/streetdrop-admin/streetdrop-admin-web/src/components/items/BannedWordPage.js @@ -0,0 +1,78 @@ +import React, {useEffect, useState} from "react"; +import {Table} from "antd"; +import BasicLayout from "../../layout/BasicLayout"; +import BannedWordApi from "../../api/domain/item/BannedWordApi"; + +function BannedWordPage() { + const [data, setData] = useState([]); + + const [tableParams, setTableParams] = useState({ + pagination: { + current: 1, + pageSize: 30 + }, + }); + + useEffect(() => { + fetchData(); + }, [JSON.stringify(tableParams)]); + + + const fetchData = async () => { + const response = await BannedWordApi.getBannedWords(tableParams.pagination.current - 1, tableParams.pagination.pageSize); + setData(response.data['data']); + setTableParams({ + ...tableParams, + pagination: { + ...tableParams.pagination, + total: response.data['meta']['totalElements'], + }, + }); + } + + + const columns = [ + { + title: 'ID', + dataIndex: 'id', + key: 'id', + }, + { + title: '금칙어', + dataIndex: 'word', + } + ]; + + + const handleTableChange = ( + pagination, + ) => { + setTableParams({ + pagination, + }); + + if (pagination.pageSize !== tableParams.pagination?.pageSize) { + setData([]); + } + }; + + + return ( + <> + +

금칙어 관리

+

아이템 콘텐츠의 금칙어를 관리할 수 있습니다.

+ record.id} + pagination={tableParams.pagination} + dataSource={data} + onChange={handleTableChange} + /> + + + ) +} + +export default BannedWordPage; \ No newline at end of file diff --git a/backend/streetdrop-admin/streetdrop-admin-web/src/layout/common/Menu.js b/backend/streetdrop-admin/streetdrop-admin-web/src/layout/common/Menu.js index aa0f834a..3938a721 100644 --- a/backend/streetdrop-admin/streetdrop-admin-web/src/layout/common/Menu.js +++ b/backend/streetdrop-admin/streetdrop-admin-web/src/layout/common/Menu.js @@ -32,6 +32,9 @@ const MenuComponent = () => { • 아이템 신고 + • 금칙어 관리 + + • 음악 검색어 추천