Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Expanding client api services #9

Open
wants to merge 19 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
19 commits
Select commit Hold shift + click to select a range
7437ea8
feat(InvoicesServices: implemented a get invoice and delete invoice f…
MoMo2Win Nov 8, 2024
422a22a
feat(InvoicesServices: implemented a get search and update invoices
MoMo2Win Nov 9, 2024
21a4414
feat(ClientServices): Implemented a service that could get a singular…
MoMo2Win Nov 10, 2024
92245df
feat(ClientServices): Implemented a service that could update and del…
MoMo2Win Nov 11, 2024
d299a0a
feat(ReceiptsServices): Created base model for receipts
MoMo2Win Nov 11, 2024
a8c703d
feat(ReceiptsServices): Implemented a service that creates receipts
MoMo2Win Nov 11, 2024
c26ef19
feat(ReceiptsServices): Implemented a service that lists all of the r…
MoMo2Win Nov 11, 2024
580af44
feat(ReceiptServices): Implemented a service that can search and upda…
MoMo2Win Nov 11, 2024
841f1c7
tests(InvoicesServices) - Implemented testing towards all of the Invo…
MoMo2Win Nov 16, 2024
df2ccd7
fix(InvoicesService): fix the update and search method invoice, so th…
MoMo2Win Nov 16, 2024
64dc816
fix(ClientService): fix the update function, so that they can choose …
MoMo2Win Nov 16, 2024
9a0818d
test(ClientService): Implemented testing for ClientsServices that inc…
MoMo2Win Nov 16, 2024
948bc36
test(ReceiptsServices): Implemented testing for all of its functions …
MoMo2Win Nov 16, 2024
6366d83
fix(Update): fixed the update function for invoice and clients, aswel…
MoMo2Win Nov 19, 2024
1d93995
feat(Api-Client): added patch and delete in MyfinanceClient
MoMo2Win Nov 19, 2024
249ec6d
Refactor(Client_Services): updated the function update_client to be l…
MoMo2Win Nov 20, 2024
76931d4
docs(Clients_service): Added comments to clarify the functions that i…
MoMo2Win Nov 20, 2024
f225859
docs(finance_services): Added comments to clarify the functions that …
MoMo2Win Nov 20, 2024
4c6b80e
Refactor(pyache): remove __pyache__ from the file
MoMo2Win Nov 24, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 4 additions & 2 deletions example/list_clients.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ def main():
response = client.clients.list_clients()
print(response.json())

response = client.clients.create_client(name="nerd")
response = client.clients.create_client(name="dock")

print(f"Created user with the ID of {response.data.client_id}")

Expand All @@ -18,5 +18,7 @@ def main():
response = client.clients.list_clients()
print(response.json())



if __name__ == "__main__":
main()
main()
Binary file removed myfinances/__pycache__/__init__.cpython-311.pyc
Binary file not shown.
Binary file removed myfinances/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file removed myfinances/__pycache__/base_service.cpython-312.pyc
Binary file not shown.
Binary file removed myfinances/__pycache__/client.cpython-312.pyc
Binary file not shown.
Binary file removed myfinances/__pycache__/main.cpython-311.pyc
Binary file not shown.
Binary file removed myfinances/__pycache__/models.cpython-312.pyc
Binary file not shown.
15 changes: 14 additions & 1 deletion myfinances/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,5 +32,18 @@ def _post(self, endpoint: str, json: dict):
response = self.session.post(url, json=json, headers=headers)
return MyFinancesResponse.from_http_response(response)

def _patch(self, endpoint: str, json: dict):
url = f"{self.base_url}{endpoint}"
headers = {"Authorization": f"Bearer {self.api_key}"}

response = self.session.patch(url, json=json, headers=headers)
return MyFinancesResponse.from_http_response(response)

def _delete(self, endpoint: str):
url = f"{self.base_url}{endpoint}"
headers = {"Authorization": f"Bearer {self.api_key}"}

response = self.session.delete(url, headers=headers)
return MyFinancesResponse.from_http_response(response)
def close(self):
self.session.close()
self.session.close()
Binary file removed myfinances/clients/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
101 changes: 86 additions & 15 deletions myfinances/clients/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,15 +3,15 @@
from pydantic import EmailStr

from myfinances.base_service import BaseService
from myfinances.clients.models import ClientIdResponse, ClientData
from myfinances.clients.models import ClientIdResponse, ClientData, Client
from myfinances.models import MyFinancesResponse


class ClientsService(BaseService):
def list_clients(
self,
order_by: Optional[str] = None,
search: Optional[str] = None
self,
order_by: Optional[str] = None,
search: Optional[str] = None
) -> MyFinancesResponse[ClientData]:
"""List clients under the specified team."""
params = {}
Expand All @@ -24,16 +24,16 @@ def list_clients(
return MyFinancesResponse(**response.dict())

def create_client(
self,
name: str,
phone_number: Optional[str] = None,
email: Optional[EmailStr] = None,
company: Optional[str] = None,
contact_method: Optional[str] = None,
is_representative: bool = False,
address: Optional[str] = None,
city: Optional[str] = None,
country: Optional[str] = None
self,
name: str,
phone_number: Optional[str] = None,
email: Optional[EmailStr] = None,
company: Optional[str] = None,
contact_method: Optional[str] = None,
is_representative: bool = False,
address: Optional[str] = None,
city: Optional[str] = None,
country: Optional[str] = None
) -> MyFinancesResponse[ClientIdResponse]:
"""List clients under the specified team."""
params = {
Expand All @@ -48,6 +48,77 @@ def create_client(
"country": country,
}

response = self._client._post("/clients/create/", params)
response = self._client._post("/clients/create/", json=params)

return MyFinancesResponse(**response.dict())

def get_client(self, client_id: int) -> MyFinancesResponse[Client]:
"""
Retrieving a singular client via their client_id.

Args:
client_id (int): The ID of the client to retrieve.

Returns:
MyFinancesResponse[Client]: Data of the client's details.

"""
response = self._client._get(f"/clients/{client_id}")
return MyFinancesResponse(**response.dict())

def update_client(self,
name: str = None,
phone_number: Optional[str] = None,
email: Optional[EmailStr] = None,
company: Optional[str] = None,
contact_method: Optional[str] = None,
is_representative: Optional[bool] = None,
address: Optional[str] = None,
city: Optional[str] = None,
country: Optional[str] = None) -> MyFinancesResponse[Client]:
"""
Updating an existing client's details, with the provided parameters

Args:
name (Optional[str]): name of the client to update
phone_number (Optional[str]): client's phone number to update
email (Optional[EmailStr]): client's email address to update
company (Optional[str]): client's company name to update
contact_method (Optional[str]): client's preferred contact to update
is_representative (Optional[bool]): to update the client if they are representative
address (Optional[str]): client's address to update
city (Optional[str]): client's location in the city to update
country (Optional[str]): client's country location to update

Returns:
MyFinancesResponse[Client]: Data of the client's details is updated
"""
params = {
key: value for key, value in {
"name": name,
"phone_number": phone_number,
"email": email,
"company": company,
"contact_method": contact_method,
"is_representative": is_representative,
"address": address,
"city": city,
"country": country,
}.items() if value is not None
}

response = self._client._patch("/clients/update/", json=params)
return MyFinancesResponse(**response.dict())

def delete_client(self, client_id: int) -> MyFinancesResponse[Client]:
"""
Deletion of a specific client

Args:
client_id (int): client's id

Returns:
MyFinancesResponse[Client]: Confirming the deletion of the client
"""
response = self._client._delete(f"/clients/{client_id}/delete")
return MyFinancesResponse(**response.dict())
Binary file removed myfinances/finance/__pycache__/__init__.cpython-312.pyc
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
4 changes: 3 additions & 1 deletion myfinances/finance/invoices/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,13 @@ class Invoice(BaseModel):
due_date: Optional[str] = None
description: Optional[str] = None


class CreateInvoiceResponse(BaseModel):
customer_id: int
amount: condecimal(gt=0)
description: Optional[str] = None
due_date: Optional[str] = None


class InvoiceList(BaseModel):
invoices: List[Invoice]
invoices: List[Invoice]
78 changes: 75 additions & 3 deletions myfinances/finance/invoices/service.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
from myfinances.base_service import BaseService
from myfinances.finance.invoices.models import InvoiceList, CreateInvoiceResponse
from myfinances.finance.invoices.models import InvoiceList, CreateInvoiceResponse, Invoice
from myfinances.models import MyFinancesResponse


Expand All @@ -14,10 +14,82 @@ def create_invoice(self,
}

response = self._client._post("/invoices/create", json=payload)

return MyFinancesResponse(**response.dict())


def list_invoices(self) -> MyFinancesResponse[InvoiceList]:
response = self._client._get(f"/invoices/")
return MyFinancesResponse(**response.dict())

def get_invoice(self, invoice_id: int) -> MyFinancesResponse[Invoice]:
"""
Gathering a specific Invoice by ID

Args:
invoice_id (int): Invoice ID

Returns:
MyFinancesResponse[Client]: Invoice details
"""
response = self._client._get(f"/invoices/{invoice_id}/")
return MyFinancesResponse(**response.dict())

def delete_invoice(self, invoice_id: int) -> MyFinancesResponse[Invoice]:
"""
Delete a specific Invoice by ID

Args:
invoice_id (int): Invoice ID

Returns:
MyFinancesResponse[Invoice]: Deleting the specified Invoice
"""
response = self._client._delete(f"/invoices/{invoice_id}/delete")
return MyFinancesResponse(**response.dict())

def search_invoices(self, customer_id: int = None, status: str = None) -> MyFinancesResponse[InvoiceList]:
"""
Search for a specific Invoice by use of filters

Args:
customer_id (int): Customer ID
status (str): Invoice status

Returns:
MyFinancesResponse[InvoiceList]: invoice list with the specified filters
"""
params = {}

if customer_id is not None:
params["customer_id"] = customer_id

if status is not None:
params["status"] = status

response = self._client._get(f"/invoices/search", params=params)
return MyFinancesResponse(**response.dict())

def update_invoice(self, customer_id: int, amount: float = None, description: str = None, due_date: str = None, status: str = None ) -> MyFinancesResponse[Invoice]:
"""
Updating an existing Invoice

Args:
customer_id (int): customer's ID
amount (float): Invoice total amount to be change
description (str): Invoice description to be change
due_date (str): due date of the invoice to be changed
status (str): Invoice status to be changed

Returns:
MyFinancesResponse[Invoice]: updating an existing invoice's details
"""
params = {
key: value for key, value in{
"amount": amount,
"description": description,
"due_date": due_date,
"status": status,
}.items() if value is not None
}

response = self._client._patch(f"/invoices/{customer_id}/update", json=params)
return MyFinancesResponse(**response.dict())
Empty file.
21 changes: 21 additions & 0 deletions myfinances/finance/receipts/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
from pydantic import BaseModel, FilePath, condecimal
from typing import Optional, List


class Receipt(BaseModel):
id: int
name: str
image: FilePath
date: Optional[str] = None
merchant_store: Optional[str] = None
purchase_category: Optional[str] = None
total_price: condecimal(gt=0)
owner: Optional[str] = None


class ReceiptList(BaseModel):
receipts: List[Receipt]


class ReceiptIDResponse(BaseModel):
receipt_id: int
Loading