Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ feat: add content search #499

Draft
wants to merge 1 commit into
base: dev
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@ public class ItemController {
@GetMapping
public ResponseEntity<?> getAllItems(
@PageableDefault(size = 20, page = 0, sort = "createdAt",
direction = Sort.Direction.DESC) Pageable pageable
direction = Sort.Direction.DESC) Pageable pageable,
@RequestParam(value = "keyword", required = false) String keyword
) {
var response = itemService.getAllItems(pageable);
var response = itemService.getAllItems(pageable, keyword);
return ResponseDto.ok(response);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ public interface ItemRepository extends JpaRepository<Item, Long> {
countQuery = "select count(i) from Item i")
Page<Item> findAll(Pageable pageable);


@Query(value = "select i from Item i join fetch i.song s join fetch s.album a join fetch a.artist ar join fetch i.itemLocation il join fetch il.villageArea va join fetch i.user u where i.content like %:keyword% ",
countQuery = "select count(i) from Item i where i.content like %:keyword%")
Page<Item> findAll(Pageable pageable, String keyword);

@Query(value = "select i from Item i join fetch i.song s join fetch s.album a join fetch a.artist ar join fetch i.itemLocation il join fetch il.villageArea va join fetch i.user u where u = :user order by i.createdAt desc ")
List<Item> findByUser(User user);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,38 +26,75 @@ public class ItemService {
private final ItemRepository itemRepository;

@Transactional(readOnly = true)
public PageResponseDto<?> getAllItems(Pageable pageable) {
Page<Item> itemPage = itemRepository.findAll(pageable);
PageMetaData pageMetaData = new PageMetaData(
itemPage.getNumber(),
itemPage.getSize(),
(int) itemPage.getTotalElements(),
itemPage.getTotalPages()
);
List<ItemResponseDto> items = itemPage.getContent()
.stream()
.map((item) ->
{
String itemLocationName;
try {
itemLocationName = item.getItemLocation().getVillageArea().getVillageName();
} catch (NullPointerException e){
itemLocationName = "";
}

return ItemResponseDto.builder()
.id(item.getId())
.songName(item.getSong().getName())
.artistName(item.getSong().getAlbum().getArtist().getName())
.dropLocationName(itemLocationName)
.userNickname(item.getUser().getNickname())
.comment(item.getContent())
.createdAt(item.getCreatedAt())
.build();
}).toList();


return new PageResponseDto<>(items, pageMetaData);
public PageResponseDto<?> getAllItems(Pageable pageable, String keyword) {
if (keyword == null) {
Page<Item> itemPage = itemRepository.findAll(pageable);
PageMetaData pageMetaData = new PageMetaData(
itemPage.getNumber(),
itemPage.getSize(),
(int) itemPage.getTotalElements(),
itemPage.getTotalPages()
);
List<ItemResponseDto> items = itemPage.getContent()
.stream()
.map((item) ->
{
String itemLocationName;
try {
itemLocationName = item.getItemLocation().getVillageArea().getVillageName();
} catch (NullPointerException e) {
itemLocationName = "";
}

return ItemResponseDto.builder()
.id(item.getId())
.songName(item.getSong().getName())
.artistName(item.getSong().getAlbum().getArtist().getName())
.dropLocationName(itemLocationName)
.userNickname(item.getUser().getNickname())
.comment(item.getContent())
.createdAt(item.getCreatedAt())
.build();
}).toList();


return new PageResponseDto<>(items, pageMetaData);

} else {
Page<Item> itemPage = itemRepository.findAll(pageable, keyword);
PageMetaData pageMetaData = new PageMetaData(
itemPage.getNumber(),
itemPage.getSize(),
(int) itemPage.getTotalElements(),
itemPage.getTotalPages()
);
List<ItemResponseDto> items = itemPage.getContent()
.stream()
.map((item) ->
{
String itemLocationName;
try {
itemLocationName = item.getItemLocation().getVillageArea().getVillageName();
} catch (NullPointerException e) {
itemLocationName = "";
}

return ItemResponseDto.builder()
.id(item.getId())
.songName(item.getSong().getName())
.artistName(item.getSong().getAlbum().getArtist().getName())
.dropLocationName(itemLocationName)
.userNickname(item.getUser().getNickname())
.comment(item.getContent())
.createdAt(item.getCreatedAt())
.build();
}).toList();


return new PageResponseDto<>(items, pageMetaData);

}

}

@Transactional
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,15 @@ const ItemApi = {
},
deleteItem: (itemId) => {
return axiosAuthInstance.delete('/items/' + itemId)
},
getItemsByKeyword : (page, size, keyword) => {
return axiosAuthInstance.get('/items', {
params: {
page: page,
size: size,
keyword: keyword
}
})
}
}
export default ItemApi;
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
import React, {useEffect, useState} from "react"
import {Button, Drawer, Modal, Table} from 'antd';
import {Button, Col, Drawer, Modal, Row, Table} from 'antd';
import BasicLayout from "../../layout/BasicLayout";
import ItemApi from "../../api/domain/item/ItemApi";
import ItemDetailPage from "../../components/items/ItemDetailPage";
import {InitialPagination} from "../../constant/PaginationConstant";
import Search from "antd/es/input/Search";


function ItemListPage() {
const [data, setData] = useState([]);
Expand All @@ -23,6 +25,12 @@ function ItemListPage() {
};


const onSearch = async (value) => {
const response = await ItemApi.getItemsByKeyword(tableParams.pagination.current - 1, tableParams.pagination.pageSize, value);
setData(response.data['data']);
}


const showDrawer = (itemId) => {
setClickedItemId(itemId)
setOpenDrawer(true);
Expand Down Expand Up @@ -127,6 +135,18 @@ function ItemListPage() {
<BasicLayout>
<h3 style={{marginBottom: '10px'}}>아이템 전체 조회</h3>
<p style={{color: 'gray'}}>아이템을 전체 조회할 수 있습니다.</p>


<Row>
<Col span={14}>
</Col>

<Col span={10}>
<Search placeholder="검색어를 입력하세요" onSearch={onSearch} enterButton/>
</Col>

</Row>

<Table
style={{marginTop: '20px'}}
columns={columns}
Expand Down