image curd
This commit is contained in:
parent
f22294056e
commit
c40e273538
1
Makefile
1
Makefile
|
|
@ -23,6 +23,7 @@ restart: docker
|
|||
|
||||
install-dev: push
|
||||
scp -i C:${HOMEPATH}/.ssh/id_rsa install-dev.yaml root@192.168.131.195:/root/install-backend-dev.yaml
|
||||
ssh -i C:${HOMEPATH}/.ssh/id_rsa root@192.168.131.195 kubectl delete -f /root/install-backend-dev.yaml
|
||||
ssh -i C:${HOMEPATH}/.ssh/id_rsa root@192.168.131.195 kubectl apply -f /root/install-backend-dev.yaml
|
||||
|
||||
push: docker
|
||||
|
|
|
|||
5
main.go
5
main.go
|
|
@ -73,6 +73,11 @@ func main() {
|
|||
|
||||
r.POST("/fork", controller.ForkApp)
|
||||
|
||||
r.POST("/image", controller.AddImage)
|
||||
r.PUT("/image", controller.UpdateImage)
|
||||
r.DELETE("/image", controller.DeleteImage)
|
||||
r.GET("/images", controller.GetImages)
|
||||
|
||||
err := r.Run(":8000")
|
||||
if err != nil {
|
||||
log.Fatal(err)
|
||||
|
|
|
|||
|
|
@ -49,13 +49,20 @@ func UpdateImage(c *gin.Context) {
|
|||
image.Save()
|
||||
}
|
||||
|
||||
func MyImages(c *gin.Context) {
|
||||
func GetImages(c *gin.Context) {
|
||||
username := c.MustGet("username").(string)
|
||||
myImages := model.GetMyImages(username)
|
||||
c.JSON(http.StatusOK, gin.H{"images": myImages})
|
||||
var Images []model.ImageModel
|
||||
if c.Query("UserName") != "" {
|
||||
if username != c.Query("UserName") {
|
||||
utils.GinError(c, http.StatusUnauthorized, "username error")
|
||||
return
|
||||
}
|
||||
|
||||
func PublicImages(c *gin.Context) {
|
||||
myImages := model.GetPublicImages()
|
||||
c.JSON(http.StatusOK, gin.H{"images": myImages})
|
||||
Images = model.GetMyImages(username)
|
||||
} else if c.Query("IsPublic") != "" {
|
||||
Images = model.GetPublicImages()
|
||||
} else {
|
||||
utils.GinError(c, http.StatusBadRequest, "param error.")
|
||||
return
|
||||
}
|
||||
c.JSON(http.StatusOK, gin.H{"data": Images})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ import (
|
|||
|
||||
type ImageModel struct {
|
||||
gorm.Model
|
||||
Name string
|
||||
Image string
|
||||
Comment string
|
||||
Command string
|
||||
|
|
@ -14,6 +15,7 @@ type ImageModel struct {
|
|||
Port string
|
||||
UserName string
|
||||
IsPublished bool
|
||||
Doc string
|
||||
}
|
||||
|
||||
func (*ImageModel) TableName() string {
|
||||
|
|
@ -40,6 +42,13 @@ func (i *ImageModel) Delete() {
|
|||
db.Delete(i)
|
||||
}
|
||||
|
||||
func GetImages(query map[string]interface{}) []ImageModel {
|
||||
db := k8s_manager.DB()
|
||||
ans := make([]ImageModel, 0)
|
||||
db.Where(query).Find(&ans)
|
||||
return ans
|
||||
}
|
||||
|
||||
func GetMyImages(username string) []ImageModel {
|
||||
db := k8s_manager.DB()
|
||||
ans := make([]ImageModel, 0)
|
||||
|
|
|
|||
Loading…
Reference in New Issue