112 lines
2.6 KiB
Markdown
112 lines
2.6 KiB
Markdown
# PetCare — Backend API
|
|
|
|
> 一款帮助宠物主人管理宠物健康、日常活动和成长记录的移动应用。
|
|
|
|
## Tech Stack
|
|
|
|
- **Runtime**: Node.js
|
|
- **Framework**: Fastify 5
|
|
- **Language**: TypeScript
|
|
- **Database**: SQLite (better-sqlite3)
|
|
- **Auth**: JWT + bcrypt
|
|
|
|
## Getting Started
|
|
|
|
```bash
|
|
# Install dependencies
|
|
npm install
|
|
|
|
# Development (hot reload)
|
|
npm run dev
|
|
|
|
# Build
|
|
npm run build
|
|
|
|
# Production start
|
|
npm run start
|
|
|
|
# Run tests
|
|
npm test
|
|
```
|
|
|
|
## Project Structure
|
|
|
|
```
|
|
src/
|
|
├── index.ts # Server entry point
|
|
├── db/
|
|
│ ├── schema.ts # SQLite schema
|
|
│ └── client.ts # Database client
|
|
├── routes/
|
|
│ ├── auth.ts # Auth routes (register/login/me)
|
|
│ └── *.ts # CRUD routes
|
|
├── services/
|
|
│ └── *.ts # Business logic
|
|
├── middleware/
|
|
│ └── auth.ts # JWT middleware
|
|
├── types/
|
|
│ └── index.ts # TypeScript types
|
|
└── __tests__/
|
|
└── *.test.ts # Tests
|
|
```
|
|
|
|
## API Endpoints
|
|
|
|
### Auth
|
|
- `POST /api/auth/register` — Register
|
|
- `POST /api/auth/login` — Login
|
|
- `GET /api/auth/me` — Current user (auth required)
|
|
|
|
### Resources
|
|
#### pets
|
|
- `GET /api/pets` — List all
|
|
- `GET /api/pets/:id` — Get by ID
|
|
- `POST /api/pets` — Create
|
|
- `PUT /api/pets/:id` — Update
|
|
- `DELETE /api/pets/:id` — Delete
|
|
|
|
#### schedules
|
|
- `GET /api/schedules` — List all
|
|
- `GET /api/schedules/:id` — Get by ID
|
|
- `POST /api/schedules` — Create
|
|
- `PUT /api/schedules/:id` — Update
|
|
- `DELETE /api/schedules/:id` — Delete
|
|
|
|
#### records
|
|
- `GET /api/records` — List all
|
|
- `GET /api/records/:id` — Get by ID
|
|
- `POST /api/records` — Create
|
|
- `PUT /api/records/:id` — Update
|
|
- `DELETE /api/records/:id` — Delete
|
|
|
|
#### albums
|
|
- `GET /api/albums` — List all
|
|
- `GET /api/albums/:id` — Get by ID
|
|
- `POST /api/albums` — Create
|
|
- `PUT /api/albums/:id` — Update
|
|
- `DELETE /api/albums/:id` — Delete
|
|
|
|
#### hospitals
|
|
- `GET /api/hospitals` — List all
|
|
- `GET /api/hospitals/:id` — Get by ID
|
|
- `POST /api/hospitals` — Create
|
|
- `PUT /api/hospitals/:id` — Update
|
|
- `DELETE /api/hospitals/:id` — Delete
|
|
|
|
#### items
|
|
- `GET /api/items` — List all
|
|
- `GET /api/items/:id` — Get by ID
|
|
- `POST /api/items` — Create
|
|
- `PUT /api/items/:id` — Update
|
|
- `DELETE /api/items/:id` — Delete
|
|
|
|
#### daily-logs
|
|
- `GET /api/daily-logs` — List all
|
|
- `GET /api/daily-logs/:id` — Get by ID
|
|
- `POST /api/daily-logs` — Create
|
|
- `PUT /api/daily-logs/:id` — Update
|
|
- `DELETE /api/daily-logs/:id` — Delete
|
|
|
|
### System
|
|
- `GET /api/health` — Health check
|