(c *gin.Context)
| 10 | ) |
| 11 | |
| 12 | func (s *Server) handleAppCreate(c *gin.Context) { |
| 13 | ctx := c.MustGet("ctx").(context.Context) |
| 14 | log := common.Logger(ctx) |
| 15 | |
| 16 | var wapp models.AppWrapper |
| 17 | |
| 18 | err := c.BindJSON(&wapp) |
| 19 | if err != nil { |
| 20 | log.WithError(err).Debug(models.ErrInvalidJSON) |
| 21 | c.JSON(http.StatusBadRequest, simpleError(models.ErrInvalidJSON)) |
| 22 | return |
| 23 | } |
| 24 | |
| 25 | if wapp.App == nil { |
| 26 | log.Debug(models.ErrAppsMissingNew) |
| 27 | c.JSON(http.StatusBadRequest, simpleError(models.ErrAppsMissingNew)) |
| 28 | return |
| 29 | } |
| 30 | |
| 31 | if err := wapp.Validate(); err != nil { |
| 32 | log.Error(err) |
| 33 | c.JSON(http.StatusInternalServerError, simpleError(err)) |
| 34 | return |
| 35 | } |
| 36 | |
| 37 | err = s.FireBeforeAppCreate(ctx, wapp.App) |
| 38 | if err != nil { |
| 39 | log.WithError(err).Error(models.ErrAppsCreate) |
| 40 | c.JSON(http.StatusInternalServerError, simpleError(err)) |
| 41 | return |
| 42 | } |
| 43 | |
| 44 | app, err := s.Datastore.InsertApp(ctx, wapp.App) |
| 45 | if err != nil { |
| 46 | handleErrorResponse(c, err) |
| 47 | return |
| 48 | } |
| 49 | |
| 50 | err = s.FireAfterAppCreate(ctx, wapp.App) |
| 51 | if err != nil { |
| 52 | log.WithError(err).Error(models.ErrAppsCreate) |
| 53 | c.JSON(http.StatusInternalServerError, simpleError(err)) |
| 54 | return |
| 55 | } |
| 56 | |
| 57 | c.JSON(http.StatusOK, appResponse{"App successfully created", app}) |
| 58 | } |
nothing calls this directly
no test coverage detected