Skip to content
This repository was archived by the owner on Feb 13, 2025. It is now read-only.

Commit 170c1b7

Browse files
Final?
1 parent 4790fe9 commit 170c1b7

21 files changed

+962
-502
lines changed

CargoHub/CARGOHUB/settings.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -133,7 +133,7 @@
133133
'SECURITY_DEFINITIONS': {
134134
'apiKeyAuth': {
135135
'type': 'apiKey',
136-
'name': 'API_KEY_ADMIN', # The header name where the token is passed
136+
'name': 'APIKEYADMIN', # The header name where the token is passed
137137
'in': 'header' # Indicates the token is passed in the request header
138138
}
139139
},

CargoHub/PUML/database_diagram.puml

Lines changed: 144 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
@startuml Database_diagram CargoHub
22

3-
map Clients_table #Chartreuse {
3+
map Clients_table #Plum {
44
id => INTEGER
55
name => TEXT
66
address => TEXT
@@ -15,26 +15,158 @@ map Clients_table #Chartreuse {
1515
updated_at => TEXT
1616
}
1717

18-
object Inventories_table
18+
map Inventories_table #Pink {
19+
id => INTEGER
20+
item_id => INTEGER
21+
description => TEXT
22+
item_reference => TEXT
23+
loactions => TEXT
24+
total_on_hand => INTEGER
25+
total_expected => INTEGER
26+
total_ordered => INTEGER
27+
total_allocated => INTEGER
28+
total_available => INTEGER
29+
created_at => TEXT
30+
updated_at => TEXT
31+
}
1932

20-
object Item_groups_table
33+
map Item_groups_table #Khaki {
34+
id => INTEGER
35+
name => TEXT
36+
description => TEXT
37+
created_at => TEXT
38+
updated_at => TEXT
39+
}
2140

22-
object Item_lines_table
41+
map Item_lines_table #PHYSICAL {
42+
id => INTEGER
43+
name => TEXT
44+
description => TEXT
45+
created_at => TEXT
46+
updated_at => TEXT
47+
}
2348

24-
object Item_types_table
49+
map Item_types_table #MistyRose {
50+
id => INTEGER
51+
name => TEXT
52+
description => TEXT
53+
created_at => TEXT
54+
updated_at => TEXT
55+
}
2556

26-
object Items_table
57+
map Items_table #BUSINESS {
58+
uid => TEXT
59+
code => TEXT
60+
description => TEXT
61+
short_description => TEXT
62+
upc_code => TEXT
63+
model_number => TEXT
64+
commodity_number => TEXT
65+
item_line => INTEGER
66+
item_group => INTEGER
67+
item_type => INTEGER
68+
unit_purchase_quantity => INTEGER
69+
unt_order_quantity => INTEGER
70+
pack_order_quantity => INTEGER
71+
supplier_id => INTEGER
72+
supplier_code => TEXT
73+
supplier_part_number => TEXT
74+
created_at => TEXT
75+
updated_at => TEXT
76+
}
2777

28-
object Locations_table
78+
map Locations_table #Cornsilk {
79+
id => INTEGER
80+
warehouse_id => INTEGER
81+
code => TEXT
82+
name => TEXT
83+
created_at => TEXT
84+
updated_at => TEXT
85+
}
2986

30-
object Orders_table
87+
map Orders_table #IMPLEMENTATION {
88+
id => INTEGER
89+
order_date => TEXT
90+
request_date => TEXT
91+
reference => TEXT
92+
reference_extra => TEXT
93+
order_status => TEXT
94+
notes => TEXT
95+
shipping_notes => TEXT
96+
picking_notes => TEXT
97+
warehouse_id => INTEGER
98+
ship_to => TEXT
99+
bill_to => TEXT
100+
shipment_id => INTEGER
101+
total_amount => INTEGER
102+
total_tax => INTEGER
103+
total_surcharge => INTEGER
104+
created_at => TEXT
105+
updated_at => TEXT
106+
items => TEXT
107+
}
31108

32-
object Shipments_table
109+
map Shipments_table #PeachPuff {
110+
id => INTEGER
111+
source_id => INTEGER
112+
order_date => TEXT
113+
request_date => TEXT
114+
shipment_date => TEXT
115+
shipment_type => TEXT
116+
shipment_status => TEXT
117+
notes => TEXT
118+
carrier_code => TEXT
119+
carrier_description => TEXT
120+
service_code => TEXT
121+
payment_type => TEXT
122+
transfer_mode => TEXT
123+
total_package_count => INTEGER
124+
total_package_weight => INTEGER
125+
created_at => TEXT
126+
updated_at => TEXT
127+
items => TEXT
128+
}
33129

