Skip to content
This repository has been archived by the owner on Dec 16, 2024. It is now read-only.

Commit

Permalink
feat: add serach service on roster page
Browse files Browse the repository at this point in the history
  • Loading branch information
jspark2000 committed Apr 9, 2024
1 parent 7ceed2a commit 563120e
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 7 deletions.
10 changes: 8 additions & 2 deletions backend/app/src/roster/roster.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -29,10 +29,16 @@ export class RosterController {
async getRosters(
@Query('page', ParseIntPipe) page: number,
@Query('limit', new ParseIntPipe({ optional: true })) limit?: number,
@Query('filter') filter?: string
@Query('filter') filter?: string,
@Query('searchTerm') searchTerm?: string
): Promise<{ total: number; rosters: Roster[] }> {
try {
return await this.rosterService.getRosters(page, limit, filter)
return await this.rosterService.getRosters(
page,
limit,
searchTerm,
filter
)
} catch (error) {
BusinessExceptionHandler(error)
}
Expand Down
11 changes: 9 additions & 2 deletions backend/app/src/roster/roster.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,14 +71,18 @@ export class RosterService {
async getRosters(
page: number,
limit = 10,
searchTerm = '',
filter?: string
): Promise<{ total: number; rosters: Roster[] }> {
try {
const status = this.checkRosterStatus(filter)

const rosters = await this.prisma.roster.findMany({
where: {
status
status,
name: {
contains: searchTerm
}
},
take: limit,
skip: calculatePaginationOffset(page, limit),
Expand All @@ -100,7 +104,10 @@ export class RosterService {

const total = await this.prisma.roster.count({
where: {
status
status,
name: {
contains: searchTerm
}
}
})

Expand Down
10 changes: 9 additions & 1 deletion frontend/src/app/console/roster/page.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
import Pagination from '@/components/Pagination'
import Search from '@/components/Search'
import { Button } from '@/components/ui/button'
import { getRosters } from '@/lib/actions'
import { calculateTotalPages } from '@/lib/utils'
import { PAGINATION_LIMIT_DEFAULT } from '@/lib/vars'
import { SearchIcon } from 'lucide-react'
import Link from 'next/link'
import RosterListTable from './_components/RosterListTable'

Expand All @@ -11,10 +13,12 @@ export default async function RosterPage({
}: {
searchParams?: {
page?: string
searchTerm?: string
}
}) {
const currentPage = Number(searchParams?.page) || 1
const rosterList = await getRosters(currentPage)
const searchTerm = searchParams?.searchTerm || ''
const rosterList = await getRosters(currentPage, searchTerm)

return (
<main className="mx-auto flex w-full flex-grow flex-col items-center justify-start">
Expand All @@ -25,6 +29,10 @@ export default async function RosterPage({
</Link>
</div>
<div className="flex w-full flex-grow flex-col gap-5 py-4 sm:px-6">
<div className="flex max-w-[340px] items-center space-x-2">
<SearchIcon className="h-6 w-6" />
<Search placeholder="이름 검색" />
</div>
<RosterListTable rosters={rosterList.rosters} />
<Pagination
totalPages={calculateTotalPages(
Expand Down
7 changes: 5 additions & 2 deletions frontend/src/lib/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,12 @@ export const getRoster = async (rosterId: number): Promise<Roster> => {
return await fetcher.get<Roster>(`/rosters/${rosterId}`)
}

export const getRosters = async (page: number): Promise<RosterList> => {
export const getRosters = async (
page: number,
searchTerm: string
): Promise<RosterList> => {
return await fetcher.get<RosterList>(
`/rosters?page=${page}&limit=${PAGINATION_LIMIT_DEFAULT}&filter=Enable`
`/rosters?page=${page}&limit=${PAGINATION_LIMIT_DEFAULT}&filter=Enable&searchTerm=${searchTerm}`
)
}

Expand Down

0 comments on commit 563120e

Please sign in to comment.