mirror of
https://github.com/fnproject/fn.git
synced 2022-10-28 21:29:17 +03:00
51 lines
889 B
Go
51 lines
889 B
Go
package server
|
|
|
|
import (
|
|
"net/http"
|
|
|
|
"github.com/gin-gonic/gin"
|
|
"gitlab-odx.oracle.com/odx/functions/api/models"
|
|
)
|
|
|
|
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
|
|
}
|
|
|
|
if wapp.App == nil {
|
|
handleErrorResponse(c, models.ErrAppsMissingNew)
|
|
return
|
|
}
|
|
|
|
if err = wapp.Validate(); err != nil {
|
|
handleErrorResponse(c, err)
|
|
return
|
|
}
|
|
|
|
err = s.FireBeforeAppCreate(ctx, wapp.App)
|
|
if err != nil {
|
|
handleErrorResponse(c, err)
|
|
return
|
|
}
|
|
|
|
app, err := s.Datastore.InsertApp(ctx, wapp.App)
|
|
if err != nil {
|
|
handleErrorResponse(c, err)
|
|
return
|
|
}
|
|
|
|
err = s.FireAfterAppCreate(ctx, wapp.App)
|
|
if err != nil {
|
|
handleErrorResponse(c, err)
|
|
return
|
|
}
|
|
|
|
c.JSON(http.StatusOK, appResponse{"App successfully created", app})
|
|
}
|