切换批次和文件的 ID 类型为 UUID,更新相关逻辑和文档

This commit is contained in:
2026-01-14 13:30:50 +08:00
parent 5160ae78cc
commit 1ffa16cf48
11 changed files with 66 additions and 59 deletions

View File

@@ -93,7 +93,7 @@ func (h *BatchHandler) ListBatches(c *gin.Context) {
// @Description 根据批次 ID 获取批次信息及关联的文件列表
// @Tags Admin
// @Security AdminAuth
// @Param batch_id path int true "批次 ID"
// @Param batch_id path string true "批次 ID (UUID)"
// @Produce json
// @Success 200 {object} model.Response{data=model.FileBatch}
// @Failure 404 {object} model.Response
@@ -101,7 +101,7 @@ func (h *BatchHandler) ListBatches(c *gin.Context) {
func (h *BatchHandler) GetBatch(c *gin.Context) {
id := c.Param("batch_id")
var batch model.FileBatch
if err := bootstrap.DB.Preload("FileItems").First(&batch, id).Error; err != nil {
if err := bootstrap.DB.Preload("FileItems").First(&batch, "id = ?", id).Error; err != nil {
c.JSON(http.StatusNotFound, model.ErrorResponse(model.CodeNotFound, "batch not found"))
return
}
@@ -115,7 +115,7 @@ func (h *BatchHandler) GetBatch(c *gin.Context) {
// @Security AdminAuth
// @Accept json
// @Produce json
// @Param batch_id path int true "批次 ID"
// @Param batch_id path string true "批次 ID (UUID)"
// @Param request body UpdateBatchRequest true "修改内容"
// @Success 200 {object} model.Response{data=model.FileBatch}
// @Failure 400 {object} model.Response
@@ -123,7 +123,7 @@ func (h *BatchHandler) GetBatch(c *gin.Context) {
func (h *BatchHandler) UpdateBatch(c *gin.Context) {
id := c.Param("batch_id")
var batch model.FileBatch
if err := bootstrap.DB.First(&batch, id).Error; err != nil {
if err := bootstrap.DB.First(&batch, "id = ?", id).Error; err != nil {
c.JSON(http.StatusNotFound, model.ErrorResponse(model.CodeNotFound, "batch not found"))
return
}
@@ -155,16 +155,15 @@ func (h *BatchHandler) UpdateBatch(c *gin.Context) {
// @Description 标记批次为已删除,并物理删除关联的存储文件
// @Tags Admin
// @Security AdminAuth
// @Param batch_id path int true "批次 ID"
// @Param batch_id path string true "批次 ID (UUID)"
// @Produce json
// @Success 200 {object} model.Response
// @Failure 500 {object} model.Response
// @Router /admin/batches/{batch_id} [delete]
func (h *BatchHandler) DeleteBatch(c *gin.Context) {
idStr := c.Param("batch_id")
id, _ := strconv.ParseUint(idStr, 10, 32)
id := c.Param("batch_id")
if err := h.batchService.DeleteBatch(c.Request.Context(), uint(id)); err != nil {
if err := h.batchService.DeleteBatch(c.Request.Context(), id); err != nil {
c.JSON(http.StatusInternalServerError, model.ErrorResponse(model.CodeInternalError, err.Error()))
return
}

View File

@@ -103,6 +103,11 @@ func (h *PickupHandler) Pickup(c *gin.Context) {
return
}
if batch.Type == "text" {
h.batchService.IncrementDownloadCount(batch.ID)
batch.DownloadCount++
}
c.JSON(http.StatusOK, model.SuccessResponse(PickupResponse{
Remark: batch.Remark,
ExpireAt: batch.ExpireAt,
@@ -119,24 +124,23 @@ func (h *PickupHandler) Pickup(c *gin.Context) {
// @Summary 下载单个文件
// @Description 根据文件 ID 下载单个文件
// @Tags Public
// @Param file_id path int true "文件 ID"
// @Param file_id path string true "文件 ID (UUID)"
// @Produce application/octet-stream
// @Success 200 {file} file
// @Failure 404 {object} model.Response
// @Failure 410 {object} model.Response
// @Router /api/files/{file_id}/download [get]
func (h *PickupHandler) DownloadFile(c *gin.Context) {
fileIDStr := c.Param("file_id")
fileID, _ := strconv.ParseUint(fileIDStr, 10, 32)
fileID := c.Param("file_id")
var item model.FileItem
if err := bootstrap.DB.First(&item, fileID).Error; err != nil {
if err := bootstrap.DB.First(&item, "id = ?", fileID).Error; err != nil {
c.JSON(http.StatusNotFound, model.ErrorResponse(model.CodeNotFound, "file not found"))
return
}
var batch model.FileBatch
if err := bootstrap.DB.First(&batch, item.BatchID).Error; err != nil {
if err := bootstrap.DB.First(&batch, "id = ?", item.BatchID).Error; err != nil {
c.JSON(http.StatusNotFound, model.ErrorResponse(model.CodeNotFound, "batch not found"))
return
}

View File

@@ -24,7 +24,7 @@ func NewUploadHandler() *UploadHandler {
type UploadResponse struct {
PickupCode string `json:"pickup_code"`
ExpireAt *time.Time `json:"expire_at"`
BatchID uint `json:"batch_id"`
BatchID string `json:"batch_id"`
}
// Upload 上传文件并生成取件码