MCPcopy Create free account
hub / github.com/PerpetualSoftware/pad / appCreateItem

Method appCreateItem

internal/server/app_api_write.go:144–174  ·  view source on GitHub ↗
(w http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

142}
143
144func (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

Callers

nothing calls this directly

Calls 15

appVisibleCollectionMethod · 0.95
requireEditPermissionMethod · 0.95
appReadmitBeforeWriteMethod · 0.95
appStoreMethod · 0.95
appContextFromFunction · 0.85
decodeAppJSONFunction · 0.85
writeErrorFunction · 0.85
writeInternalErrorFunction · 0.85
appActorFunction · 0.85
writeAppStoreErrorFunction · 0.85
appActorKindFunction · 0.85

Tested by

no test coverage detected