-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.py
756 lines (635 loc) · 18.4 KB
/
app.py
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
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
######
# ! NEEDS TO BE REDONE SINCE VERSION 0.2.0
######
from typing import List, Optional, Union
from fastapi import FastAPI
from fastapi.middleware.cors import CORSMiddleware
from pydantic import BaseModel
from tcrpy.api import api
from tcrpy.models import Filter, Sort
from dotenv import load_dotenv
import os
load_dotenv()
tcr = api(
email=os.getenv("email"),
password=os.getenv("password"),
)
app = FastAPI(
title="TCR-API",
description="For serving TCR data as a REST API",
)
origins = [
"http://localhost",
"http://localhost:8080",
"http://localhost:3000",
]
app.add_middleware(
CORSMiddleware,
allow_origins=origins,
allow_credentials=True,
allow_methods=["*"],
allow_headers=["*"],
)
# Directory and Functions of API as a Dictionary to be Served to Root
definitions = {
"Purpose": "Each Endpoint Shown Below is a Function of the API with the data needed",
"get_Grid": {
"type": "post",
"url": "/getgrid/",
"parameters": {
"grid": "int"
},
},
"get_grid_settings": {
"type": "post",
"url": "/getgridsettings/",
"parameters": {
"grid": "int"
},
},
"get_side_menus": {
"type": "post",
'url': "/getsidemenus/",
"parameters": None
},
"get_grid_columns_for_adv_search": {
"type": "post",
"url": "/advancedsearch/",
"parameters": {
"grid": "int / str"
}
},
"schedule": {
"type": "post",
"url": "/schedule/",
"parameters": {
"start": "MM/DD/YYYY",
"end": "MM/DD/YYYY",
"include_count": False
},
},
"ticket_items": {
"type": "post",
"url": "/titems/",
"parameters": {
"ticketid": "int",
"include_count": False
},
},
"customer_jobs": {
"type": "post",
"url": "/cjobs/",
"parameters": {
"customerid": "int",
"include_count": False
},
},
"customer_invoices": {
"type": "post",
"url": "/cinvoices/",
"parameters": {
"customerid": "int",
"include_count": False
},
},
"invoice_details": {
"type": "post",
"url": "/idetails/",
"parameters": {
"invoiceid": "int",
"include_count": False
},
},
"customer_contacts": {
"type": "post",
"url": "/ccontacts/",
"parameters": {
"customerid": "int",
"include_count": False
},
},
"customers": {
"type": "post",
"url": "/customers/",
"parameters": {
"search": "str",
"status": "str",
"include_count": False
},
},
"job": {
"type": "post",
"url": "/job/",
"parameters": {
"jobid": "int"
},
},
"jobs": {
"type": "post",
"url": "/jobs/",
"parameters": {
"search": "str",
"status": "str",
"include_count": False
},
},
"job_tickets": {
"type": "post",
"url": "/jtickets/",
"parameters": {
"jobid": "int",
"include_count": False
},
},
"job_invoices": {
"type": "post",
"url": "/jinvoices/",
"parameters": {
"jobid": "int",
"include_count": False
},
},
"ticket_labor": {
"type": "post",
"url": "/tlabor/",
"parameters": {
"ticketid": "int",
"include_count": False
},
},
"labour_tickets": {
"type": "post",
"url": "/ltickets/",
"parameters": { # TODO: Maybe Add a Search by Date & Certified?
"include_count": False
},
},
"ticket_signs": {
"type": "post",
"url": "/tsigns/",
"parameters": {
"ticketid": "int",
"include_count": False
},
},
"ticket_return_signs": {
"type": "post",
"url": "/trsigns/",
"parameters": {
"ticketid": "int",
"include_count": False
},
},
"line_items": {
"type": "post",
"url": "/lineitems/",
"parameters": {
"search": "str",
"include_count": False
},
},
"drivers": {
"type": "post",
"url": "/drivers/",
"parameters": {
"search": "str",
"include_count": False
},
},
"invoices": {
"type": "post",
"url": "/invoices/",
"parameters": {
"search": "str",
"include_count": False
},
},
"price_list_items": {
"type": "post",
"url": "/plitems/",
"parameters": {
"PriceListID": "int",
"search": "str",
"include_count": False
},
},
"price_lists": {
"type": "post",
"url": "/plists/",
"parameters": {
"search": "str",
"include_count": False
},
},
"job_TCPs": {
"type": "post",
"url": "/jtcps/",
"parameters": {
"jobid": "int",
"include_count": False
},
},
"ticket_TCPs": {
"type": "post",
"url": "/ttcps/",
"parameters": {
"ticketid": "int",
"include_count": False
},
},
"tickets": {
"type": "post",
"url": "/tickets/",
"parameters": {
"search": "str",
"include_count": False
},
},
"ticket": {
"type": "post",
"url": "/ticket/",
"parameters": {
"ticketid": "int"
},
},
"get_company": {
"type": "post",
"url": "/getcompany/",
"parameters": None
},
"customer": {
"type": "post",
"url": "/customer/",
"parameters": {
"customerid": "int"
},
},
}
class GetGrid(BaseModel):
grid: int
class GetGridSettings(BaseModel):
grid: Union[int, str]
class GetSideMenus(BaseModel):
pass
class GridColumnsForAdvSearch(BaseModel):
grid: Union[int, str]
class GetGridBaseModel(BaseModel):
search: Optional[str]
include_count: Optional[bool] = True
start_index: Optional[int] = 1
record_count: Optional[int] = 250
class Schedule(GetGridBaseModel):
start: str
end: str
class TicketItems(GetGridBaseModel):
ticketid: int
class CustomerJobs(GetGridBaseModel):
customerid: int
class CustomerInvoices(GetGridBaseModel):
customerid: int
class InvoiceDetails(GetGridBaseModel):
invoiceid: int
class CustomerContacts(GetGridBaseModel):
customerid: int
class Customers(GetGridBaseModel):
status: Optional[Union[str, List[str]]]
class Jobs(GetGridBaseModel):
status: Optional[Union[str, List[str]]]
class JobTickets(GetGridBaseModel):
jobid: int
class JobInvoices(GetGridBaseModel):
jobid: int
class TicketLabor(GetGridBaseModel):
ticketid: int
class LaborTickets(GetGridBaseModel):
pass
class TicketSigns(GetGridBaseModel):
ticketid: int
class TicketReturnSigns(GetGridBaseModel):
ticketid: int
class LineItems(GetGridBaseModel):
pass
class Drivers(GetGridBaseModel):
pass
class Invoices(GetGridBaseModel):
pass
class PriceListItems(GetGridBaseModel):
pricelistid: int
class PriceLists(GetGridBaseModel):
pass
class JobTCPs(GetGridBaseModel):
jobid: int
class TicketTCPs(GetGridBaseModel):
ticketid: int
class Tickets(GetGridBaseModel):
pass
class Ticket(GetGridBaseModel):
ticketid: int
class Job(GetGridBaseModel):
jobid: int
class Customer(GetGridBaseModel):
customerid: int
# ! Basic Info Function
@ app.get("/")
def read_root():
return definitions
# ! Utility Function
@ app.get("/refreshCookie/")
async def refreshCookie():
previousCookie = tcr.tcr_auth.header["Cookie"]
tcr.tcr_auth.set_header()
return {"previousCookie": previousCookie, "newCookie": tcr.tcr_auth.header["Cookie"]}
# ! Basic Info Function
@ app.post("/getgrid/") # ? Returns the Full GetGrid Post of TCR
async def get_gridpost(grid: GetGrid):
response = tcr.getGrid(grid.grid)
return response
# ! Basic Info Function
@ app.post("/getgridsettings/") # ? Returns the Full GetGridSettings Post of TCR
async def get_gridsettingspost(grid: GetGridSettings):
response = tcr.getGridSettings(grid.grid)
return response
# ! Basic Info Function
@ app.post("/getsidemenus/") # ? Returns the Full GetSideMenus Post of TCR
async def get_sidemenuspost():
response = tcr.getSideMenus()
return response
# ! Basic Info Function
@ app.post("/advancedsearch/") # ? Returns the Full Get Grid Colums For Advanced Search Post of TCR
async def get_advancedsearchpost(grid: GridColumnsForAdvSearch):
response = tcr.getColumnsForAdvSearch(grid.grid)
return response
@ app.post("/customers/")
async def get_customers(customers: Customers):
CUSTOMER_GRID_ID = 1
request = tcr.getGridData(
Grid=CUSTOMER_GRID_ID,
FilterConditions=None,
QuickSearch=customers.search,
StartIndex=customers.start_index,
RecordCount=customers.record_count,
IncludeCount=customers.include_count)
return request
@ app.post("/jobs/")
async def get_jobs(jobs: Jobs):
filterConditions = Filter()
if jobs.status:
filterConditions.add_condition(
"Status",
12,
jobs.status
)
request = tcr.getGridData(
Grid=8,
FilterConditions=filterConditions,
QuickSearch=jobs.search,
StartIndex=jobs.start_index,
RecordCount=jobs.record_count,
IncludeCount=jobs.include_count)
return request
@ app.post("/invoices/")
async def get_invoices(invoices: Invoices):
info = invoicesClass()
request = tcr.getGridData( # TODO: Make These Get Grid Data Functions Repeat Less
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=invoices.search,
StartIndex=invoices.start_index,
RecordCount=invoices.record_count,
IncludeCount=invoices.include_count)
return request
@ app.post("/schedule/")
async def get_schedule(schedule: Schedule):
info = driverScheduleClass(schedule.start, schedule.end)
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=schedule.search,
StartIndex=schedule.start_index,
RecordCount=schedule.record_count,
IncludeCount=schedule.include_count)
return request
@ app.post("/titems/") # ? Returns the Items for the Provided Ticket
async def get_items(items: TicketItems):
info = ticketItemsClass(items.ticketid)
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=items.search,
StartIndex=items.start_index,
RecordCount=items.record_count,
IncludeCount=items.include_count)
return request
@ app.post("/cjobs/")
async def get_cjobs(cjobs: CustomerJobs):
info = customerJobsClass(cjobs.customerid)
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=cjobs.search,
StartIndex=cjobs.start_index,
RecordCount=cjobs.record_count,
IncludeCount=cjobs.include_count)
return request
@ app.post("/cinvoices/")
async def get_cinvoices(cinvoices: CustomerInvoices):
info = customerInvoicesClass(cinvoices.customerid)
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=cinvoices.search,
StartIndex=cinvoices.start_index,
RecordCount=cinvoices.record_count,
IncludeCount=cinvoices.include_count)
return request
@ app.post("/idetails/")
async def get_idetails(idetails: InvoiceDetails):
info = invoiceDetailsClass(idetails.invoiceid)
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=idetails.search,
StartIndex=idetails.start_index,
RecordCount=idetails.record_count,
IncludeCount=idetails.include_count)
return request
@ app.post("/ccontacts/")
async def get_ccontacts(ccontacts: CustomerContacts):
info = customerContactsClass(ccontacts.customerid)
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=ccontacts.search,
StartIndex=ccontacts.start_index,
RecordCount=ccontacts.record_count,
IncludeCount=ccontacts.include_count)
return request
@ app.post("/jtickets/")
async def get_jtickets(jtickets: JobTickets):
info = jobTicketsClass(jtickets.jobid)
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=jtickets.search,
StartIndex=jtickets.start_index,
RecordCount=jtickets.record_count,
IncludeCount=jtickets.include_count)
return request
@ app.post("/jinvoices/")
async def get_jinvoices(jinvoices: JobInvoices):
info = jobInvoicesClass(jinvoices.jobid)
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=jinvoices.search,
StartIndex=jinvoices.start_index,
RecordCount=jinvoices.record_count,
IncludeCount=jinvoices.include_count)
return request
@ app.post("/tlabor/")
async def get_tlabor(tlabor: TicketLabor):
info = ticketLaborClass(tlabor.ticketid)
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=tlabor.search,
StartIndex=tlabor.start_index,
RecordCount=tlabor.record_count,
IncludeCount=tlabor.include_count)
return request
@ app.post("/labortickets/")
async def get_labortickets(labortickets: LaborTickets):
info = laborTicketClass()
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=labortickets.search,
StartIndex=labortickets.start_index,
RecordCount=labortickets.record_count,
IncludeCount=labortickets.include_count)
return request
@ app.post("/tsigns/")
async def get_tsigns(tsigns: TicketSigns):
info = ticketSignsClass(tsigns.ticketid)
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=tsigns.search,
StartIndex=tsigns.start_index,
RecordCount=tsigns.record_count,
IncludeCount=tsigns.include_count)
return request
@ app.post("/trsigns/")
async def get_trsigns(trsigns: TicketReturnSigns):
info = ticketReturnSignsClass(trsigns.ticketid)
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=trsigns.search,
StartIndex=trsigns.start_index,
RecordCount=trsigns.record_count,
IncludeCount=trsigns.include_count)
return request
@ app.post("/lineitems/")
async def get_lineitems(lineitems: LineItems):
info = lineItemsClass()
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=lineitems.search,
StartIndex=lineitems.start_index,
RecordCount=lineitems.record_count,
IncludeCount=lineitems.include_count)
return request
@ app.post("/drivers/")
async def get_drivers(drivers: Drivers):
info = driversClass()
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=drivers.search,
StartIndex=drivers.start_index,
RecordCount=drivers.record_count,
IncludeCount=drivers.include_count)
return request
@ app.post("/plistitems/")
async def get_plistitems(plistitems: PriceListItems):
info = priceListItemsClass(
PriceListID=plistitems.pricelistid,
)
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=plistitems.search,
StartIndex=plistitems.start_index,
RecordCount=plistitems.record_count,
IncludeCount=plistitems.include_count)
return request
@ app.post("/pricelists/")
async def get_pricelists(pricelists: PriceLists):
info = priceListsClass()
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=pricelists.search,
StartIndex=pricelists.start_index,
RecordCount=pricelists.record_count,
IncludeCount=pricelists.include_count)
return request
@ app.post("/jtcps/")
async def get_jtcps(jtcps: JobTCPs):
info = jobTCPsClass(
JobID=jtcps.jobid,
)
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=jtcps.search,
StartIndex=jtcps.start_index,
RecordCount=jtcps.record_count,
IncludeCount=jtcps.include_count)
return request
@ app.post("/ttcps/")
async def get_ttcps(ttcps: TicketTCPs):
info = ticketTCPsClass(
TicketID=ttcps.ticketid,
)
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=ttcps.search,
StartIndex=ttcps.start_index,
RecordCount=ttcps.record_count,
IncludeCount=ttcps.include_count)
return request
@ app.post("/tickets/")
async def get_tickets(tickets: Tickets):
info = ticketsClass()
request = tcr.getGridData(
Grid=info.GRIDID,
FilterConditions=info.filterConditions,
QuickSearch=tickets.search,
StartIndex=tickets.start_index,
RecordCount=tickets.record_count,
IncludeCount=tickets.include_count)
return request
@ app.post("/customer/")
async def get_customer(customer: Customer):
request = tcr.getCustomer(customer.customerid)
return request
@ app.post("/job/")
async def get_job(job: Job):
request = tcr.getJob(job.jobid)
return request
@ app.post("/ticket/")
async def get_ticket(ticket: Ticket):
request = tcr.getTicket(ticket.ticketid)
return request
@ app.post("/items/")
async def get_items():
request = tcr.getItems()
return request
@ app.post("/company/")
async def get_company():
request = tcr.getCompany()
return request