Dragonfly2

Форк
0
129 строк · 3.1 Кб
1
/*
2
 *     Copyright 2022 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
	// nolint
27
	"d7y.io/dragonfly/v2/manager/types"
28
	// nolint
29
	_ "d7y.io/dragonfly/v2/pkg/objectstorage"
30
)
31

32
// @Summary Create Bucket
33
// @Description Create by json bucket
34
// @Tags Bucket
35
// @Accept json
36
// @Produce json
37
// @Param Bucket body types.CreateBucketRequest true "Bucket"
38
// @Success 200
39
// @Failure 400
40
// @Failure 404
41
// @Failure 500
42
// @Router /buckets [post]
43
func (h *Handlers) CreateBucket(ctx *gin.Context) {
44
	var json types.CreateBucketRequest
45
	if err := ctx.ShouldBindJSON(&json); err != nil {
46
		ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
47
		return
48
	}
49

50
	if err := h.service.CreateBucket(ctx.Request.Context(), json); err != nil {
51
		ctx.Error(err) // nolint: errcheck
52
		return
53
	}
54

55
	ctx.Status(http.StatusOK)
56
}
57

58
// @Summary Destroy Bucket
59
// @Description Destroy by id
60
// @Tags Bucket
61
// @Accept json
62
// @Produce json
63
// @Param id path string true "id"
64
// @Success 200
65
// @Failure 400
66
// @Failure 404
67
// @Failure 500
68
// @Router /buckets/{id} [delete]
69
func (h *Handlers) DestroyBucket(ctx *gin.Context) {
70
	var params types.BucketParams
71
	if err := ctx.ShouldBindUri(&params); err != nil {
72
		ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
73
		return
74
	}
75

76
	if err := h.service.DestroyBucket(ctx.Request.Context(), params.ID); err != nil {
77
		ctx.Error(err) // nolint: errcheck
78
		return
79
	}
80

81
	ctx.Status(http.StatusOK)
82
}
83

84
// @Summary Get Bucket
85
// @Description Get Bucket by id
86
// @Tags Bucket
87
// @Accept json
88
// @Produce json
89
// @Param id path string true "id"
90
// @Success 200 {object} objectstorage.BucketMetadata
91
// @Failure 400
92
// @Failure 404
93
// @Failure 500
94
// @Router /buckets/{id} [get]
95
func (h *Handlers) GetBucket(ctx *gin.Context) {
96
	var params types.BucketParams
97
	if err := ctx.ShouldBindUri(&params); err != nil {
98
		ctx.JSON(http.StatusUnprocessableEntity, gin.H{"errors": err.Error()})
99
		return
100
	}
101

102
	bucket, err := h.service.GetBucket(ctx.Request.Context(), params.ID)
103
	if err != nil {
104
		ctx.Error(err) // nolint: errcheck
105
		return
106
	}
107

108
	ctx.JSON(http.StatusOK, bucket)
109
}
110

111
// @Summary Get Buckets
112
// @Description Get Buckets
113
// @Tags Bucket
114
// @Accept json
115
// @Produce json
116
// @Success 200 {object} []objectstorage.BucketMetadata
117
// @Failure 400
118
// @Failure 404
119
// @Failure 500
120
// @Router /buckets [get]
121
func (h *Handlers) GetBuckets(ctx *gin.Context) {
122
	buckets, err := h.service.GetBuckets(ctx.Request.Context())
123
	if err != nil {
124
		ctx.Error(err) // nolint: errcheck
125
		return
126
	}
127

128
	ctx.JSON(http.StatusOK, buckets)
129
}
130

Использование cookies

Мы используем файлы cookie в соответствии с Политикой конфиденциальности и Политикой использования cookies.

Нажимая кнопку «Принимаю», Вы даете АО «СберТех» согласие на обработку Ваших персональных данных в целях совершенствования нашего веб-сайта и Сервиса GitVerse, а также повышения удобства их использования.

Запретить использование cookies Вы можете самостоятельно в настройках Вашего браузера.