-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
major refactoring to improve conventions
- Loading branch information
1 parent
7206179
commit f22959b
Showing
24 changed files
with
174 additions
and
163 deletions.
There are no files selected for viewing
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
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
4 changes: 2 additions & 2 deletions
4
.../dashboard/_actions/delete-item-action.ts → .../dashboard/_actions/delete-item.action.ts
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
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
5 changes: 3 additions & 2 deletions
5
.../dashboard/_actions/mark-as-low-action.ts → .../dashboard/_actions/mark-as-low.action.ts
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
5 changes: 3 additions & 2 deletions
5
...ashboard/_actions/unmark-as-low-action.ts → ...ashboard/_actions/unmark-as-low.action.ts
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
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
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
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
This file was deleted.
Oops, something went wrong.
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,14 @@ | ||
import "server-only"; | ||
|
||
import { db } from "@/db"; | ||
import { items } from "@/db/schema"; | ||
|
||
export type CreateItemDto = { | ||
name: string; | ||
userId: string; | ||
quantity: number; | ||
}; | ||
|
||
export async function createItem(item: CreateItemDto): Promise<void> { | ||
await db.insert(items).values(item); | ||
} |
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 @@ | ||
import "server-only"; | ||
|
||
import { db } from "@/db"; | ||
import { items } from "@/db/schema"; | ||
import { eq } from "drizzle-orm"; | ||
import { ItemId } from "./get-item.persistence"; | ||
|
||
export async function deleteItem(itemId: ItemId): Promise<void> { | ||
await db.delete(items).where(eq(items.id, itemId)); | ||
} |
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,37 @@ | ||
import "server-only"; | ||
|
||
import { db } from "@/db"; | ||
import { Item, items } from "@/db/schema"; | ||
import { eq } from "drizzle-orm"; | ||
|
||
export type ItemId = number; | ||
|
||
export type ItemDto = { | ||
id: number; | ||
name: string; | ||
quantity: number; | ||
userId: string; | ||
isLow: boolean; | ||
}; | ||
|
||
export function toDtoMapper(item: Item) { | ||
return { | ||
id: item.id, | ||
name: item.name, | ||
quantity: item.quantity, | ||
userId: item.userId, | ||
isLow: item.isLow, | ||
}; | ||
} | ||
|
||
export async function getItem(itemId: number): Promise<ItemDto> { | ||
const foundItem = await db.query.items.findFirst({ | ||
where: eq(items.id, itemId), | ||
}); | ||
|
||
if (!foundItem) { | ||
throw new Error("could not find item"); | ||
} | ||
|
||
return toDtoMapper(foundItem); | ||
} |
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,21 @@ | ||
import "server-only"; | ||
|
||
import { db } from "@/db"; | ||
import { Item, items } from "@/db/schema"; | ||
import { eq, and } from "drizzle-orm"; | ||
import { ItemDto, toDtoMapper } from "./get-item.persistence"; | ||
|
||
export async function getUserItemByName( | ||
userId: string, | ||
name: string | ||
): Promise<ItemDto | undefined> { | ||
const foundItem = await db.query.items.findFirst({ | ||
where: and(eq(items.userId, userId), eq(items.name, name)), | ||
}); | ||
|
||
if (!foundItem) { | ||
return undefined; | ||
} | ||
|
||
return toDtoMapper(foundItem); | ||
} |
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 @@ | ||
import "server-only"; | ||
|
||
import { db } from "@/db"; | ||
import { ItemDto, toDtoMapper } from "./get-item.persistence"; | ||
|
||
export async function getItems(): Promise<ItemDto[]> { | ||
const items = await db.query.items.findMany(); | ||
|
||
return items.map(toDtoMapper); | ||
} |
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 @@ | ||
import "server-only"; | ||
|
||
import { db } from "@/db"; | ||
import { items } from "@/db/schema"; | ||
import { eq } from "drizzle-orm"; | ||
import { ItemDto } from "./get-item.persistence"; | ||
|
||
export async function updateItem(item: ItemDto): Promise<void> { | ||
await db.update(items).set(item).where(eq(items.id, item.id)); | ||
} |
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
10 changes: 2 additions & 8 deletions
10
...se-cases/items/decrement-item-use-case.ts → ...se-cases/items/decrement-item.use-case.ts
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
3 changes: 2 additions & 1 deletion
3
src/use-cases/items/delete-item-use-case.ts → src/use-cases/items/delete-item.use-case.ts
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
10 changes: 2 additions & 8 deletions
10
...se-cases/items/increment-item-use-case.ts → ...se-cases/items/increment-item.use-case.ts
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
9 changes: 2 additions & 7 deletions
9
src/use-cases/items/mark-as-low-use-case.ts → src/use-cases/items/mark-as-low.use-case.ts
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
Oops, something went wrong.