(e *core.RequestEvent)
| 76 | } |
| 77 | |
| 78 | func collectionCreate(e *core.RequestEvent) error { |
| 79 | // populate the minimal required factory collection data (if any) |
| 80 | factoryExtract := struct { |
| 81 | Type string `form:"type" json:"type"` |
| 82 | Name string `form:"name" json:"name"` |
| 83 | }{} |
| 84 | if err := e.BindBody(&factoryExtract); err != nil { |
| 85 | return e.BadRequestError("Failed to load the collection type data due to invalid formatting.", err) |
| 86 | } |
| 87 | |
| 88 | // create scaffold |
| 89 | collection := core.NewCollection(factoryExtract.Type, factoryExtract.Name) |
| 90 | |
| 91 | // merge the scaffold with the submitted request data |
| 92 | if err := e.BindBody(collection); err != nil { |
| 93 | return e.BadRequestError("Failed to load the submitted data due to invalid formatting.", err) |
| 94 | } |
| 95 | |
| 96 | event := new(core.CollectionRequestEvent) |
| 97 | event.RequestEvent = e |
| 98 | event.Collection = collection |
| 99 | |
| 100 | return e.App.OnCollectionCreateRequest().Trigger(event, func(e *core.CollectionRequestEvent) error { |
| 101 | if err := e.App.Save(e.Collection); err != nil { |
| 102 | // validation failure |
| 103 | var validationErrors validation.Errors |
| 104 | if errors.As(err, &validationErrors) { |
| 105 | return e.BadRequestError("Failed to create collection.", validationErrors) |
| 106 | } |
| 107 | |
| 108 | // other generic db error |
| 109 | return e.BadRequestError("Failed to create collection. Raw error: \n"+err.Error(), nil) |
| 110 | } |
| 111 | |
| 112 | return execAfterSuccessTx(true, e.App, func() error { |
| 113 | return e.JSON(http.StatusOK, e.Collection) |
| 114 | }) |
| 115 | }) |
| 116 | } |
| 117 | |
| 118 | func collectionUpdate(e *core.RequestEvent) error { |
| 119 | collection, err := e.App.FindCollectionByNameOrId(e.Request.PathValue("collection")) |
nothing calls this directly
no test coverage detected
searching dependent graphs…