Rainbond/api/handler/tenant_application_handler.go

47 lines
1.4 KiB
Go
Raw Normal View History

2020-09-17 15:45:46 +08:00
package handler
import (
"github.com/goodrain/rainbond/api/model"
"github.com/goodrain/rainbond/db"
dbmodel "github.com/goodrain/rainbond/db/model"
2020-09-18 10:31:35 +08:00
"github.com/goodrain/rainbond/util"
2020-09-17 16:43:53 +08:00
"github.com/jinzhu/gorm"
2020-09-17 15:45:46 +08:00
)
// TenantApplicationAction -
type TenantApplicationAction struct{}
// TenantApplicationHandler defines handler methods to TenantApplication.
type TenantApplicationHandler interface {
CreateApp(req *model.Application) (*model.Application, error)
2020-09-17 16:43:53 +08:00
ListApps(tenantID string, page, pageSize int) ([]*dbmodel.Application, int64, error)
2020-09-17 15:45:46 +08:00
}
// NewTenantApplicationHandler creates a new Tenant Application Handler.
func NewTenantApplicationHandler() TenantApplicationHandler {
return &TenantApplicationAction{}
}
// CreateApp -
func (a *TenantApplicationAction) CreateApp(req *model.Application) (*model.Application, error) {
appReq := &dbmodel.Application{
AppName: req.AppName,
2020-09-18 10:31:35 +08:00
AppID: util.NewUUID(),
2020-09-17 15:45:46 +08:00
TenantID: req.TenantID,
}
if err := db.GetManager().TenantApplicationDao().AddModel(appReq); err != nil {
return nil, err
}
return req, nil
}
2020-09-17 16:43:53 +08:00
// ListApps -
func (a *TenantApplicationAction) ListApps(tenantID string, page, pageSize int) ([]*dbmodel.Application, int64, error) {
apps, total, err := db.GetManager().TenantApplicationDao().ListApps(tenantID, page, pageSize)
if err != nil && err != gorm.ErrRecordNotFound {
return nil, 0, err
}
return apps, total, nil
}