-
Notifications
You must be signed in to change notification settings - Fork 3
feat: add list accounts with pagination #24
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
base: main
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,16 @@ | ||
| import type z from "zod"; | ||
| import { ListAccountSchema } from "@/shared/schemas/ListAccounts"; | ||
| import { createPaginateSchema, InputPageSchema } from "@/shared/utils/paginate"; | ||
|
|
||
| export const ListAccountsContractSchema = { | ||
| input: InputPageSchema, | ||
| output: createPaginateSchema(ListAccountSchema), | ||
| }; | ||
|
|
||
| export type ListAccountsContractInput = z.infer< | ||
| typeof ListAccountsContractSchema.input | ||
| >; | ||
|
|
||
| export type ListAccountsContractOutput = z.infer< | ||
| typeof ListAccountsContractSchema.output | ||
| >; |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| import { inject, injectable } from "tsyringe"; | ||
| import type { AccountsService } from "@/application/services"; | ||
| import type { Pagination } from "@/domain/modules"; | ||
| import { TOKENS } from "@/infra/di/tokens"; | ||
| import type { UseCase } from "@/shared/interfaces/usecase"; | ||
| import type { | ||
| ListAccountsContractInput, | ||
| ListAccountsContractOutput, | ||
| } from "./contract"; | ||
|
|
||
| @injectable() | ||
| export class ListAccountsUseCase | ||
| implements UseCase<ListAccountsContractInput, ListAccountsContractOutput> | ||
| { | ||
| constructor( | ||
| @inject(TOKENS.AccountsService) | ||
| private readonly accountsService: AccountsService, | ||
| @inject(TOKENS.Pagination) private readonly pagination: Pagination, | ||
| ) {} | ||
|
|
||
| async execute( | ||
| input: ListAccountsContractInput, | ||
| ): Promise<ListAccountsContractOutput> { | ||
| const { storeHistory, total } = await this.accountsService.listAccounts({ | ||
| pagination: input, | ||
| }); | ||
|
|
||
| return this.pagination.paginate(storeHistory, { | ||
| page: input.page ?? 1, | ||
| size: input.size ?? 10, | ||
| total, | ||
| }); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -210,6 +210,27 @@ export class AccountRepository { | |
| }; | ||
| } | ||
|
|
||
| async listAccounts(opts?: { pagination: PaginationInput }) { | ||
| const page = opts?.pagination.page ?? 1; | ||
| const size = opts?.pagination.size ?? 10; | ||
|
|
||
| const [storeHistory, total] = await Promise.all([ | ||
| this.prisma.accounts.findMany({ | ||
| orderBy: { | ||
| name: "desc", | ||
| }, | ||
| skip: (page - 1) * size, | ||
| take: size, | ||
| }), | ||
| this.prisma.accounts.count(), | ||
| ]); | ||
|
|
||
| return { | ||
| storeHistory, | ||
|
||
| total, | ||
| }; | ||
| } | ||
|
|
||
| async details(email: string) { | ||
| return this.prisma.accounts.findFirst({ | ||
| where: { | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { base } from "@/infra/rpc/base"; | ||
| import { listAccountsRouter } from "./list"; | ||
|
|
||
| export const adminAccountsRouter = base.prefix("/accounts").router({ | ||
| list: listAccountsRouter, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,22 @@ | ||
| import { ListAccountsContractSchema } from "@/application/usecases/account/listAccounts/contract"; | ||
| import { isPermissionedProcedure } from "@/presentation/procedures/isPermissioned"; | ||
|
|
||
| export const listAccountsRouter = isPermissionedProcedure | ||
| .meta({ | ||
| permission: { | ||
| type: "GAME_MASTER", | ||
| }, | ||
| }) | ||
| .route({ | ||
| method: "GET", | ||
| path: "/list", | ||
| summary: "List Accounts", | ||
| successStatus: 200, | ||
| description: | ||
| "Retrieves a list of accounts registered on the server. Only GAME_MASTER and ADMIN users are allowed to perform this action", | ||
| }) | ||
| .input(ListAccountsContractSchema.input) | ||
| .output(ListAccountsContractSchema.output) | ||
| .handler(async ({ context, input }) => { | ||
| return await context.usecases.account.listAccounts.execute(input); | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,6 @@ | ||
| import { base } from "@/infra/rpc/base"; | ||
| import { adminAccountsRouter } from "./accounts"; | ||
|
|
||
| export const adminRouter = base.prefix("/admin").tag("Admin").router({ | ||
| accounts: adminAccountsRouter, | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,8 @@ | ||
| import z from "zod"; | ||
|
|
||
| export const ListAccountSchema = z.object({ | ||
| id: z.number(), | ||
| name: z.string().nullable(), | ||
| email: z.email(), | ||
| type: z.number(), | ||
| }); |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,5 @@ | ||
| VITE_SHOW_DEVTOOLS=true | ||
|
|
||
| # ==== RPC ==== # | ||
| VITE_MIFORGE_RPC_URL="http://localhost:4000" | ||
| VITE_MIFORGE_RPC_PATH="/v1/rpc" |
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
| @@ -1,20 +1,33 @@ | ||||||
| import type { LinkProps } from "@tanstack/react-router"; | ||||||
| import { MenuBox } from "@/components/Box/Menu"; | ||||||
| import { MenuItem } from "./Item"; | ||||||
|
|
||||||
| export const Menu = () => { | ||||||
| export const Icons = { | ||||||
| management: "/assets/icons/32/loremaster_doll.gif", | ||||||
| news: "/assets/icons/32/news-menu.gif", | ||||||
| sphere: "/assets/icons/32/armillary_sphere.gif", | ||||||
| munster: "/assets/icons/32/baby_munster.gif", | ||||||
| }; | ||||||
|
|
||||||
| interface MenuProps { | ||||||
| items: Array<{ | ||||||
| label: string; | ||||||
| icon: keyof typeof Icons; | ||||||
| menus: Array<{ | ||||||
| label: string; | ||||||
| to: LinkProps["to"]; | ||||||
| hot?: boolean; | ||||||
| }>; | ||||||
| }>; | ||||||
| } | ||||||
|
|
||||||
| export const Menu = ({ items }: MenuProps) => { | ||||||
| return ( | ||||||
| <div className="flex"> | ||||||
| <MenuBox> | ||||||
| <MenuItem | ||||||
| label="News" | ||||||
| icon="news" | ||||||
| menus={[{ label: "Latest News", to: "/terms" }]} | ||||||
| /> | ||||||
| <MenuItem | ||||||
| label="Sphere" | ||||||
| icon="sphere" | ||||||
| menus={[{ label: "Updates", to: "/", hot: true }]} | ||||||
| /> | ||||||
| {items.map((item) => ( | ||||||
| <MenuItem label={item.label} icon={item.icon} menus={item.menus} /> | ||||||
|
Check warning on line 29 in apps/web/src/components/Menu/index.tsx
|
||||||
|
||||||
| <MenuItem label={item.label} icon={item.icon} menus={item.menus} /> | |
| <MenuItem key={item.label} label={item.label} icon={item.icon} menus={item.menus} /> |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The variable name
storeHistoryis misleading and inconsistent with the function's purpose. This method lists accounts, not store history. Rename toaccountsfor clarity.