mirror of
https://github.com/1Panel-dev/1Panel.git
synced 2025-03-14 01:34:47 +08:00
style: 修改app的代码结构
This commit is contained in:
parent
a353adc4b9
commit
7171d015a4
@ -2,24 +2,22 @@ package v1
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
||||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||||
"github.com/gin-gonic/gin"
|
"github.com/gin-gonic/gin"
|
||||||
)
|
)
|
||||||
|
|
||||||
func (b *BaseApi) SearchApp(c *gin.Context) {
|
func (b *BaseApi) SearchApp(c *gin.Context) {
|
||||||
var req dto.AppRequest
|
var req request.AppSearch
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
list, err := appService.PageApp(req)
|
list, err := appService.PageApp(req)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
helper.SuccessWithData(c, list)
|
helper.SuccessWithData(c, list)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -32,7 +30,6 @@ func (b *BaseApi) SyncApp(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *BaseApi) GetApp(c *gin.Context) {
|
func (b *BaseApi) GetApp(c *gin.Context) {
|
||||||
|
|
||||||
id, err := helper.GetParamID(c)
|
id, err := helper.GetParamID(c)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||||
@ -46,13 +43,11 @@ func (b *BaseApi) GetApp(c *gin.Context) {
|
|||||||
helper.SuccessWithData(c, appDTO)
|
helper.SuccessWithData(c, appDTO)
|
||||||
}
|
}
|
||||||
func (b *BaseApi) GetAppDetail(c *gin.Context) {
|
func (b *BaseApi) GetAppDetail(c *gin.Context) {
|
||||||
|
|
||||||
appId, err := helper.GetIntParamByKey(c, "appId")
|
appId, err := helper.GetIntParamByKey(c, "appId")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
version := c.Param("version")
|
version := c.Param("version")
|
||||||
appDetailDTO, err := appService.GetAppDetail(appId, version)
|
appDetailDTO, err := appService.GetAppDetail(appId, version)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -63,7 +58,7 @@ func (b *BaseApi) GetAppDetail(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *BaseApi) InstallApp(c *gin.Context) {
|
func (b *BaseApi) InstallApp(c *gin.Context) {
|
||||||
var req dto.AppInstallRequest
|
var req request.AppInstallCreate
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||||
return
|
return
|
||||||
@ -73,6 +68,5 @@ func (b *BaseApi) InstallApp(c *gin.Context) {
|
|||||||
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
helper.ErrorWithDetail(c, constant.CodeErrInternalServer, constant.ErrTypeInternalServer, err)
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
helper.SuccessWithData(c, install)
|
helper.SuccessWithData(c, install)
|
||||||
}
|
}
|
||||||
|
@ -2,6 +2,7 @@ package v1
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"errors"
|
"errors"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
||||||
"reflect"
|
"reflect"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
"github.com/1Panel-dev/1Panel/backend/app/api/v1/helper"
|
||||||
@ -12,7 +13,7 @@ import (
|
|||||||
)
|
)
|
||||||
|
|
||||||
func (b *BaseApi) SearchAppInstalled(c *gin.Context) {
|
func (b *BaseApi) SearchAppInstalled(c *gin.Context) {
|
||||||
var req dto.AppInstalledRequest
|
var req request.AppInstalledSearch
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||||
return
|
return
|
||||||
@ -68,7 +69,6 @@ func (b *BaseApi) LoadPort(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *BaseApi) DeleteCheck(c *gin.Context) {
|
func (b *BaseApi) DeleteCheck(c *gin.Context) {
|
||||||
|
|
||||||
appInstallId, err := helper.GetIntParamByKey(c, "appInstallId")
|
appInstallId, err := helper.GetIntParamByKey(c, "appInstallId")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
||||||
@ -92,7 +92,7 @@ func (b *BaseApi) SyncInstalled(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *BaseApi) SearchInstalledBackup(c *gin.Context) {
|
func (b *BaseApi) SearchInstalledBackup(c *gin.Context) {
|
||||||
var req dto.AppBackupRequest
|
var req request.AppBackupSearch
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||||
return
|
return
|
||||||
@ -110,7 +110,7 @@ func (b *BaseApi) SearchInstalledBackup(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *BaseApi) OperateInstalled(c *gin.Context) {
|
func (b *BaseApi) OperateInstalled(c *gin.Context) {
|
||||||
var req dto.AppInstallOperate
|
var req request.AppInstalledOperate
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||||
return
|
return
|
||||||
@ -124,7 +124,7 @@ func (b *BaseApi) OperateInstalled(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *BaseApi) DeleteAppBackup(c *gin.Context) {
|
func (b *BaseApi) DeleteAppBackup(c *gin.Context) {
|
||||||
var req dto.AppBackupDeleteRequest
|
var req request.AppBackupDelete
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||||
return
|
return
|
||||||
@ -137,7 +137,6 @@ func (b *BaseApi) DeleteAppBackup(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *BaseApi) GetServices(c *gin.Context) {
|
func (b *BaseApi) GetServices(c *gin.Context) {
|
||||||
|
|
||||||
key := c.Param("key")
|
key := c.Param("key")
|
||||||
services, err := appInstallService.GetServices(key)
|
services, err := appInstallService.GetServices(key)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -149,7 +148,6 @@ func (b *BaseApi) GetServices(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *BaseApi) GetUpdateVersions(c *gin.Context) {
|
func (b *BaseApi) GetUpdateVersions(c *gin.Context) {
|
||||||
|
|
||||||
appInstallId, err := helper.GetIntParamByKey(c, "appInstallId")
|
appInstallId, err := helper.GetIntParamByKey(c, "appInstallId")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInternalServer, nil)
|
||||||
@ -166,7 +164,7 @@ func (b *BaseApi) GetUpdateVersions(c *gin.Context) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
func (b *BaseApi) ChangeAppPort(c *gin.Context) {
|
func (b *BaseApi) ChangeAppPort(c *gin.Context) {
|
||||||
var req dto.PortUpdate
|
var req request.PortUpdate
|
||||||
if err := c.ShouldBindJSON(&req); err != nil {
|
if err := c.ShouldBindJSON(&req); err != nil {
|
||||||
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
helper.ErrorWithDetail(c, constant.CodeErrBadRequest, constant.ErrTypeInvalidParams, err)
|
||||||
return
|
return
|
||||||
|
@ -2,113 +2,8 @@ package dto
|
|||||||
|
|
||||||
import (
|
import (
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"time"
|
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/model"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
type AppRes struct {
|
|
||||||
Version string `json:"version"`
|
|
||||||
CanUpdate bool `json:"canUpdate"`
|
|
||||||
Items []*AppDTO `json:"items"`
|
|
||||||
Tags []model.Tag `json:"tags"`
|
|
||||||
Total int64 `json:"total"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppDTO struct {
|
|
||||||
model.App
|
|
||||||
Versions []string `json:"versions"`
|
|
||||||
Tags []model.Tag `json:"tags"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppDetailDTO struct {
|
|
||||||
model.AppDetail
|
|
||||||
Enable bool `json:"enable"`
|
|
||||||
Params interface{} `json:"params"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppRequest struct {
|
|
||||||
PageInfo
|
|
||||||
Name string `json:"name"`
|
|
||||||
Tags []string `json:"tags"`
|
|
||||||
Type string `json:"type"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppInstallRequest struct {
|
|
||||||
AppDetailId uint `json:"appDetailId" validate:"required"`
|
|
||||||
Params map[string]interface{} `json:"params"`
|
|
||||||
Name string `json:"name" validate:"required"`
|
|
||||||
Services map[string]string `json:"services"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type CheckInstalled struct {
|
|
||||||
IsExist bool `json:"isExist"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
App string `json:"app"`
|
|
||||||
Version string `json:"version"`
|
|
||||||
Status string `json:"status"`
|
|
||||||
CreatedAt time.Time `json:"createdAt"`
|
|
||||||
LastBackupAt string `json:"lastBackupAt"`
|
|
||||||
AppInstallID uint `json:"appInstallId"`
|
|
||||||
ContainerName string `json:"containerName"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppInstalled struct {
|
|
||||||
model.AppInstall
|
|
||||||
Total int `json:"total"`
|
|
||||||
Ready int `json:"ready"`
|
|
||||||
AppName string `json:"appName"`
|
|
||||||
Icon string `json:"icon"`
|
|
||||||
CanUpdate bool `json:"canUpdate"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppInstalledRequest struct {
|
|
||||||
PageInfo
|
|
||||||
Type string `json:"type"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppBackupRequest struct {
|
|
||||||
PageInfo
|
|
||||||
AppInstallID uint `json:"appInstallID"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppBackupDeleteRequest struct {
|
|
||||||
Ids []uint `json:"ids"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppOperate string
|
|
||||||
|
|
||||||
var (
|
|
||||||
Up AppOperate = "up"
|
|
||||||
Down AppOperate = "down"
|
|
||||||
Restart AppOperate = "restart"
|
|
||||||
Delete AppOperate = "delete"
|
|
||||||
Sync AppOperate = "sync"
|
|
||||||
Backup AppOperate = "backup"
|
|
||||||
Restore AppOperate = "restore"
|
|
||||||
Update AppOperate = "update"
|
|
||||||
)
|
|
||||||
|
|
||||||
type AppInstallOperate struct {
|
|
||||||
InstallId uint `json:"installId" validate:"required"`
|
|
||||||
BackupId uint `json:"backupId"`
|
|
||||||
DetailId uint `json:"detailId"`
|
|
||||||
Operate AppOperate `json:"operate" validate:"required"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type PortUpdate struct {
|
|
||||||
Key string `json:"key"`
|
|
||||||
Name string `json:"name"`
|
|
||||||
Port int64 `json:"port"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppService struct {
|
|
||||||
Label string `json:"label"`
|
|
||||||
Value string `json:"value"`
|
|
||||||
Config interface{} `json:"config"`
|
|
||||||
}
|
|
||||||
|
|
||||||
type AppDatabase struct {
|
type AppDatabase struct {
|
||||||
ServiceName string `json:"PANEL_DB_HOST"`
|
ServiceName string `json:"PANEL_DB_HOST"`
|
||||||
DbName string `json:"PANEL_DB_NAME"`
|
DbName string `json:"PANEL_DB_NAME"`
|
||||||
|
48
backend/app/dto/request/app.go
Normal file
48
backend/app/dto/request/app.go
Normal file
@ -0,0 +1,48 @@
|
|||||||
|
package request
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AppSearch struct {
|
||||||
|
dto.PageInfo
|
||||||
|
Name string `json:"name"`
|
||||||
|
Tags []string `json:"tags"`
|
||||||
|
Type string `json:"type"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppInstallCreate struct {
|
||||||
|
AppDetailId uint `json:"appDetailId" validate:"required"`
|
||||||
|
Params map[string]interface{} `json:"params"`
|
||||||
|
Name string `json:"name" validate:"required"`
|
||||||
|
Services map[string]string `json:"services"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppInstalledSearch struct {
|
||||||
|
dto.PageInfo
|
||||||
|
Type string `json:"type"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppBackupSearch struct {
|
||||||
|
dto.PageInfo
|
||||||
|
AppInstallID uint `json:"appInstallID"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppBackupDelete struct {
|
||||||
|
Ids []uint `json:"ids"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppInstalledOperate struct {
|
||||||
|
InstallId uint `json:"installId" validate:"required"`
|
||||||
|
BackupId uint `json:"backupId"`
|
||||||
|
DetailId uint `json:"detailId"`
|
||||||
|
Operate constant.AppOperate `json:"operate" validate:"required"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type PortUpdate struct {
|
||||||
|
Key string `json:"key"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
Port int64 `json:"port"`
|
||||||
|
}
|
53
backend/app/dto/response/app.go
Normal file
53
backend/app/dto/response/app.go
Normal file
@ -0,0 +1,53 @@
|
|||||||
|
package response
|
||||||
|
|
||||||
|
import (
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/app/model"
|
||||||
|
"time"
|
||||||
|
)
|
||||||
|
|
||||||
|
type AppRes struct {
|
||||||
|
Version string `json:"version"`
|
||||||
|
CanUpdate bool `json:"canUpdate"`
|
||||||
|
Items []*AppDTO `json:"items"`
|
||||||
|
Tags []model.Tag `json:"tags"`
|
||||||
|
Total int64 `json:"total"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppDTO struct {
|
||||||
|
model.App
|
||||||
|
Versions []string `json:"versions"`
|
||||||
|
Tags []model.Tag `json:"tags"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppInstalledCheck struct {
|
||||||
|
IsExist bool `json:"isExist"`
|
||||||
|
Name string `json:"name"`
|
||||||
|
App string `json:"app"`
|
||||||
|
Version string `json:"version"`
|
||||||
|
Status string `json:"status"`
|
||||||
|
CreatedAt time.Time `json:"createdAt"`
|
||||||
|
LastBackupAt string `json:"lastBackupAt"`
|
||||||
|
AppInstallID uint `json:"appInstallId"`
|
||||||
|
ContainerName string `json:"containerName"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppDetailDTO struct {
|
||||||
|
model.AppDetail
|
||||||
|
Enable bool `json:"enable"`
|
||||||
|
Params interface{} `json:"params"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppInstalledDTO struct {
|
||||||
|
model.AppInstall
|
||||||
|
Total int `json:"total"`
|
||||||
|
Ready int `json:"ready"`
|
||||||
|
AppName string `json:"appName"`
|
||||||
|
Icon string `json:"icon"`
|
||||||
|
CanUpdate bool `json:"canUpdate"`
|
||||||
|
}
|
||||||
|
|
||||||
|
type AppService struct {
|
||||||
|
Label string `json:"label"`
|
||||||
|
Value string `json:"value"`
|
||||||
|
Config interface{} `json:"config"`
|
||||||
|
}
|
@ -9,6 +9,8 @@ import (
|
|||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
"github.com/1Panel-dev/1Panel/backend/app/dto"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/app/dto/response"
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/model"
|
"github.com/1Panel-dev/1Panel/backend/app/model"
|
||||||
"github.com/1Panel-dev/1Panel/backend/app/repo"
|
"github.com/1Panel-dev/1Panel/backend/app/repo"
|
||||||
"github.com/1Panel-dev/1Panel/backend/constant"
|
"github.com/1Panel-dev/1Panel/backend/constant"
|
||||||
@ -22,7 +24,7 @@ import (
|
|||||||
type AppService struct {
|
type AppService struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppService) PageApp(req dto.AppRequest) (interface{}, error) {
|
func (a AppService) PageApp(req request.AppSearch) (interface{}, error) {
|
||||||
|
|
||||||
var opts []repo.DBOption
|
var opts []repo.DBOption
|
||||||
opts = append(opts, commonRepo.WithOrderBy("name"))
|
opts = append(opts, commonRepo.WithOrderBy("name"))
|
||||||
@ -52,14 +54,14 @@ func (a AppService) PageApp(req dto.AppRequest) (interface{}, error) {
|
|||||||
|
|
||||||
opts = append(opts, commonRepo.WithIdsIn(appIds))
|
opts = append(opts, commonRepo.WithIdsIn(appIds))
|
||||||
}
|
}
|
||||||
var res dto.AppRes
|
var res response.AppRes
|
||||||
total, apps, err := appRepo.Page(req.Page, req.PageSize, opts...)
|
total, apps, err := appRepo.Page(req.Page, req.PageSize, opts...)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var appDTOs []*dto.AppDTO
|
var appDTOs []*response.AppDTO
|
||||||
for _, a := range apps {
|
for _, a := range apps {
|
||||||
appDTO := &dto.AppDTO{
|
appDTO := &response.AppDTO{
|
||||||
App: a,
|
App: a,
|
||||||
}
|
}
|
||||||
appDTOs = append(appDTOs, appDTO)
|
appDTOs = append(appDTOs, appDTO)
|
||||||
@ -88,8 +90,8 @@ func (a AppService) PageApp(req dto.AppRequest) (interface{}, error) {
|
|||||||
return res, nil
|
return res, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppService) GetApp(id uint) (dto.AppDTO, error) {
|
func (a AppService) GetApp(id uint) (response.AppDTO, error) {
|
||||||
var appDTO dto.AppDTO
|
var appDTO response.AppDTO
|
||||||
app, err := appRepo.GetFirst(commonRepo.WithByID(id))
|
app, err := appRepo.GetFirst(commonRepo.WithByID(id))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return appDTO, err
|
return appDTO, err
|
||||||
@ -109,10 +111,9 @@ func (a AppService) GetApp(id uint) (dto.AppDTO, error) {
|
|||||||
return appDTO, nil
|
return appDTO, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppService) GetAppDetail(appId uint, version string) (dto.AppDetailDTO, error) {
|
func (a AppService) GetAppDetail(appId uint, version string) (response.AppDetailDTO, error) {
|
||||||
|
|
||||||
var (
|
var (
|
||||||
appDetailDTO dto.AppDetailDTO
|
appDetailDTO response.AppDetailDTO
|
||||||
opts []repo.DBOption
|
opts []repo.DBOption
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -4,6 +4,8 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/app/dto/request"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/app/dto/response"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"os"
|
"os"
|
||||||
"path"
|
"path"
|
||||||
@ -27,7 +29,7 @@ import (
|
|||||||
type AppInstallService struct {
|
type AppInstallService struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) Page(req dto.AppInstalledRequest) (int64, []dto.AppInstalled, error) {
|
func (a AppInstallService) Page(req request.AppInstalledSearch) (int64, []response.AppInstalledDTO, error) {
|
||||||
var opts []repo.DBOption
|
var opts []repo.DBOption
|
||||||
|
|
||||||
if req.Name != "" {
|
if req.Name != "" {
|
||||||
@ -47,9 +49,9 @@ func (a AppInstallService) Page(req dto.AppInstalledRequest) (int64, []dto.AppIn
|
|||||||
return total, installDTOs, nil
|
return total, installDTOs, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) CheckExist(key string) (*dto.CheckInstalled, error) {
|
func (a AppInstallService) CheckExist(key string) (*response.AppInstalledCheck, error) {
|
||||||
|
|
||||||
res := &dto.CheckInstalled{
|
res := &response.AppInstalledCheck{
|
||||||
IsExist: false,
|
IsExist: false,
|
||||||
}
|
}
|
||||||
app, err := appRepo.GetFirst(appRepo.WithKey(key))
|
app, err := appRepo.GetFirst(appRepo.WithKey(key))
|
||||||
@ -87,7 +89,7 @@ func (a AppInstallService) LoadPort(key string) (int64, error) {
|
|||||||
return app.Port, nil
|
return app.Port, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) Search(req dto.AppInstalledRequest) ([]dto.AppInstalled, error) {
|
func (a AppInstallService) Search(req request.AppInstalledSearch) ([]response.AppInstalledDTO, error) {
|
||||||
var installs []model.AppInstall
|
var installs []model.AppInstall
|
||||||
var err error
|
var err error
|
||||||
if req.Type != "" {
|
if req.Type != "" {
|
||||||
@ -113,7 +115,7 @@ func (a AppInstallService) Search(req dto.AppInstalledRequest) ([]dto.AppInstall
|
|||||||
return handleInstalled(installs)
|
return handleInstalled(installs)
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) Operate(req dto.AppInstallOperate) error {
|
func (a AppInstallService) Operate(req request.AppInstalledOperate) error {
|
||||||
install, err := appInstallRepo.GetFirst(commonRepo.WithByID(req.InstallId))
|
install, err := appInstallRepo.GetFirst(commonRepo.WithByID(req.InstallId))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return err
|
return err
|
||||||
@ -122,25 +124,25 @@ func (a AppInstallService) Operate(req dto.AppInstallOperate) error {
|
|||||||
dockerComposePath := install.GetComposePath()
|
dockerComposePath := install.GetComposePath()
|
||||||
|
|
||||||
switch req.Operate {
|
switch req.Operate {
|
||||||
case dto.Up:
|
case constant.Up:
|
||||||
out, err := compose.Up(dockerComposePath)
|
out, err := compose.Up(dockerComposePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return handleErr(install, err, out)
|
return handleErr(install, err, out)
|
||||||
}
|
}
|
||||||
install.Status = constant.Running
|
install.Status = constant.Running
|
||||||
case dto.Down:
|
case constant.Down:
|
||||||
out, err := compose.Stop(dockerComposePath)
|
out, err := compose.Stop(dockerComposePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return handleErr(install, err, out)
|
return handleErr(install, err, out)
|
||||||
}
|
}
|
||||||
install.Status = constant.Stopped
|
install.Status = constant.Stopped
|
||||||
case dto.Restart:
|
case constant.Restart:
|
||||||
out, err := compose.Restart(dockerComposePath)
|
out, err := compose.Restart(dockerComposePath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return handleErr(install, err, out)
|
return handleErr(install, err, out)
|
||||||
}
|
}
|
||||||
install.Status = constant.Running
|
install.Status = constant.Running
|
||||||
case dto.Delete:
|
case constant.Delete:
|
||||||
tx, ctx := getTxAndContext()
|
tx, ctx := getTxAndContext()
|
||||||
if err := deleteAppInstall(ctx, install); err != nil {
|
if err := deleteAppInstall(ctx, install); err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
@ -148,9 +150,9 @@ func (a AppInstallService) Operate(req dto.AppInstallOperate) error {
|
|||||||
}
|
}
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
return nil
|
return nil
|
||||||
case dto.Sync:
|
case constant.Sync:
|
||||||
return syncById(install.ID)
|
return syncById(install.ID)
|
||||||
case dto.Backup:
|
case constant.Backup:
|
||||||
tx, ctx := getTxAndContext()
|
tx, ctx := getTxAndContext()
|
||||||
if err := backupInstall(ctx, install); err != nil {
|
if err := backupInstall(ctx, install); err != nil {
|
||||||
tx.Rollback()
|
tx.Rollback()
|
||||||
@ -158,9 +160,9 @@ func (a AppInstallService) Operate(req dto.AppInstallOperate) error {
|
|||||||
}
|
}
|
||||||
tx.Commit()
|
tx.Commit()
|
||||||
return nil
|
return nil
|
||||||
case dto.Restore:
|
case constant.Restore:
|
||||||
return restoreInstall(install, req.BackupId)
|
return restoreInstall(install, req.BackupId)
|
||||||
case dto.Update:
|
case constant.Update:
|
||||||
return updateInstall(install.ID, req.DetailId)
|
return updateInstall(install.ID, req.DetailId)
|
||||||
default:
|
default:
|
||||||
return errors.New("operate not support")
|
return errors.New("operate not support")
|
||||||
@ -184,11 +186,11 @@ func (a AppInstallService) SyncAll() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) PageInstallBackups(req dto.AppBackupRequest) (int64, []model.AppInstallBackup, error) {
|
func (a AppInstallService) PageInstallBackups(req request.AppBackupSearch) (int64, []model.AppInstallBackup, error) {
|
||||||
return appInstallBackupRepo.Page(req.Page, req.PageSize, appInstallBackupRepo.WithAppInstallID(req.AppInstallID))
|
return appInstallBackupRepo.Page(req.Page, req.PageSize, appInstallBackupRepo.WithAppInstallID(req.AppInstallID))
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) DeleteBackup(req dto.AppBackupDeleteRequest) error {
|
func (a AppInstallService) DeleteBackup(req request.AppBackupDelete) error {
|
||||||
|
|
||||||
backups, err := appInstallBackupRepo.GetBy(commonRepo.WithIdsIn(req.Ids))
|
backups, err := appInstallBackupRepo.GetBy(commonRepo.WithIdsIn(req.Ids))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@ -213,7 +215,7 @@ func (a AppInstallService) DeleteBackup(req dto.AppBackupDeleteRequest) error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) GetServices(key string) ([]dto.AppService, error) {
|
func (a AppInstallService) GetServices(key string) ([]response.AppService, error) {
|
||||||
app, err := appRepo.GetFirst(appRepo.WithKey(key))
|
app, err := appRepo.GetFirst(appRepo.WithKey(key))
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
@ -222,13 +224,13 @@ func (a AppInstallService) GetServices(key string) ([]dto.AppService, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var res []dto.AppService
|
var res []response.AppService
|
||||||
for _, install := range installs {
|
for _, install := range installs {
|
||||||
paramMap := make(map[string]string)
|
paramMap := make(map[string]string)
|
||||||
if install.Param != "" {
|
if install.Param != "" {
|
||||||
_ = json.Unmarshal([]byte(install.Param), ¶mMap)
|
_ = json.Unmarshal([]byte(install.Param), ¶mMap)
|
||||||
}
|
}
|
||||||
res = append(res, dto.AppService{
|
res = append(res, response.AppService{
|
||||||
Label: install.Name,
|
Label: install.Name,
|
||||||
Value: install.ServiceName,
|
Value: install.ServiceName,
|
||||||
Config: paramMap,
|
Config: paramMap,
|
||||||
@ -262,7 +264,7 @@ func (a AppInstallService) GetUpdateVersions(installId uint) ([]dto.AppVersion,
|
|||||||
return versions, nil
|
return versions, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (a AppInstallService) ChangeAppPort(req dto.PortUpdate) error {
|
func (a AppInstallService) ChangeAppPort(req request.PortUpdate) error {
|
||||||
return updateInstallInfoInDB(req.Key, "port", true, strconv.FormatInt(req.Port, 10))
|
return updateInstallInfoInDB(req.Key, "port", true, strconv.FormatInt(req.Port, 10))
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -4,6 +4,7 @@ import (
|
|||||||
"context"
|
"context"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"fmt"
|
"fmt"
|
||||||
|
"github.com/1Panel-dev/1Panel/backend/app/dto/response"
|
||||||
"github.com/1Panel-dev/1Panel/backend/buserr"
|
"github.com/1Panel-dev/1Panel/backend/buserr"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"math"
|
"math"
|
||||||
@ -589,12 +590,12 @@ func getAppFromOss() error {
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func handleInstalled(installed []model.AppInstall) ([]dto.AppInstalled, error) {
|
func handleInstalled(installed []model.AppInstall) ([]response.AppInstalledDTO, error) {
|
||||||
var res []dto.AppInstalled
|
var res []response.AppInstalledDTO
|
||||||
|
|
||||||
for _, installed := range installed {
|
for _, installed := range installed {
|
||||||
|
|
||||||
installDTO := dto.AppInstalled{
|
installDTO := response.AppInstalledDTO{
|
||||||
AppInstall: installed,
|
AppInstall: installed,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -16,3 +16,16 @@ const (
|
|||||||
AppMysql = "mysql"
|
AppMysql = "mysql"
|
||||||
AppRedis = "redis"
|
AppRedis = "redis"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
type AppOperate string
|
||||||
|
|
||||||
|
var (
|
||||||
|
Up AppOperate = "up"
|
||||||
|
Down AppOperate = "down"
|
||||||
|
Restart AppOperate = "restart"
|
||||||
|
Delete AppOperate = "delete"
|
||||||
|
Sync AppOperate = "sync"
|
||||||
|
Backup AppOperate = "backup"
|
||||||
|
Restore AppOperate = "restore"
|
||||||
|
Update AppOperate = "update"
|
||||||
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user