mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2024-12-05 02:19:00 +08:00
76 lines
2.2 KiB
Go
76 lines
2.2 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"
|
|
)
|
|
|
|
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)
|
|
}
|