animeic-cd 1 жил өмнө
parent
commit
9133679a92

+ 29 - 1
src/api/version.go

@@ -3,14 +3,19 @@ package api
 import (
 	"cr-svc/db/model"
 	"cr-svc/db/repo"
+	"cr-svc/log"
 	"errors"
+	"net/http"
 
 	"github.com/gin-gonic/gin"
+	"go.mongodb.org/mongo-driver/bson/primitive"
 )
 
 func Version(r *GinRouter) {
 	r.GET("/versions", GetVersion)
 	r.GET("/version/latest", VersionLatest)
+	r.POSTJWT("/version/update", UpdateVersion)
+	r.POSTJWT("/version/delete/:id", DeleteArticle)
 }
 
 func GetVersion(c *gin.Context, apictx *ApiSession) (interface{}, error) {
@@ -31,5 +36,28 @@ func VersionLatest(c *gin.Context, apictx *ApiSession) (interface{}, error) {
 	if !ok || err != nil {
 		return nil, errors.New("未找到数据")
 	}
-	return version, nil
+	c.JSON(http.StatusOK, version)
+	return nil, nil
+}
+
+func UpdateVersion(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	var version model.Versions
+	err := c.ShouldBindJSON(&version)
+	if err != nil {
+		log.Error(err)
+		return nil, err
+	}
+	if version.Id.IsZero() {
+		return nil, errors.New("id错误")
+	}
+	return repo.RepoUpdateSetDoc(apictx.CreateRepoCtx(), repo.CollectionVersions, version.Id.Hex(), &version)
+}
+
+func DeleteArticle(c *gin.Context, apictx *ApiSession) (interface{}, error) {
+	_id := c.Param("id")
+	id, _ := primitive.ObjectIDFromHex(_id)
+	if id.IsZero() {
+		return nil, errors.New("id错误")
+	}
+	return repo.RepoDeleteDoc(apictx.CreateRepoCtx(), repo.CollectionVersions, _id)
 }

+ 1 - 1
src/package/readme.md

@@ -1 +1 @@
-# 存放安装包
+# 存放安装包