Modificato in una REST API con Flask
This commit is contained in:
@@ -19,5 +19,12 @@ class Department:
|
||||
def location_id(self) -> Location:
|
||||
return self.__location
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
'department_id': self.__department_id,
|
||||
'name': self.__name,
|
||||
'location': self.__location.to_json() if self.__location is not None else None
|
||||
}
|
||||
|
||||
def __str__(self):
|
||||
return f"Department({self.__department_id}, {self.__name}, {self.__location})"
|
||||
|
||||
@@ -18,8 +18,8 @@ class Person:
|
||||
|
||||
|
||||
class Employee(Person):
|
||||
def __init__(self, employee_id, first_name, last_name, email, phone_number,
|
||||
hire_date, department, job_id=0, salary=0, manager_id=0):
|
||||
def __init__(self, employee_id: int, first_name: str, last_name: str, email: str, phone_number: str,
|
||||
hire_date: date, department: Department, job_id: int = 0, salary: float = 0, manager_id: int = 0):
|
||||
super().__init__(first_name, last_name)
|
||||
self.__employee_id = employee_id
|
||||
self.__email = email
|
||||
@@ -62,6 +62,20 @@ class Employee(Person):
|
||||
def manager_id(self) -> int:
|
||||
return self.__manager_id
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
'employee_id': self.__employee_id,
|
||||
'first_name': self.first_name,
|
||||
'last_name': self.last_name,
|
||||
'email': self.__email,
|
||||
'hire_date': self.__hire_date,
|
||||
'department': self.__department.to_json() if self.__department is not None else None,
|
||||
'job_id': self.__job_id,
|
||||
# FIXME devo gestire meglio i tipi decimali
|
||||
'salary': str(self.__salary),
|
||||
'manager_id': self.__manager_id
|
||||
}
|
||||
|
||||
def __str__(self):
|
||||
return f"Employee({self.__employee_id}, {self.first_name}, {self.last_name}, " \
|
||||
f"{self.__email}, {self.__phone_number}, {self.__hire_date})"
|
||||
|
||||
@@ -32,6 +32,16 @@ class Location:
|
||||
def country_id(self) -> int:
|
||||
return self.__country_id
|
||||
|
||||
def to_json(self):
|
||||
return {
|
||||
'location_id': self.__location_id,
|
||||
'street_address': self.__street_address,
|
||||
'postal_code': self.__postal_code,
|
||||
'city': self.__city,
|
||||
'state_province': self.__state_province,
|
||||
'country_id': self.__country_id
|
||||
}
|
||||
|
||||
def __str__(self):
|
||||
return f"Location({self.__location_id}, {self.__postal_code}, " \
|
||||
f"{self.__street_address}, {self.__city}, {self.__state_province}) "
|
||||
|
||||
Reference in New Issue
Block a user