TreyWW / MyFinances

MyFinances is a web application that can help you as an individual, or team, manage your finances!
https://docs.myfinances.cloud
GNU Affero General Public License v3.0
91 stars 134 forks source link

cleanup: Service Layer improvement #442

Closed TreyWW closed 1 month ago

TreyWW commented 1 month ago

How big is this feature?

Medium

Describe the problem

Our service layer, backend/service/ has a few different kinds of approaches for defining functions, returning errors, logging, etc. But I no longer want this.

I want every service file to follow the same structure, return the same way, and log every step. (python console logging).

Describe a possible solution

Make every service layer folder, and files, be structured in a similar way, have a document (in the docs) so that all follow a similar approach and return a better response to the view.

TreyWW commented 1 month ago

An example is the clients creation endpoint + service.

https://github.com/TreyWW/MyFinances/blob/main/backend/views/core/clients/create.py https://github.com/TreyWW/MyFinances/blob/main/backend/service/clients/create.py

At the moment we respond with a Client | str, if a client object than success, if a string then error. But this isn't obvious from a new contributors first look.

Instead, we could use objects, like in the reminders.py where we have a dataclass. But instead of a seperate success response and error response, what about a central base class, that handles error, success, object returns, etc.

That way may we can do like if service_response.success: xyz elseprint(service_response.error)`.

Hopefully this makes sense @brainycarp67531, I can add more detail if you wish, just let me know what parts you may need clarity on! :)

brainycarp67531 commented 1 month ago

I will have a look at it, I will get back to you if I have nay questions.

TreyWW commented 1 month ago

Sure thing! Thanks 👍🏽

Feel free to join our discord and get setting up info on our documentation page

brainycarp67531 commented 1 month ago

Hi @TreyWW,

This task was a little bit over my skill level. Thank you for the opportunity to contribute, but I am not able to finish this task. Sorry for the inconvenience.

TreyWW commented 1 month ago

No problem at all! Thanks for stopping by :)

Let me know if you would like to work on any other issues or features