akmolina28
1 week ago

Properly tie a model to a google calendar event?

Posted 1 week ago by akmolina28

Hello,

I'm working on a project involving google calendar events and I'm trying to figure out a good, testable code structure. I have a model that should always have a google calendar event tied to it, let's call it MyEvent.

Currently, I store a reference to the google calendar object as a field in the MyEvent model, persisted in the database. I hook into the model saving event to insert/update the google calendar event any time the MyEvent model is created or saved. If the API fails, then the model won't be saved. Hopefully this way, everything stays in sync. It's also worth noting that I am resolving the google API from a service container in the model.

Is there a better pattern for keeping a model in sync with a third party API like google calendar? I also considered breaking out a separate Model just for the google calendar event object, but that seemed like an unnecessary complication. I'm curious for other ideas.

Thanks!

Please sign in or create an account to participate in this conversation.