UpdateProjectWebhook updates an instance of ProjectWebhook.
(ctx context.Context, projectResourceID string, webhookResourceID string, update *UpdateProjectWebhookMessage)
| 172 | |
| 173 | // UpdateProjectWebhook updates an instance of ProjectWebhook. |
| 174 | func (s *Store) UpdateProjectWebhook(ctx context.Context, projectResourceID string, webhookResourceID string, update *UpdateProjectWebhookMessage) (*ProjectWebhookMessage, error) { |
| 175 | var payload []byte |
| 176 | if update.Payload != nil { |
| 177 | p, err := protojson.Marshal(update.Payload) |
| 178 | if err != nil { |
| 179 | return nil, errors.Wrapf(err, "failed to marshal payload") |
| 180 | } |
| 181 | payload = p |
| 182 | } |
| 183 | |
| 184 | q := qb.Q().Space(` |
| 185 | UPDATE project_webhook |
| 186 | SET payload = ? |
| 187 | WHERE resource_id = ? |
| 188 | RETURNING resource_id, project, payload |
| 189 | `, payload, webhookResourceID) |
| 190 | |
| 191 | query, args, err := q.ToSQL() |
| 192 | if err != nil { |
| 193 | return nil, errors.Wrapf(err, "failed to build sql") |
| 194 | } |
| 195 | |
| 196 | projectWebhook := ProjectWebhookMessage{ |
| 197 | Payload: &storepb.ProjectWebhook{}, |
| 198 | } |
| 199 | var returnedPayload []byte |
| 200 | // Execute update query with RETURNING. |
| 201 | if err := s.GetDB().QueryRowContext(ctx, query, args...).Scan( |
| 202 | &projectWebhook.ResourceID, |
| 203 | &projectWebhook.ProjectID, |
| 204 | &returnedPayload, |
| 205 | ); err != nil { |
| 206 | if err == sql.ErrNoRows { |
| 207 | return nil, &common.Error{Code: common.NotFound, Err: errors.Errorf("project hook not found: %s", webhookResourceID)} |
| 208 | } |
| 209 | return nil, err |
| 210 | } |
| 211 | |
| 212 | if err := common.ProtojsonUnmarshaler.Unmarshal(returnedPayload, projectWebhook.Payload); err != nil { |
| 213 | return nil, errors.Wrapf(err, "failed to unmarshal") |
| 214 | } |
| 215 | |
| 216 | s.removeProjectCache(projectResourceID) |
| 217 | return &projectWebhook, nil |
| 218 | } |
| 219 | |
| 220 | // DeleteProjectWebhook deletes an existing projectWebhook by resource ID. |
| 221 | func (s *Store) DeleteProjectWebhook(ctx context.Context, projectResourceID string, webhookResourceID string) error { |
no test coverage detected