-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopenapi.yaml
348 lines (331 loc) · 9.66 KB
/
openapi.yaml
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
openapi: 3.0.3
info:
title: Contract Management API
description: Node.js/Express.js REST API for managing client and contractor profiles, contracts, and jobs, built with Sequelize and SQLite.
version: 1.0.0
servers:
- url: http://localhost:3001
description: Local server
components:
schemas:
Id:
type: integer
example: 1
nullable: false
String:
type: string
minLength: 1
nullable: false
Balance:
type: number
format: float
example: 1150.00
minimum: 0
nullable: false
Profile:
type: object
properties:
id:
$ref: '#/components/schemas/Id'
firstName:
$ref: '#/components/schemas/String'
lastName:
$ref: '#/components/schemas/String'
profession:
$ref: '#/components/schemas/String'
balance:
$ref: '#/components/schemas/Balance'
type:
type: string
enum: [client, contractor]
example: client
nullable: false
Contract:
type: object
properties:
id:
$ref: '#/components/schemas/Id'
terms:
$ref: '#/components/schemas/String'
status:
type: string
enum: [new, in_progress, terminated]
example: in_progress
nullable: false
ClientId:
$ref: '#/components/schemas/Id'
ContractorId:
$ref: '#/components/schemas/Id'
Job:
type: object
properties:
id:
$ref: '#/components/schemas/Id'
description:
$ref: '#/components/schemas/String'
price:
$ref: '#/components/schemas/Balance'
paid:
type: boolean
example: false
nullable: false
paymentDate:
type: string
format: date-time
example: 2020-08-15T19:11:26.737Z
nullable: true
ContractId:
$ref: '#/components/schemas/Id'
Amount:
type: number
format: float
example: 100.0
minimum: 0
nullable: false
Error:
type: object
properties:
message:
type: string
example: An error occurred.
SuccessMessage:
type: object
properties:
message:
type: string
example: Operation successful
nullable: false
parameters:
ProfileIdHeader:
in: header
name: profile_id
required: true
schema:
type: integer
example: 1
description: Profile ID for authenticated user
paths:
/contracts/{id}:
get:
summary: Get contract by ID
description: Returns the contract only if it belongs to the profile calling.
parameters:
- $ref: '#/components/parameters/ProfileIdHeader'
- in: path
name: id
required: true
schema:
$ref: '#/components/schemas/Id'
description: The ID of the contract
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/Contract'
'403':
description: Forbidden, contract does not belong to the profile
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'404':
description: Contract not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/contracts:
get:
summary: Get contracts
description: Returns a list of contracts belonging to a user (client or contractor). The list should only contain non-terminated contracts.
parameters:
- $ref: '#/components/parameters/ProfileIdHeader'
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Contract'
/jobs/unpaid:
get:
summary: Get unpaid jobs
description: Get all unpaid jobs for a user (either a client or contractor), for active contracts only.
parameters:
- $ref: '#/components/parameters/ProfileIdHeader'
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: array
items:
$ref: '#/components/schemas/Job'
/jobs/{job_id}/pay:
post:
summary: Pay for a job
description: Pay for a job, a client can only pay if his balance >= the amount to pay. The amount should be moved from the client's balance to the contractor's balance.
parameters:
- $ref: '#/components/parameters/ProfileIdHeader'
- in: path
name: job_id
required: true
schema:
$ref: '#/components/schemas/Id'
description: The ID of the job
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessMessage'
'400':
description: Bad request, insufficient balance or job not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'403':
description: Forbidden, client does not have access to this job
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
'404':
description: Job not found
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/balances/deposit/{userId}:
post:
summary: Deposit money
description: Deposits money into the balance of a client, a client can't deposit more than 25% of their total jobs to pay at the deposit moment.
parameters:
- $ref: '#/components/parameters/ProfileIdHeader'
- in: path
name: userId
required: true
schema:
$ref: '#/components/schemas/Id'
description: The ID of the user
requestBody:
required: true
content:
application/json:
schema:
type: object
properties:
amount:
$ref: '#/components/schemas/Amount'
responses:
'200':
description: Successful response
content:
application/json:
schema:
$ref: '#/components/schemas/SuccessMessage'
'400':
description: Bad request, deposit amount exceeds 25% limit
content:
application/json:
schema:
$ref: '#/components/schemas/Error'
/admin/best-profession:
get:
summary: Get best profession
description: Returns the profession that earned the most money (sum of jobs paid) for any contractor that worked in the query time range.
parameters:
- in: query
name: start
required: true
schema:
type: string
format: date
nullable: false
description: The start date of the query range
- in: query
name: end
required: true
schema:
type: string
format: date
nullable: false
description: The end date of the query range
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: object
properties:
profession:
type: string
example: Programmer
nullable: false
totalEarned:
type: number
format: float
example: 5000.00
nullable: false
/admin/best-clients:
get:
summary: Get best clients
description: Returns the clients that paid the most for jobs in the query time period. Limit query parameter should be applied, default limit is 2.
parameters:
- in: query
name: start
required: true
schema:
type: string
format: date
nullable: false
description: The start date of the query range
- in: query
name: end
required: true
schema:
type: string
format: date
nullable: false
description: The end date of the query range
- in: query
name: limit
required: false
schema:
type: integer
default: 2
minimum: 1
nullable: false
description: The number of top clients to return
responses:
'200':
description: Successful response
content:
application/json:
schema:
type: array
items:
type: object
properties:
id:
$ref: '#/components/schemas/Id'
fullName:
type: string
example: Reece Moyer
nullable: false
paid:
$ref: '#/components/schemas/Balance'
'400':
description: Bad request, invalid date range or limit
content:
application/json:
schema:
$ref: '#/components/schemas/Error'