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)
| 327 | // @Success 200 {object} model.CommonResponse{data=model.Prompt} "成功" |
| 328 | // @Router /api/prompts/{pid} [get] |
| 329 | func 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 更新提示词 |
nothing calls this directly
no test coverage detected