调整路由以符合 RESTful 规范,新增 API Token 撤销功能
This commit is contained in:
@@ -97,7 +97,7 @@ func (h *BatchHandler) ListBatches(c *gin.Context) {
|
||||
// @Produce json
|
||||
// @Success 200 {object} model.Response{data=model.FileBatch}
|
||||
// @Failure 404 {object} model.Response
|
||||
// @Router /admin/batch/{batch_id} [get]
|
||||
// @Router /admin/batches/{batch_id} [get]
|
||||
func (h *BatchHandler) GetBatch(c *gin.Context) {
|
||||
id := c.Param("batch_id")
|
||||
var batch model.FileBatch
|
||||
@@ -119,7 +119,7 @@ func (h *BatchHandler) GetBatch(c *gin.Context) {
|
||||
// @Param request body UpdateBatchRequest true "修改内容"
|
||||
// @Success 200 {object} model.Response{data=model.FileBatch}
|
||||
// @Failure 400 {object} model.Response
|
||||
// @Router /admin/batch/{batch_id} [put]
|
||||
// @Router /admin/batches/{batch_id} [put]
|
||||
func (h *BatchHandler) UpdateBatch(c *gin.Context) {
|
||||
id := c.Param("batch_id")
|
||||
var batch model.FileBatch
|
||||
@@ -159,7 +159,7 @@ func (h *BatchHandler) UpdateBatch(c *gin.Context) {
|
||||
// @Produce json
|
||||
// @Success 200 {object} model.Response
|
||||
// @Failure 500 {object} model.Response
|
||||
// @Router /admin/batch/{batch_id} [delete]
|
||||
// @Router /admin/batches/{batch_id} [delete]
|
||||
func (h *BatchHandler) DeleteBatch(c *gin.Context) {
|
||||
idStr := c.Param("batch_id")
|
||||
id, _ := strconv.ParseUint(idStr, 10, 32)
|
||||
|
||||
@@ -80,6 +80,16 @@ func (h *TokenHandler) CreateToken(c *gin.Context) {
|
||||
}))
|
||||
}
|
||||
|
||||
// RevokeToken 撤销 API Token
|
||||
// @Summary 撤销 API Token
|
||||
// @Description 将 API Token 标记为已撤销,使其失效但保留记录
|
||||
// @Tags Admin
|
||||
// @Security AdminAuth
|
||||
// @Param id path int true "Token ID"
|
||||
// @Produce json
|
||||
// @Success 200 {object} model.Response
|
||||
// @Failure 500 {object} model.Response
|
||||
// @Router /admin/api-tokens/{id}/revoke [post]
|
||||
func (h *TokenHandler) RevokeToken(c *gin.Context) {
|
||||
id := c.Param("id")
|
||||
if err := bootstrap.DB.Model(&model.APIToken{}).Where("id = ?", id).Update("revoked", true).Error; err != nil {
|
||||
|
||||
Reference in New Issue
Block a user