34-
object Suppliers_table
130+
map Suppliers_table #TECHNOLOGY {
131+
id => INTEGER
132+
code => TEXT
133+
name => TEXT
134+
address => TEXT
135+
address_extra => TEXT
136+
city => TEXT
137+
zip_code => TEXT
138+
province => TEXT
139+
country => TEXT
140+
contact_name => TEXT
141+
phonenumber => TEXT
142+
reference => TEXT
143+
created_at => TEXT
144+
updated_at => TEXT
145+
}
35146

36-
object Transfers_table
147+
map Transfers_table #SkyBlue {
148+
id => INTEGER
149+
reference => TEXT
150+
transfer_from => TEXT
151+
transfer_to => INTEGER
152+
transfer_status => TEXT
153+
created_at => TEXT
154+
updated_at => TEXT
155+
items => TEXT
156+
}
37157

38-
object Warehouses_table
158+
map Warehouses_table #Lavender {
159+
id => INTEGER
160+
code => TEXT
161+
name => TEXT
162+
address => TEXT
163+
zip => TEXT
164+
city => TEXT
165+
province => TEXT
166+
country => TEXT
167+
contact => TEXT
168+
created_at => TEXT
169+
updated_at => TEXT
170+
}
39171

40172
@enduml

CargoHub/api/models/Database_file.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def create_database(self):
99
conn = sqlite3.connect(database_name)
1010
cursor = conn.cursor()
1111

12-
# Define the table creation SQL statements
12+
# Define the table creation
1313
create_table_clients = """
1414
CREATE TABLE IF NOT EXISTS clients (
1515
id INTEGER PRIMARY KEY,

CargoHub/api/models/clients.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -166,7 +166,7 @@ def update(self, client_id, client):
166166
client['contact_phone'],
167167
client['contact_email'],
168168
client['created_at'],
169-
self.get_timestamp(), # Assuming this method returns the current timestamp
169+
self.get_timestamp(),
170170
client_id
171171
))
172172

CargoHub/api/models/inventories.py

Lines changed: 62 additions & 66 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,6 @@ def get(self, inventory_id):
3838
cursor = conn.cursor()
3939

4040
try:
41-
# Use the correct placeholder "?" for SQLite
4241
query = "SELECT * FROM inventories WHERE id = ?"
4342
cursor.execute(query, (inventory_id,)) # Pass the client_id as a tuple
4443
inv = cursor.fetchone() # Fetch a single row
@@ -57,79 +56,77 @@ def get(self, inventory_id):
5756
cursor.close()
5857
conn.close()
5958

60-
# def get_inventories_for_item(self, item_id):
61-
# conn = self.db.connection(self.dbfile)
62-
# if conn is None:
63-
# print("DB connection failed")
64-
# return None # Exit if connection fails
59+
def get_inventories_for_item(self, item_id):
60+
conn = self.db.connection(self.dbfile)
61+
if conn is None:
62+
print("DB connection failed")
63+
return None # Exit if connection fails
6564

66-
# try:
67-
# cursor = conn.cursor()
65+
try:
66+
cursor = conn.cursor()
6867

69-
# # Parameterized query to prevent SQL injection
70-
# query = "SELECT * FROM inventories WHERE item_id = ?"
71-
# cursor.execute(query, (item_id,))
68+
query = "SELECT * FROM inventories WHERE item_id = ?"
69+
cursor.execute(query, (item_id,))
7270

73-
# inventories = cursor.fetchall() # Fetch all records matching the item_id
71+
inventories = cursor.fetchall() # Fetch all records matching the item_id
7472

75-
# if not inventories:
76-
# print(f"No inventories found for item ID {item_id}")
77-
# return [] # Return empty list if no records are found
73+
if not inventories:
74+
print(f"No inventories found for item ID {item_id}")
75+
return [] # Return empty list if no records are found
7876

79-
# return inventories # Return the list of inventory records
77+
return inventories # Return the list of inventory records
8078

81-
# except Exception as e:
82-
# print(f"An error occurred: {e}")
83-
# return None
84-
# finally:
85-
# cursor.close()
86-
# conn.close()
87-
88-
# def get_inventory_totals_for_item(self, item_id):
89-
# result = {
90-
# "total_expected": 0,
91-
# "total_ordered": 0,
92-
# "total_allocated": 0,
93-
# "total_available": 0
94-
# }
95-
96-
# conn = self.db.connection(self.dbfile)
97-
# if conn is None:
98-
# print("DB connection failed")
99-
# return None # Exit if connection fails
79+
except Exception as e:
80+
print(f"An error occurred: {e}")
81+
return None
82+
finally:
83+
cursor.close()
84+
conn.close()
85+
86+
def get_inventory_totals_for_item(self, item_id):
87+
result = {
88+
"total_expected": 0,
89+
"total_ordered": 0,
90+
"total_allocated": 0,
91+
"total_available": 0
92+
}
93+
94+
conn = self.db.connection(self.dbfile)
95+
if conn is None:
96+
print("DB connection failed")
97+
return None # Exit if connection fails
10098

101-
# try:
102-
# cursor = conn.cursor()
103-
104-
# # Parameterized query to get totals for each column
105-
# query = """
106-
# SELECT total_expected, total_ordered, total_allocated, total_available
107-
# FROM inventories
108-
# WHERE item_id = ?
109-
# """
110-
# cursor.execute(query, (item_id,))
99+
try:
100+
cursor = conn.cursor()
101+
102+
query = """
103+
SELECT total_expected, total_ordered, total_allocated, total_available
104+
FROM inventories
105+
WHERE item_id = ?
106+
"""
107+
cursor.execute(query, (item_id,))
111108

