Skip to content

Commit 128f2d9

Browse files
committed
feat: add persistent cache service
Signed-off-by: BruceAko <chongzhi@hust.edu.cn>
1 parent e0bedbd commit 128f2d9

File tree

9 files changed

+1036
-2
lines changed

9 files changed

+1036
-2
lines changed

manager/handlers/job.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ import (
3838
// @Failure 400
3939
// @Failure 404
4040
// @Failure 500
41+
// @Router /api/v1/jobs [post]
4142
// @Router /oapi/v1/jobs [post]
4243
func (h *Handlers) CreateJob(ctx *gin.Context) {
4344
var json types.CreateJobRequest
Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
"d7y.io/dragonfly/v2/manager/types"
25+
)
26+
27+
// @Summary Get PersistentCaches
28+
// @Description Get PersistentCaches
29+
// @Tags PersistentCache
30+
// @Accept json
31+
// @Produce json
32+
// @Param page query int true "current page" default(0)
33+
// @Param per_page query int true "return max item count, default 10, max 50" default(10) minimum(2) maximum(50)
34+
// @Success 200 {object} []types.GetPersistentCachesResponse
35+
// @Failure 400
36+
// @Failure 404
37+
// @Failure 500
38+
// @Router /api/v1/persistent-caches [get]
39+
func (h *Handlers) GetPersistentCaches(ctx *gin.Context) {
40+
var query types.GetPersistentCachesQuery
41+
if err := ctx.ShouldBindQuery(&query); err != nil {
42+
ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
43+
return
44+
}
45+
46+
h.setPaginationDefault(&query.Page, &query.PerPage)
47+
persistentCaches, count, err := h.service.GetPersistentCaches(ctx.Request.Context(), query)
48+
if err != nil {
49+
ctx.Error(err) // nolint: errcheck
50+
return
51+
}
52+
53+
h.setPaginationLinkHeader(ctx, query.Page, query.PerPage, int(count))
54+
ctx.JSON(http.StatusOK, persistentCaches)
55+
}

manager/router/router.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -233,6 +233,12 @@ func Init(cfg *config.Config, logDir string, service service.Service, database *
233233
pat.GET(":id", h.GetPersonalAccessToken)
234234
pat.GET("", h.GetPersonalAccessTokens)
235235

236+
// Persistent Cache.
237+
pc := apiv1.Group("/persistent-caches", jwt.MiddlewareFunc(), rbac)
238+
//pc.DELETE(":id", h.DestroyPersistentCache)
239+
//pc.GET(":id", h.GetPersistentCache)
240+
pc.GET("", h.GetPersistentCaches)
241+
236242
// Open API router.
237243
oapiv1 := r.Group("/oapi/v1")
238244

manager/service/mocks/service_mock.go

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)