mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-12-04 01:39:20 +08:00
85 lines
2.4 KiB
Go
85 lines
2.4 KiB
Go
package v1
|
|
|
|
import (
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
|
"github.com/gin-gonic/gin"
|
|
)
|
|
|
|
// List app
|
|
// @Tags App
|
|
// @Summary Search app list
|
|
// @Description 获取应用列表
|
|
// @Accept json
|
|
// @Param request body request.AppSearch true "request"
|
|
// @Success 200
|
|
// @Security ApiKeyAuth
|
|
// @Router /apps/search [post]
|
|
func (b *BaseApi) SearchApp(c *gin.Context) {
|
|
var req request.AppSearch
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
return
|
|
}
|
|
list, err := appService.PageApp(req)
|
|
if err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
return
|
|
}
|
|
helper.SuccessWithData(c, list)
|
|
}
|
|
|
|
func (b *BaseApi) SyncApp(c *gin.Context) {
|
|
if err := appService.SyncAppList(); err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
return
|
|
}
|
|
helper.SuccessWithData(c, "")
|
|
}
|
|
|
|
func (b *BaseApi) GetApp(c *gin.Context) {
|
|
id, err := helper.GetParamID(c)
|
|
if err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
return
|
|
}
|
|
appDTO, err := appService.GetApp(id)
|
|
if err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
return
|
|
}
|
|
helper.SuccessWithData(c, appDTO)
|
|
}
|
|
func (b *BaseApi) GetAppDetail(c *gin.Context) {
|
|
appId, err := helper.GetIntParamByKey(c, "appId")
|
|
if err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
|
return
|
|
}
|
|
version := c.Param("version")
|
|
appDetailDTO, err := appService.GetAppDetail(appId, version)
|
|
if err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
return
|
|
}
|
|
helper.SuccessWithData(c, appDetailDTO)
|
|
}
|
|
|
|
func (b *BaseApi) InstallApp(c *gin.Context) {
|
|
var req request.AppInstallCreate
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
return
|
|
}
|
|
tx, ctx := helper.GetTxAndContext()
|
|
install, err := appService.Install(ctx, req)
|
|
if err != nil {
|
|
tx.Rollback()
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
return
|
|
}
|
|
tx.Commit()
|
|
helper.SuccessWithData(c, install)
|
|
}
|