From a11ed1c3be1ad6e9c292150cdec7525827ef0bd4 Mon Sep 17 00:00:00 2001 From: Jung Seonghun <80201773+seonghun-dev@users.noreply.github.com> Date: Sat, 20 Jan 2024 17:14:29 +0900 Subject: [PATCH] :sparkles: feat: add admin banned word create, delete --- .../item/controller/BannedWordController.java | 21 ++++++-- .../item/dto/BannedWordRequestDto.java | 12 +++++ .../item/service/BannedWordService.java | 14 ++++++ .../src/api/domain/item/BannedWordApi.js | 8 +++ .../src/components/items/BannedWordPage.js | 49 ++++++++++++++++++- .../depromeet/common/entity/BannedWord.java | 4 ++ 6 files changed, 103 insertions(+), 5 deletions(-) create mode 100644 backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/dto/BannedWordRequestDto.java 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 index c549ac38..562f6ec8 100644 --- 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 @@ -1,6 +1,7 @@ package com.depromeet.domains.item.controller; +import com.depromeet.domains.item.dto.BannedWordRequestDto; import com.depromeet.domains.item.service.BannedWordService; import com.depromeet.domains.user.dto.ResponseDto; import lombok.RequiredArgsConstructor; @@ -8,9 +9,7 @@ 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; +import org.springframework.web.bind.annotation.*; @RestController @RequiredArgsConstructor @@ -27,4 +26,20 @@ public ResponseEntity> getBannedWords( return ResponseDto.ok(result); } + @PostMapping + public ResponseEntity> createBannedWord( + @RequestBody BannedWordRequestDto bannedWordRequestDto + ) { + var result = bannedWordService.createBannedWord(bannedWordRequestDto.getWord()); + return ResponseDto.ok(result); + } + + @DeleteMapping("/{bannedWordId}") + public ResponseEntity> deleteBannedWord( + @PathVariable Long bannedWordId + ) { + bannedWordService.deleteBannedWord(bannedWordId); + return ResponseDto.noContent(); + } + } diff --git a/backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/dto/BannedWordRequestDto.java b/backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/dto/BannedWordRequestDto.java new file mode 100644 index 00000000..92184157 --- /dev/null +++ b/backend/streetdrop-admin/streetdrop-admin-server/src/main/java/com/depromeet/domains/item/dto/BannedWordRequestDto.java @@ -0,0 +1,12 @@ +package com.depromeet.domains.item.dto; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; + +@AllArgsConstructor +@NoArgsConstructor +@Getter +public class BannedWordRequestDto { + private String word; +} 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 index 6e995dd2..c0d4ecce 100644 --- 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 @@ -1,6 +1,7 @@ package com.depromeet.domains.item.service; import com.depromeet.common.dto.PageMetaData; +import com.depromeet.common.entity.BannedWord; import com.depromeet.domains.item.dto.BannedWordAllResponseDto; import com.depromeet.domains.item.dto.BannedWordResponseDto; import com.depromeet.domains.item.repository.BannedWordRepository; @@ -36,4 +37,17 @@ public BannedWordAllResponseDto getBannedWords(Pageable pageable) { return new BannedWordAllResponseDto(bannedWords, pageMetaData); } + + public BannedWordResponseDto createBannedWord(String word) { + BannedWord bannedWord = new BannedWord(word); + var bannedWordResult = bannedWordRepository.save(bannedWord); + return BannedWordResponseDto.builder() + .id(bannedWordResult.getId()) + .word(bannedWordResult.getWord()) + .build(); + } + + public void deleteBannedWord(Long bannedWordId) { + bannedWordRepository.deleteById(bannedWordId); + } } 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 index 1ccadb5c..ba62ff3a 100644 --- 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 @@ -10,6 +10,14 @@ const BannedWordApi = { } }) }, + createBannedWord: (bannedWord) => { + return axiosAuthInstance.post('/banned-words', { + word: bannedWord + }) + }, + deleteBannedWord: (id) => { + return axiosAuthInstance.delete('/banned-words/' + id) + } } 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 index 77d1ec6c..20e2dd70 100644 --- a/backend/streetdrop-admin/streetdrop-admin-web/src/components/items/BannedWordPage.js +++ b/backend/streetdrop-admin/streetdrop-admin-web/src/components/items/BannedWordPage.js @@ -1,10 +1,33 @@ import React, {useEffect, useState} from "react"; -import {Table} from "antd"; +import {Button, Input, Modal, Table} from "antd"; import BasicLayout from "../../layout/BasicLayout"; import BannedWordApi from "../../api/domain/item/BannedWordApi"; function BannedWordPage() { const [data, setData] = useState([]); + const [inputValue, setInputValue] = useState(''); + const [isModalOpen, setIsModalOpen] = useState(false); + + const showModal = () => { + setIsModalOpen(true); + }; + + const createBannedWord = async () => { + if (inputValue !== '') { + BannedWordApi.createBannedWord(inputValue); + await fetchData(); + } + setIsModalOpen(false); + } + + + const deleteBannedWord = async (id) => { + await BannedWordApi.deleteBannedWord(id); + Modal.success({ + content: '삭제되었습니다.', + }); + await fetchData(); + } const [tableParams, setTableParams] = useState({ pagination: { @@ -15,7 +38,7 @@ function BannedWordPage() { useEffect(() => { fetchData(); - }, [JSON.stringify(tableParams)]); + }, [JSON.stringify(tableParams), isModalOpen, inputValue]); const fetchData = async () => { @@ -40,6 +63,15 @@ function BannedWordPage() { { title: '금칙어', dataIndex: 'word', + }, + { + title: '삭제', + dataIndex: 'id', + render: (id) => ( + deleteBannedWord(id)}> + 삭제 + + ), } ]; @@ -62,6 +94,19 @@ function BannedWordPage() { 금칙어 관리 아이템 콘텐츠의 금칙어를 관리할 수 있습니다. + 금칙어 추가 + createBannedWord()} + onCancel={() => setIsModalOpen(false)} + > + setInputValue(e.target.value)} + /> +
아이템 콘텐츠의 금칙어를 관리할 수 있습니다.