MCPcopy Create free account
hub / github.com/53AI/53AIHub / GetPrompt

Function GetPrompt

api/controller/prompt.go:329–380  ·  view source on GitHub ↗

GetPrompt 获取单个提示词 @Summary 获取单个提示词 @Description 根据ID获取提示词详情 @Tags Prompt @Produce json @Security BearerAuth @Param pid path int true "提示词ID" @Success 200 {object} model.CommonResponse{data=model.Prompt} "成功" @Router /api/prompts/{pid} [get]

(c *gin.Context)

Source from the content-addressed store, hash-verified

327// @Success 200 {object} model.CommonResponse{data=model.Prompt} "成功"
328// @Router /api/prompts/{pid} [get]
329func GetPrompt(c *gin.Context) {
330 promptID, err := strconv.Atoi(c.Param("pid"))
331 if err != nil {
332 c.JSON(http.StatusBadRequest, model.ParamError.ToResponse(nil))
333 return
334 }
335
336 var eid int64
337 user, err := model.GetLoginUser(c)
338 if err == nil {
339 eid = user.Eid
340 } else {
341 eid = config.GetEID(c)
342 }
343 prompt, err := model.GetPromptByID(promptID)
344 if err != nil {
345 c.JSON(http.StatusNotFound, model.NotFound.ToResponse(nil))
346 return
347 }
348
349 // 检查提示词是否属于当前企业
350 if prompt.Eid != eid {
351 c.JSON(http.StatusNotFound, model.NotFound.ToResponse(nil))
352 return
353 }
354
355 // 加载提示词的分组信息
356 if err := prompt.LoadPromptGroups(); err != nil {
357 c.JSON(http.StatusInternalServerError, model.DBError.ToResponse(nil))
358 return
359 }
360
361 // 反序列化 AILinks 字段
362 var links []model.AILinkInfo
363 if prompt.AILinks != "" {
364 if err := json.Unmarshal([]byte(prompt.AILinks), &links); err != nil {
365 // 记录日志并使用默认值
366 links = []model.AILinkInfo{}
367 }
368 }
369 prompt.AILinksData = links
370
371 if err := prompt.LoadIsLiked(config.GetUserId(c)); err != nil {
372 c.JSON(http.StatusInternalServerError, model.DBError.ToResponse(nil))
373 return
374 }
375
376 prompt.Views++
377 prompt.Update()
378
379 c.JSON(http.StatusOK, model.Success.ToResponse(prompt))
380}
381
382// UpdatePrompt 更新提示词
383// @Summary 更新提示词

Callers

nothing calls this directly

Calls 5

ToResponseMethod · 0.80
GetEIDMethod · 0.80
LoadPromptGroupsMethod · 0.80
LoadIsLikedMethod · 0.80
UpdateMethod · 0.65

Tested by

no test coverage detected