(w http.ResponseWriter, r *http.Request)
| 142 | } |
| 143 | |
| 144 | func (s *Server) appCreateItem(w http.ResponseWriter, r *http.Request) { |
| 145 | ac := appContextFrom(r) |
| 146 | c, ok := s.appVisibleCollection(w, r, chi.URLParam(r, "collSlug")) |
| 147 | if !ok { |
| 148 | return |
| 149 | } |
| 150 | if !s.requireEditPermission(w, r, ac.WorkspaceID, "", c.ID) { |
| 151 | return |
| 152 | } |
| 153 | var in AppItemCreateRequest |
| 154 | if err := decodeAppJSON(r, &in); err != nil { |
| 155 | writeError(w, http.StatusBadRequest, "bad_request", err.Error()) |
| 156 | return |
| 157 | } |
| 158 | if !s.appReadmitBeforeWrite(w, r, "", c.ID) { |
| 159 | return |
| 160 | } |
| 161 | as, err := s.appStore() |
| 162 | if err != nil { |
| 163 | writeInternalError(w, err) |
| 164 | return |
| 165 | } |
| 166 | wr, err := as.CreateItemWrite(r.Context(), ac.appFenceSpec(), c.ID, appstore.AppItemCreate{Title: in.Title, Content: in.Content, Fields: in.Fields}, appActor(ac)) |
| 167 | if err != nil { |
| 168 | writeAppStoreError(w, err) |
| 169 | return |
| 170 | } |
| 171 | item := wr.Item |
| 172 | s.publishItemEventWithName(sseItemCreated, ac.WorkspaceID, item.ID, item.Title, wr.View.CollectionSlug, appActorKind(ac), wr.ActorDisplay, "app", item.Seq) |
| 173 | writeAppJSON(w, http.StatusCreated, appWrittenItemDTO(wr)) |
| 174 | } |
| 175 | |
| 176 | // appWrittenItemDTO is a write's response, built only from what the write's |
| 177 | // own transaction read (appstore.ItemWrite). Nothing here touches the |
nothing calls this directly
no test coverage detected