Skip to content

Commit acb76e3

Browse files
authored
docs: Add cards endpoints docs (#57)
* Document API endpoints for card operations Added API endpoints section with details on card operations. Signed-off-by: freya-docs <freya.docs.pp@gmail.com> * Update README with Card API examples and error cases Added examples for PUT, DELETE, and error handling for Cards. Signed-off-by: freya-docs <freya.docs.pp@gmail.com> * Add 409 error in README Signed-off-by: freya-docs <freya.docs.pp@gmail.com> --------- Signed-off-by: freya-docs <freya.docs.pp@gmail.com>
1 parent 8031904 commit acb76e3

1 file changed

Lines changed: 133 additions & 0 deletions

File tree

README.md

Lines changed: 133 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -118,6 +118,139 @@ DevCard uses a three-layer follow engine:
118118
| WebView Connect | In-app WebView interaction | LinkedIn, Twitter/X |
119119
| Profile Link | Opens profile in browser | GitLab, Devfolio, others |
120120

121+
## API Endpoints
122+
123+
The API provides the following endpoints (defined by the `cardRoutes` function in `apps/backend/src/routes/cards.ts`):
124+
125+
| Method | Endpoint | Description |
126+
|--------|----------|-------------|
127+
| **GET** | `/` | List all cards for the authenticated user |
128+
| **POST** | `/` | Create a new card (first card is auto-set as default) |
129+
| **PUT** | `/:id` | Update a card's title and/or links |
130+
| **DELETE** | `/:id` | Delete a card |
131+
| **PUT** | `/:id/default` | Set a card as the default card |
132+
133+
### **POST /** - Create a New Card (Example)
134+
135+
**Request:**
136+
```json
137+
POST /cards HTTP/1.1
138+
Authorization: Bearer <token>
139+
Content-Type: application/json
140+
141+
{
142+
"title": "New Card",
143+
"linkIds": [
144+
"223e4567-e89b-12d3-a456-426614174000",
145+
"323e4567-e89b-12d3-a456-426614174000"
146+
]
147+
}
148+
```
149+
150+
**Response (201 Created):**
151+
```json
152+
{
153+
"id": "623e4567-e89b-12d3-a456-426614174000",
154+
"title": "New Card",
155+
"isDefault": false,
156+
"links": [
157+
{
158+
"id": "223e4567-e89b-12d3-a456-426614174000",
159+
"platform": "github",
160+
"username": "john-doe",
161+
"url": "https://github.com/john-doe"
162+
},
163+
{
164+
"id": "323e4567-e89b-12d3-a456-426614174000",
165+
"platform": "twitter",
166+
"username": "johndoe",
167+
"url": "https://twitter.com/johndoe"
168+
}
169+
]
170+
}
171+
```
172+
**Field constraints:**
173+
- `title`: String, 1-100 characters (required)
174+
- `linkIds`: Array of UUID strings (required, can be empty array)
175+
176+
### **PUT /:id** - Update a Card (Example)
177+
178+
**Request:**
179+
```json
180+
PUT /cards/123e4567-e89b-12d3-a456-426614174000 HTTP/1.1
181+
Authorization: Bearer <token>
182+
Content-Type: application/json
183+
184+
{
185+
"title": "Updated Card Title",
186+
"linkIds": [
187+
"223e4567-e89b-12d3-a456-426614174000"
188+
]
189+
}
190+
```
191+
192+
**Response (200 OK):**
193+
```json
194+
{
195+
"id": "123e4567-e89b-12d3-a456-426614174000",
196+
"title": "Updated Card Title",
197+
"isDefault": true,
198+
"links": [
199+
{
200+
"id": "223e4567-e89b-12d3-a456-426614174000",
201+
"platform": "github",
202+
"username": "john-doe",
203+
"url": "https://github.com/john-doe"
204+
}
205+
]
206+
}
207+
```
208+
209+
**Field constraints:**
210+
- `title`: String, 1-100 characters (optional)
211+
- `linkIds`: Array of UUID strings (optional)
212+
213+
### **DELETE /:id** - Delete a Card (Example)
214+
215+
**Request:**
216+
```http
217+
DELETE /cards/123e4567-e89b-12d3-a456-426614174000 HTTP/1.1
218+
Authorization: Bearer <token>
219+
```
220+
221+
**Response (204 No Content):**
222+
```
223+
(empty body)
224+
```
225+
### **PUT /:id/default** - Set a Card as Default (Example)
226+
227+
**Request:**
228+
```http
229+
PUT /cards/423e4567-e89b-12d3-a456-426614174000/default HTTP/1.1
230+
Authorization: Bearer <token>
231+
Content-Type: application/json
232+
```
233+
234+
**Response (200 OK):**
235+
```json
236+
{
237+
"message": "Default card updated"
238+
}
239+
```
240+
241+
### Error Cases
242+
243+
The following error cases are implemented:
244+
245+
| Scenario | Status | Response |
246+
|----------|--------|----------|
247+
| **Create/Update Card** | 400 | `{ error: 'Validation failed', details: parsed.error.flatten() }` — when title or linkIds don't meet constraints |
248+
| **Create/Update Card** | 409 | `{ error: 'Username already taken'}` — when a user with the same username exists |
249+
| **Update Card** | 404 | `{ error: 'Card not found' }` — when card ID doesn't exist or doesn't belong to authenticated user |
250+
| **Delete Card** | 404 | `{ error: 'Card not found' }` — when card ID doesn't exist or doesn't belong to authenticated user |
251+
| **Set Default Card** | 404 | `{ error: 'Card not found' }` — when card ID doesn't exist or doesn't belong to authenticated user |
252+
| **Successful Deletion** | 204 | No content |
253+
121254
## Contributing
122255

123256
See [CONTRIBUTING.md](./CONTRIBUTING.md) for setup instructions, coding standards, and PR process.

0 commit comments

Comments
 (0)