mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
push down app listeners to a datastore (#742)
* push down app listeners to a datastore fnext.NewDatastore returns a datastore that wraps the appropriate methods for AppListener in a Datastore implementation. this is more future proof than needing to wrap every call of GetApp/UpdateApp/etc with the listeners, there are a few places where this can happen and it seems like the AppListener behavior is supposed to wrap the datastore, not just the front end methods surrounding CRUD ops on an app. the hairy case that came up was when fiddling with the create/update route business. this changes the FireBeforeApp* ops to be an AppListener implementation itself rather than having the Server itself expose certain methods to fire off the app listeners, now they're on the datastore itself, which the server can return the instance of. small change to BeforeAppDelete/AfterAppDelete -- we were passing in a half baked struct with only the name filled in and not filling in the fields anywhere. this is mostly just misleading, we could fill in the app, but we weren't and don't really want to, it's more to notify of an app deletion event so that an extension can behave accordingly instead of letting a user inspect the app. i know of 3 extensions and the changes required to update are very small. cleans up all the front end implementations FireBefore/FireAfter. this seems potentially less flexible than previous version if we do want to allow users some way to call the database methods without using the extensions, but that's exactly the trade off, as far as the AppListener's are described it seems heavily implied that this should be the case. mostly a feeler, for the above reasons, but this was kind of odorous so just went for it. we do need to lock in the extension api stuff. * hand em an app that's been smokin the reefer
This commit is contained in:
@@ -28,23 +28,11 @@ func (s *Server) handleAppCreate(c *gin.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
err = s.FireBeforeAppCreate(ctx, app)
|
||||
if err != nil {
|
||||
handleErrorResponse(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
app, err = s.datastore.InsertApp(ctx, app)
|
||||
if err != nil {
|
||||
handleErrorResponse(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
err = s.FireAfterAppCreate(ctx, app)
|
||||
if err != nil {
|
||||
handleErrorResponse(c, err)
|
||||
return
|
||||
}
|
||||
|
||||
c.JSON(http.StatusOK, appResponse{"App successfully created", app})
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user