-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
✨ feat: add admin banned word view (#426)
- Loading branch information
1 parent
f2a2945
commit 90afc5c
Showing
9 changed files
with
210 additions
and
0 deletions.
There are no files selected for viewing
30 changes: 30 additions & 0 deletions
30
...dmin-server/src/main/java/com/depromeet/domains/item/controller/BannedWordController.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,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); | ||
} | ||
|
||
} |
16 changes: 16 additions & 0 deletions
16
...p-admin-server/src/main/java/com/depromeet/domains/item/dto/BannedWordAllResponseDto.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,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<BannedWordResponseDto> data; | ||
PageMetaData meta; | ||
} |
17 changes: 17 additions & 0 deletions
17
...drop-admin-server/src/main/java/com/depromeet/domains/item/dto/BannedWordResponseDto.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.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; | ||
|
||
} |
10 changes: 10 additions & 0 deletions
10
...dmin-server/src/main/java/com/depromeet/domains/item/repository/BannedWordRepository.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,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<BannedWord, Long> { | ||
Page<BannedWord> findAll(Pageable pageable); | ||
} |
39 changes: 39 additions & 0 deletions
39
...drop-admin-server/src/main/java/com/depromeet/domains/item/service/BannedWordService.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,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<BannedWordResponseDto> bannedWords = bannedWord.getContent() | ||
.stream() | ||
.map((word) -> { | ||
return BannedWordResponseDto.builder() | ||
.id(word.getId()) | ||
.word(word.getWord()) | ||
.build(); | ||
}).toList(); | ||
|
||
return new BannedWordAllResponseDto(bannedWords, pageMetaData); | ||
} | ||
} |
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
15 changes: 15 additions & 0 deletions
15
backend/streetdrop-admin/streetdrop-admin-web/src/api/domain/item/BannedWordApi.js
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,15 @@ | ||
import {axiosAuthInstance} from "../../AxiosInstance"; | ||
|
||
|
||
const BannedWordApi = { | ||
getBannedWords: (page, size) => { | ||
return axiosAuthInstance.get('/banned-words', { | ||
params: { | ||
page: page, | ||
size: size | ||
} | ||
}) | ||
}, | ||
} | ||
|
||
export default BannedWordApi; |
78 changes: 78 additions & 0 deletions
78
backend/streetdrop-admin/streetdrop-admin-web/src/components/items/BannedWordPage.js
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,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 ( | ||
<> | ||
<BasicLayout> | ||
<h3 style={{marginBottom: '10px'}}>금칙어 관리</h3> | ||
<p style={{color: 'gray'}}>아이템 콘텐츠의 금칙어를 관리할 수 있습니다.</p> | ||
<Table | ||
style={{marginTop: '20px'}} | ||
columns={columns} | ||
rowKey={record => record.id} | ||
pagination={tableParams.pagination} | ||
dataSource={data} | ||
onChange={handleTableChange} | ||
/> | ||
</BasicLayout> | ||
</> | ||
) | ||
} | ||
|
||
export default BannedWordPage; |
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