2022-09-22 16:16:04 +08:00
|
|
|
package v1
|
|
|
|
|
|
|
|
import (
|
2022-10-17 16:32:31 +08:00
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
|
|
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
2022-09-22 16:16:04 +08:00
|
|
|
"github.com/gin-gonic/gin"
|
|
|
|
)
|
|
|
|
|
2022-10-11 16:27:58 +08:00
|
|
|
func (b *BaseApi) SearchApp(c *gin.Context) {
|
2022-09-22 16:16:04 +08:00
|
|
|
var req dto.AppRequest
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-10-11 16:27:58 +08:00
|
|
|
list, err := appService.PageApp(req)
|
2022-09-22 16:16:04 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
|
|
|
helper.SuccessWithData(c, list)
|
|
|
|
}
|
|
|
|
|
2022-10-11 16:27:58 +08:00
|
|
|
func (b *BaseApi) SyncApp(c *gin.Context) {
|
2022-09-29 18:16:56 +08:00
|
|
|
if err := appService.SyncAppList(); err != nil {
|
2022-09-22 16:16:04 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, "")
|
|
|
|
}
|
2022-09-23 16:33:55 +08:00
|
|
|
|
|
|
|
func (b *BaseApi) GetApp(c *gin.Context) {
|
2022-11-03 17:06:48 +08:00
|
|
|
|
|
|
|
id, err := helper.GetParamID(c)
|
2022-09-23 16:33:55 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
2022-11-03 17:06:48 +08:00
|
|
|
appDTO, err := appService.GetApp(id)
|
2022-09-23 16:33:55 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, appDTO)
|
|
|
|
}
|
|
|
|
func (b *BaseApi) GetAppDetail(c *gin.Context) {
|
2022-11-03 17:06:48 +08:00
|
|
|
|
|
|
|
appId, err := helper.GetIntParamByKey(c, "appId")
|
2022-09-23 16:33:55 +08:00
|
|
|
if err != nil {
|
2022-11-03 17:06:48 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
2022-09-23 16:33:55 +08:00
|
|
|
return
|
|
|
|
}
|
2022-11-03 17:06:48 +08:00
|
|
|
|
2022-09-23 16:33:55 +08:00
|
|
|
version := c.Param("version")
|
2022-11-03 17:06:48 +08:00
|
|
|
appDetailDTO, err := appService.GetAppDetail(appId, version)
|
2022-09-23 16:33:55 +08:00
|
|
|
if err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
helper.SuccessWithData(c, appDetailDTO)
|
|
|
|
}
|
2022-09-26 16:32:40 +08:00
|
|
|
|
|
|
|
func (b *BaseApi) InstallApp(c *gin.Context) {
|
|
|
|
var req dto.AppInstallRequest
|
|
|
|
if err := c.ShouldBindJSON(&req); err != nil {
|
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
|
|
|
return
|
|
|
|
}
|
2022-11-02 15:19:14 +08:00
|
|
|
install, err := appService.Install(req.Name, req.AppDetailId, req.Params)
|
|
|
|
if err != nil {
|
2022-09-26 16:32:40 +08:00
|
|
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2022-11-02 15:19:14 +08:00
|
|
|
helper.SuccessWithData(c, install)
|
2022-09-26 16:32:40 +08:00
|
|
|
}
|