|
| 1 | +/* |
| 2 | + * Copyright 2025 The Dragonfly Authors |
| 3 | + * |
| 4 | + * Licensed under the Apache License, Version 2.0 (the "License"); |
| 5 | + * you may not use this file except in compliance with the License. |
| 6 | + * You may obtain a copy of the License at |
| 7 | + * |
| 8 | + * http://www.apache.org/licenses/LICENSE-2.0 |
| 9 | + * |
| 10 | + * Unless required by applicable law or agreed to in writing, software |
| 11 | + * distributed under the License is distributed on an "AS IS" BASIS, |
| 12 | + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 13 | + * See the License for the specific language governing permissions and |
| 14 | + * limitations under the License. |
| 15 | + */ |
| 16 | + |
| 17 | +package handlers |
| 18 | + |
| 19 | +import ( |
| 20 | + "net/http" |
| 21 | + |
| 22 | + "github.com/gin-gonic/gin" |
| 23 | + |
| 24 | + // nolint |
| 25 | + _ "d7y.io/dragonfly/v2/manager/models" |
| 26 | + "d7y.io/dragonfly/v2/manager/types" |
| 27 | +) |
| 28 | + |
| 29 | +// @Summary Get Audits |
| 30 | +// @Description Get Audits |
| 31 | +// @Tags Audit |
| 32 | +// @Accept json |
| 33 | +// @Produce json |
| 34 | +// @Param page query int true "current page" default(0) |
| 35 | +// @Param per_page query int true "return max item count, default 10, max 50" default(10) minimum(2) maximum(50) |
| 36 | +// @Success 200 {object} []models.Audit |
| 37 | +// @Failure 400 |
| 38 | +// @Failure 404 |
| 39 | +// @Failure 500 |
| 40 | +// @Router /api/v1/audits [get] |
| 41 | +func (h *Handlers) GetAudits(ctx *gin.Context) { |
| 42 | + var query types.GetAuditsQuery |
| 43 | + if err := ctx.ShouldBindQuery(&query); err != nil { |
| 44 | + ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()}) |
| 45 | + return |
| 46 | + } |
| 47 | + |
| 48 | + h.setPaginationDefault(&query.Page, &query.PerPage) |
| 49 | + audits, count, err := h.service.GetAudits(ctx.Request.Context(), query) |
| 50 | + if err != nil { |
| 51 | + ctx.Error(err) //nolint: errcheck |
| 52 | + return |
| 53 | + } |
| 54 | + |
| 55 | + h.setPaginationLinkHeader(ctx, query.Page, query.PerPage, int(count)) |
| 56 | + ctx.JSON(http.StatusOK, audits) |
| 57 | +} |
0 commit comments