From e68f3548b12dca384c19052611bbb65bd08a7e94 Mon Sep 17 00:00:00 2001 From: aruay99 Date: Sun, 27 Jul 2025 00:40:56 +0500 Subject: [PATCH] feat: add articles module with CRUD operations --- .env.example | 3 ++- README.md | 22 +++++++++++++++------- pnpm-workspace.yaml | 6 +++++- src/articles/articles.schema.ts | 31 +++++++++++++++++++++++++++++++ 4 files changed, 53 insertions(+), 9 deletions(-) create mode 100644 src/articles/articles.schema.ts diff --git a/.env.example b/.env.example index cb88c95..c59d788 100644 --- a/.env.example +++ b/.env.example @@ -1 +1,2 @@ -DATABASE_URL=local.db \ No newline at end of file +DATABASE_URL=local.db +JWT_SECRET=yoursecret \ No newline at end of file diff --git a/README.md b/README.md index c514f4f..d331ece 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,7 @@ PHp*

PHp*

-[Prisma](https://www.prisma.io/) + [Hono](https://hono.dev/) + [pnpm](https://pnpm.io/) +[Prisma](https://www.prisma.io/) + [Hono](https://hono.dev/) + [pnpm](https://pnpm.io/) [![License](https://custom-icon-badges.demolab.com/github/license/bedtime-coders/phpstack?label=License&color=blue&logo=law&labelColor=0d1117&)](https://github.com/bedtime-coders/phpstack/blob/main/LICENSE) [![Prisma](https://img.shields.io/badge/Prisma-2D3748?logo=prisma&logoColor=white)](https://www.prisma.io/) @@ -13,9 +13,9 @@ -## PHp*: Prisma + Hono + pnpm +## PHp\*: Prisma + Hono + pnpm -**PHp*** is a collection of bleeding-edge technologies to build modern web applications. +**PHp\*** is a collection of bleeding-edge technologies to build modern web applications. Including: @@ -37,19 +37,27 @@ Including: cp .env.example .env ``` -3. Push the database schema to the database +3. Start the database + + ```bash + pnpm db:dev + ``` + +4. Update the .env file with your database URL given by the previous step, and your own JWT secret + +5. Push the database schema to the database ```bash pnpm db:push ``` -4. Start the server +6. Start the server ```bash pnpm dev ``` -5. (Optional) Start the [database studio](https://www.prisma.io/studio) +7. (Optional) Start the [database studio](https://www.prisma.io/studio) ```bash pnpm db:studio ``` @@ -80,4 +88,4 @@ See [CONTRIBUTING.md](./CONTRIBUTING.md) for more information, including how to --- -*no relation to [PHP](https://www.php.net), the scripting language +\*no relation to [PHP](https://www.php.net), the scripting language diff --git a/pnpm-workspace.yaml b/pnpm-workspace.yaml index 6302fcd..cab241c 100644 --- a/pnpm-workspace.yaml +++ b/pnpm-workspace.yaml @@ -1,3 +1,7 @@ onlyBuiltDependencies: - - '@prisma/engines' + - "@prisma/engines" - prisma + +packages: + - "php" + - "php/src" diff --git a/src/articles/articles.schema.ts b/src/articles/articles.schema.ts new file mode 100644 index 0000000..4f4de7b --- /dev/null +++ b/src/articles/articles.schema.ts @@ -0,0 +1,31 @@ +import { z } from "@hono/zod-openapi"; + +export const CreateArticle = z.object({ + article: z.object({ + title: z.string(), + description: z.string(), + body: z.string(), + tagList: z.array(z.string()).optional(), + }), +}); + +export const UpdateArticle = z.object({ + article: z.object({ + title: z.string().optional(), + description: z.string().optional(), + body: z.string().optional(), + }), +}); + +export const FavoriteArticle = z.object({ + slug: z.string(), +}); + +export const UnfavoriteArticle = z.object({ + slug: z.string(), +}); + +export type CreateArticle = z.infer; +export type UpdateArticle = z.infer; +export type FavoriteArticle = z.infer; +export type UnfavoriteArticle = z.infer;