mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* route updated_at * add app created at, fix some route updated_at bugs * add app updated_at TODO need to add tests through front end TODO for validation we don't really want to use the validate wrapper since it's a programmer error and not a user error, hopefully tests block this. * add tests for timestamps to exist / change on apps&routes * route equals at done, fix tests wit dis * fix up the equals sugar * add swagger * fix rebase * precisely allocate maps in clone * vetted * meh * fix api tests
53 lines
891 B
Go
53 lines
891 B
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/fnproject/fn/api/models"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
func (s *Server) handleAppCreate(c *gin.Context) {
|
|
ctx := c.Request.Context()
|
|
|
|
var wapp models.AppWrapper
|
|
|
|
err := c.BindJSON(&wapp)
|
|
if err != nil {
|
|
handleErrorResponse(c, models.ErrInvalidJSON)
|
|
return
|
|
}
|
|
|
|
app := wapp.App
|
|
if app == nil {
|
|
handleErrorResponse(c, models.ErrAppsMissingNew)
|
|
return
|
|
}
|
|
|
|
app.SetDefaults()
|
|
if err = app.Validate(); err != nil {
|
|
handleErrorResponse(c, err)
|
|
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})
|
|
}
|