Olen/Spond

Refactor and abstract out entity classes

Opened this issue · 2 comments

Olen commented

Just an idea for now, please give some feedback.

I have been thinking about some refactoring where we create new classes for e.g. SpondEvent, SpondPerson, SpondGroup. SpondMessage etc.

It would allow us to keep a stable API even if Spond should change stuff, and do more things in a more consistent way.

Something along the lines of

event = SpondEvent()
event.begin = "2023-01-30 13:00:00"
event.end = "2023-01-30 17:00:00"
event.name = "Race"
event.location = SpondLocation(address="Foo Street 123")
event.save()

After saving the event, the object is populated with an event.id.

You can change it later:

event = SpondEvent(event_id)
event.begin = "2023-01-27 14:00:00"
event.save()

There should also be some validations done (start < end etc) before saving.

And similar for persons, messages etc.

person = SpondPerson(person_id)
print(person.first_name)

It also allows for creating shortcuts for things like

class SpondPerson():
    ...
    @property
    def name(self):
        return f"{self.first_name} {self.last_name}"

I've actually written a partial implementation of this, as a separate, compatible package for now.

It only covers what I need for my read-only use cases, and I am sure it is naïve in some places. It was largely a learning exercise for me.

It sounds like I should make it public in case it is useful. I will do that in the next few days.

Initial, very partial release: https://github.com/elliot-100/Spond-classes