MCPcopy Index your code
hub / github.com/coder/coder / patchUserSkill

Method patchUserSkill

coderd/userskills.go:185–271  ·  view source on GitHub ↗

@Summary Update a user skill @ID update-a-user-skill @Security CoderSessionToken @Accept json @Produce json @Tags Users @Param user path string true "User ID, username, or me" @Param skillName path string true "Skill name" @Param request body codersdk.UpdateUserSkillRequest true "Update user skill r

(rw http.ResponseWriter, r *http.Request)

Source from the content-addressed store, hash-verified

183// @Router /api/experimental/users/{user}/skills/{skillName} [patch]
184// @x-apidocgen {"skip": true}
185func (api *API) patchUserSkill(rw http.ResponseWriter, r *http.Request) {
186 var (
187 ctx = r.Context()
188 user = httpmw.UserParam(r)
189 name = chi.URLParam(r, "skillName")
190 auditor = api.Auditor.Load()
191 aReq, commitAudit = audit.InitRequest[database.UserSkill](rw, &audit.RequestParams{
192 Audit: *auditor,
193 Log: api.Logger,
194 Request: r,
195 Action: database.AuditActionWrite,
196 })
197 )
198 defer commitAudit()
199
200 r.Body = http.MaxBytesReader(rw, r.Body, maxPersonalSkillRequestBytes)
201
202 var req codersdk.UpdateUserSkillRequest
203 if !httpapi.Read(ctx, rw, r, &req) {
204 return
205 }
206
207 parsedSkill, err := skills.ParsePersonalSkillMarkdown([]byte(req.Content))
208 if err != nil {
209 writeInvalidUserSkillContent(ctx, rw, err)
210 return
211 }
212 if parsedSkill.Name != name {
213 httpapi.Write(ctx, rw, http.StatusBadRequest, codersdk.Response{
214 Message: "Skill name in path does not match frontmatter name.",
215 Detail: fmt.Sprintf("path has %q, frontmatter has %q", name, parsedSkill.Name),
216 })
217 return
218 }
219
220 params := database.UpdateUserSkillByUserIDAndNameParams{
221 UserID: user.ID,
222 Name: name,
223 Description: parsedSkill.Description,
224 Content: req.Content,
225 }
226
227 var (
228 skill database.UserSkill
229 oldSkill database.UserSkill
230 )
231 err = api.Database.InTx(func(tx database.Store) error {
232 fetched, err := tx.GetUserSkillByUserIDAndName(ctx, database.GetUserSkillByUserIDAndNameParams{
233 UserID: user.ID,
234 Name: name,
235 })
236 if err != nil {
237 return xerrors.Errorf("fetch user skill: %w", err)
238 }
239
240 updated, err := tx.UpdateUserSkillByUserIDAndName(ctx, params)
241 if err != nil {
242 return xerrors.Errorf("update user skill: %w", err)

Callers

nothing calls this directly

Calls 15

UserParamFunction · 0.92
InitRequestFunction · 0.92
ReadFunction · 0.92
WriteFunction · 0.92
IsUnauthorizedErrorFunction · 0.92
ForbiddenFunction · 0.92
IsCheckViolationFunction · 0.92
Is404ErrorFunction · 0.92
ResourceNotFoundFunction · 0.92
InternalServerErrorFunction · 0.92
UserSkillFunction · 0.92

Tested by

no test coverage detected