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

Method appUpdateItem

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

Source from the content-addressed store, hash-verified

191}
192
193func (s *Server) appUpdateItem(w http.ResponseWriter, r *http.Request) {
194 ac := appContextFrom(r)
195 before, _, ok := s.appVisibleItem(w, r)
196 if !ok {
197 return
198 }
199 if !s.requireEditPermission(w, r, ac.WorkspaceID, before.ID, before.CollectionID) {
200 return
201 }
202 var in AppItemUpdateRequest
203 if err := decodeAppJSON(r, &in); err != nil {
204 writeError(w, http.StatusBadRequest, "bad_request", err.Error())
205 return
206 }
207 if !s.appReadmitBeforeWrite(w, r, before.ID, before.CollectionID) {
208 return
209 }
210 as, err := s.appStore()
211 if err != nil {
212 writeInternalError(w, err)
213 return
214 }
215 wr, err := as.UpdateItemWrite(r.Context(), ac.appFenceSpec(), before.ID, appstore.AppItemUpdate{FieldsPatch: in.FieldsPatch, ExpectedETag: in.ExpectedETag}, appActor(ac))
216 if err != nil {
217 writeAppStoreError(w, err)
218 return
219 }
220 after := wr.Item
221 s.publishItemEventWithName(sseItemUpdated, ac.WorkspaceID, after.ID, after.Title, wr.View.CollectionSlug, appActorKind(ac), wr.ActorDisplay, "app", after.Seq)
222 // Watchers hear about an app's status change as about anyone's. The signal is the fenced
223 // transaction's own, never a comparison with this handler's earlier read: a status another writer
224 // changed between that read and the commit is not this write's.
225 if after.LastMutation != nil && after.LastMutation.StatusChanged {
226 s.publishWatchNotifications(ac.WorkspaceID, after, appActorKind(ac), wr.ActorDisplay)
227 }
228 writeAppJSON(w, http.StatusOK, appWrittenItemDTO(wr))
229}
230
231// appCommentDTO is one comment's DTO, written by this request's actor.
232func appCommentDTO(c *models.Comment, authorKind string) AppComment {

Callers

nothing calls this directly

Calls 15

appVisibleItemMethod · 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

Tested by

no test coverage detected