112-
# inventories = cursor.fetchall() # Fetch all inventory records
109+
inventories = cursor.fetchall() # Fetch all inventory records
113110

114-
# if not inventories:
115-
# print(f"No inventories found for item ID {item_id}")
116-
# return result # Return default result if no records found
111+
if not inventories:
112+
print(f"No inventories found for item ID {item_id}")
113+
return result # Return default result if no records found
117114

118-
# # Summing up the totals for the given item_id
119-
# for inventory in inventories:
120-
# result["total_expected"] += inventory[0]
121-
# result["total_ordered"] += inventory[1]
122-
# result["total_allocated"] += inventory[2]
123-
# result["total_available"] += inventory[3]
115+
# Summing up the totals for the given item_id
116+
for inventory in inventories:
117+
result["total_expected"] += inventory[0]
118+
result["total_ordered"] += inventory[1]
119+
result["total_allocated"] += inventory[2]
120+
result["total_available"] += inventory[3]
124121

125-
# return result # Return the calculated totals
122+
return result # Return the calculated totals
126123

127-
# except Exception as e:
128-
# print(f"An error occurred: {e}")
129-
# return None
130-
# finally:
131-
# cursor.close()
132-
# conn.close()
124+
except Exception as e:
125+
print(f"An error occurred: {e}")
126+
return None
127+
finally:
128+
cursor.close()
129+
conn.close()
133130

134131
def add(self, inventory):
135132
conn = self.db.connection(self.dbfile)
@@ -151,7 +148,7 @@ def add(self, inventory):
151148
) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?);"""
152149

153150
location = json.dumps(inventory['locations'])
154-
# Preparing the data tuple, including serializing locations as a JSON string
151+
# Preparing the data tuple
155152
data = (
156153
inventory['id'],
157154
inventory['item_id'],
@@ -262,12 +259,11 @@ def convert_to_dict(self, inv):
262259
Converts the inventory tuple fetched from the database into a dictionary
263260
with the structure of the given JSON. Handles 'locations' properly.
264261
"""
265-
locations_str = inv[4] # The 'locations' field from the database
262+
locations_str = inv[4]
266263

267264
# Check if locations contain square brackets and strip them out
268265
if locations_str:
269-
# Remove square brackets if they exist and then split by commas
270-
locations_str = locations_str.strip('[]') # Strip any square brackets
266+
locations_str = locations_str.strip('[]')
271267
locations = [int(loc) for loc in locations_str.split(',')] if locations_str else []
272268
else:
273269
locations = []

CargoHub/api/models/item_groups.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ def update(self, item_group_id, item_group):
9898
try:
9999
cursor = conn.cursor()
100100

101-
# Check if the client exists
102101
cursor.execute("SELECT * FROM item_groups WHERE id = ?", (item_group_id,))
103102
item_group_old = cursor.fetchone()
104103
if item_group_old is None:

CargoHub/api/models/item_lines.py

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ def update(self, item_line_id, item_line):
9898
try:
9999
cursor = conn.cursor()
100100

101-
# Check if the client exists
102101
cursor.execute("SELECT * FROM item_lines WHERE id = ?", (item_line_id,))
103102
item_line_old = cursor.fetchone()
104103
if item_line_old is None:

0 commit comments

Comments
 (0)