File size: 6,057 Bytes
25f22bf
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
# API Design Document

## Overview
This document outlines the RESTful API endpoints for the Lin application backend. The API will be implemented using Flask and will follow REST conventions.

## Authentication
All endpoints (except authentication endpoints) require a valid JWT token in the Authorization header:
```
Authorization: Bearer <token>
```

## Error Handling
All endpoints will return appropriate HTTP status codes:
- 200: Success
- 201: Created
- 400: Bad Request
- 401: Unauthorized
- 404: Not Found
- 500: Internal Server Error

Error responses will follow this format:
```json
{
  "error": "Error message",
  "code": "ERROR_CODE"
}
```

## Endpoints

### Authentication

#### Register User
- **POST** `/api/auth/register`
- **Description**: Register a new user
- **Request Body**:
```json
{
  "email": "string",
  "password": "string",
  "confirm_password": "string"
}
```
- **Response**:
```json
{
  "message": "User registered successfully",
  "user": {
    "id": "string",
    "email": "string"
  }
}
```

#### Login User
- **POST** `/api/auth/login`
- **Description**: Authenticate a user
- **Request Body**:
```json
{
  "email": "string",
  "password": "string"
}
```
- **Response**:
```json
{
  "token": "string",
  "user": {
    "id": "string",
    "email": "string"
  }
}
```

#### Logout User
- **POST** `/api/auth/logout`
- **Description**: Logout current user
- **Response**:
```json
{
  "message": "Logged out successfully"
}
```

#### Get Current User
- **GET** `/api/auth/user`
- **Description**: Get current authenticated user
- **Response**:
```json
{
  "user": {
    "id": "string",
    "email": "string"
  }
}
```

### Sources

#### Get All Sources
- **GET** `/api/sources`
- **Description**: Get all sources for the current user
- **Response**:
```json
{
  "sources": [
    {
      "id": "string",
      "user_id": "string",
      "source": "string",
      "category": "string",
      "last_update": "datetime"
    }
  ]
}
```

#### Add Source
- **POST** `/api/sources`
- **Description**: Add a new source
- **Request Body**:
```json
{
  "source": "string"
}
```
- **Response**:
```json
{
  "message": "Source added successfully",
  "source": {
    "id": "string",
    "user_id": "string",
    "source": "string",
    "category": "string",
    "last_update": "datetime"
  }
}
```

#### Delete Source
- **DELETE** `/api/sources/{id}`
- **Description**: Delete a source
- **Response**:
```json
{
  "message": "Source deleted successfully"
}
```

### Social Accounts

#### Get All Accounts
- **GET** `/api/accounts`
- **Description**: Get all social media accounts for the current user
- **Response**:
```json
{
  "accounts": [
    {
      "id": "string",
      "user_id": "string",
      "social_network": "string",
      "account_name": "string",
      "created_at": "datetime"
    }
  ]
}
```

#### Add Account
- **POST** `/api/accounts`
- **Description**: Add a new social media account
- **Request Body**:
```json
{
  "account_name": "string",
  "social_network": "string"
}
```
- **Response**:
```json
{
  "message": "Account added successfully",
  "account": {
    "id": "string",
    "user_id": "string",
    "social_network": "string",
    "account_name": "string",
    "created_at": "datetime"
  }
}
```

#### Delete Account
- **DELETE** `/api/accounts/{id}`
- **Description**: Delete a social media account
- **Response**:
```json
{
  "message": "Account deleted successfully"
}
```

### Posts

#### Get All Posts
- **GET** `/api/posts`
- **Description**: Get all posts for the current user
- **Query Parameters**:
  - `published` (boolean): Filter by published status
- **Response**:
```json
{
  "posts": [
    {
      "id": "string",
      "user_id": "string",
      "social_account_id": "string",
      "text_content": "string",
      "image_content_url": "string",
      "is_published": "boolean",
      "created_at": "datetime",
      "scheduled_at": "datetime"
    }
  ]
}
```

#### Generate Post
- **POST** `/api/posts/generate`
- **Description**: Generate a new post using AI
- **Request Body**:
```json
{
  "user_id": "string"
}
```
- **Response**:
```json
{
  "content": "string"
}
```

#### Create Post
- **POST** `/api/posts`
- **Description**: Create a new post
- **Request Body**:
```json
{
  "social_account_id": "string",
  "text_content": "string",
  "image_content_url": "string",
  "scheduled_at": "datetime"
}
```
- **Response**:
```json
{
  "message": "Post created successfully",
  "post": {
    "id": "string",
    "user_id": "string",
    "social_account_id": "string",
    "text_content": "string",
    "image_content_url": "string",
    "is_published": "boolean",
    "created_at": "datetime",
    "scheduled_at": "datetime"
  }
}
```

#### Publish Post
- **POST** `/api/posts/{id}/publish`
- **Description**: Publish a post to social media
- **Response**:
```json
{
  "message": "Post published successfully"
}
```

#### Delete Post
- **DELETE** `/api/posts/{id}`
- **Description**: Delete a post
- **Response**:
```json
{
  "message": "Post deleted successfully"
}
```

### Schedules

#### Get All Schedules
- **GET** `/api/schedules`
- **Description**: Get all schedules for the current user
- **Response**:
```json
{
  "schedules": [
    {
      "id": "string",
      "social_account_id": "string",
      "schedule_time": "string",
      "adjusted_time": "string",
      "created_at": "datetime"
    }
  ]
}
```

#### Create Schedule
- **POST** `/api/schedules`
- **Description**: Create a new schedule
- **Request Body**:
```json
{
  "social_account_id": "string",
  "schedule_time": "string",  // Format: "Monday 18:00"
  "days": ["string"]          // Array of days
}
```
- **Response**:
```json
{
  "message": "Schedule created successfully",
  "schedule": {
    "id": "string",
    "social_account_id": "string",
    "schedule_time": "string",
    "adjusted_time": "string",
    "created_at": "datetime"
  }
}
```

#### Delete Schedule
- **DELETE** `/api/schedules/{id}`
- **Description**: Delete a schedule
- **Response**:
```json
{
  "message": "Schedule deleted successfully"
}