mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
* push validate/defaults into datastore we weren't setting a timestamp in route insert when we needed to create an app there. that whole thing isn't atomic, but this fixes the timestamp issue. closes #738 seems like we should do similar with the FireBeforeX stuff too. * fix tests * app name validation was buggy, an upper cased letter failed. now it doesn't. uses unicode now. * removes duplicate errors for datastore and models validation that were used interchangably but weren't.
51 lines
867 B
Go
51 lines
867 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 {
|
|
if models.IsAPIError(err) {
|
|
handleErrorResponse(c, err)
|
|
} else {
|
|
handleErrorResponse(c, models.ErrInvalidJSON)
|
|
}
|
|
return
|
|
}
|
|
|
|
app := wapp.App
|
|
if app == nil {
|
|
handleErrorResponse(c, models.ErrAppsMissingNew)
|
|
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})
|
|
}
|