Skip to content

Commit

Permalink
✨ feat: add admin banned word create, delete (#427)
Browse files Browse the repository at this point in the history
  • Loading branch information
seonghun-dev committed Jan 22, 2024
1 parent 90afc5c commit b37949e
Show file tree
Hide file tree
Showing 6 changed files with 103 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,16 +1,15 @@
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;
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;
import org.springframework.web.bind.annotation.*;

@RestController
@RequiredArgsConstructor
Expand All @@ -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();
}

}
Original file line number Diff line number Diff line change
@@ -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;
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Original file line number Diff line number Diff line change
@@ -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: {
Expand All @@ -15,7 +38,7 @@ function BannedWordPage() {

useEffect(() => {
fetchData();
}, [JSON.stringify(tableParams)]);
}, [JSON.stringify(tableParams), isModalOpen, inputValue]);


const fetchData = async () => {
Expand All @@ -40,6 +63,15 @@ function BannedWordPage() {
{
title: '금칙어',
dataIndex: 'word',
},
{
title: '삭제',
dataIndex: 'id',
render: (id) => (
<Button onClick={() => deleteBannedWord(id)}>
삭제
</Button>
),
}
];

Expand All @@ -62,6 +94,19 @@ function BannedWordPage() {
<BasicLayout>
<h3 style={{marginBottom: '10px'}}>금칙어 관리</h3>
<p style={{color: 'gray'}}>아이템 콘텐츠의 금칙어를 관리할 수 있습니다.</p>
<Button onClick={showModal} type="primary">금칙어 추가</Button>
<Modal
title="금칙어 추가"
open={isModalOpen}
onOk={() => createBannedWord()}
onCancel={() => setIsModalOpen(false)}
>
<Input
placeholder="금칙어를 입력하세요"
value={inputValue}
onChange={(e) => setInputValue(e.target.value)}
/>
</Modal>
<Table
style={{marginTop: '20px'}}
columns={columns}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,4 +20,8 @@ public class BannedWord {

@Column(length = 20, nullable = false)
private String word;

public BannedWord(String word) {
this.word = word;
}
}

0 comments on commit b37949e

Please sign in to comment.