Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
karminski committed Jul 10, 2023
2 parents 43e7374 + b630d9d commit dec31e2
Show file tree
Hide file tree
Showing 39 changed files with 1,624 additions and 796 deletions.
464 changes: 301 additions & 163 deletions api/resthandler/app.go

Large diffs are not rendered by default.

1 change: 1 addition & 0 deletions api/resthandler/utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ const (
ERROR_FLAG_CAN_NOT_CREATE_ACTION = "ERROR_FLAG_CAN_NOT_CREATE_ACTION"
ERROR_FLAG_CAN_NOT_CREATE_RESOURCE = "ERROR_FLAG_CAN_NOT_CREATE_RESOURCE"
ERROR_FLAG_CAN_NOT_CREATE_APP = "ERROR_FLAG_CAN_NOT_CREATE_APP"
ERROR_FLAG_CAN_NOT_CREATE_STATE = "ERROR_FLAG_CAN_NOT_CREATE_STATE"

// can not get resource
ERROR_FLAG_CAN_NOT_GET_USER = "ERROR_FLAG_CAN_NOT_GET_USER"
Expand Down
1 change: 0 additions & 1 deletion api/router/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,6 @@ func NewAppRouterImpl(appRestHandler resthandler.AppRestHandler) *AppRouterImpl
func (impl AppRouterImpl) InitAppRouter(appRouter *gin.RouterGroup) {
appRouter.POST("", impl.appRestHandler.CreateApp)
appRouter.DELETE(":appID", impl.appRestHandler.DeleteApp)
appRouter.PUT(":appID", impl.appRestHandler.RenameApp)
appRouter.PATCH(":appID/config", impl.appRestHandler.ConfigApp)
appRouter.GET("", impl.appRestHandler.GetAllApps)
appRouter.GET(":appID/versions/:version", impl.appRestHandler.GetMegaData)
Expand Down
2 changes: 1 addition & 1 deletion cmd/http-server/wire_gen.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions cmd/websocket-server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ var kvssi *state.KVStateServiceImpl
var sssi *state.SetStateServiceImpl
var asi *app.AppServiceImpl
var rsi *resource.ResourceServiceImpl
var appRepositoryImpl *repository.AppRepositoryImpl

func initEnv() error {
sugaredLogger := util.NewSugardLogger()
Expand All @@ -59,7 +60,7 @@ func initEnv() error {
treestateRepositoryImpl := repository.NewTreeStateRepositoryImpl(sugaredLogger, gormDB)
kvstateRepositoryImpl := repository.NewKVStateRepositoryImpl(sugaredLogger, gormDB)
setstateRepositoryImpl := repository.NewSetStateRepositoryImpl(sugaredLogger, gormDB)
appRepositoryImpl := repository.NewAppRepositoryImpl(sugaredLogger, gormDB)
appRepositoryImpl = repository.NewAppRepositoryImpl(sugaredLogger, gormDB)
resourceRepositoryImpl := repository.NewResourceRepositoryImpl(sugaredLogger, gormDB)
actionRepositoryImpl := repository.NewActionRepositoryImpl(sugaredLogger, gormDB)
// init service
Expand All @@ -73,13 +74,14 @@ func initEnv() error {

var hub *ws.Hub

func InitHub(asi *app.AppServiceImpl, rsi *resource.ResourceServiceImpl, tssi *state.TreeStateServiceImpl, kvssi *state.KVStateServiceImpl, sssi *state.SetStateServiceImpl) {
func InitHub(asi *app.AppServiceImpl, rsi *resource.ResourceServiceImpl, tssi *state.TreeStateServiceImpl, kvssi *state.KVStateServiceImpl, sssi *state.SetStateServiceImpl, appRepository *repository.AppRepositoryImpl) {
hub = ws.NewHub()
hub.SetAppServiceImpl(asi)
hub.SetResourceServiceImpl(rsi)
hub.SetTreeStateServiceImpl(tssi)
hub.SetKVStateServiceImpl(kvssi)
hub.SetSetStateServiceImpl(sssi)
hub.SetAppRepositoryImpl(appRepositoryImpl)
go filter.Run(hub)
}

Expand Down Expand Up @@ -131,7 +133,7 @@ func main() {

// init
initEnv()
InitHub(asi, rsi, tssi, kvssi, sssi)
InitHub(asi, rsi, tssi, kvssi, sssi, appRepositoryImpl)

// listen and serve
r := mux.NewRouter()
Expand Down
38 changes: 38 additions & 0 deletions internal/datacontrol/data_control.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,10 @@
package datacontrol

import (
"fmt"
"strconv"
"strings"

"github.com/illacloud/builder-backend/internal/repository"

supervisior "github.com/illacloud/builder-backend/internal/util/supervisior"
Expand All @@ -27,6 +31,40 @@ func GetUserInfo(targetUserID int) (*repository.User, error) {
return user, nil
}

func GetMultiUserInfo(targetUserIDs []int) (map[int]*repository.User, error) {
// init sdk
instance, err := supervisior.NewSupervisior()
if err != nil {
return nil, err
}

// convert to query param
targetUserIDsInString := make([]string, 0)
for _, userIDInt := range targetUserIDs {
userIDString := strconv.Itoa(userIDInt)
if len(userIDString) != 0 {
targetUserIDsInString = append(targetUserIDsInString, strconv.Itoa(userIDInt))
}
}
requestParams := strings.Join(targetUserIDsInString, ",")
fmt.Printf("[DUMP] datacontrol.GetMultiUserInfo.requestParams: %+v\n", requestParams)

// fetch raw data
usersRaw, errInGetTargetUser := instance.GetMultiUser(requestParams)
fmt.Printf("[DUMP] datacontrol.GetMultiUserInfo.usersRaw: %+v\n", usersRaw)

if errInGetTargetUser != nil {
return nil, errInGetTargetUser
}

// construct
users, errInNewUsers := repository.NewUsersByDataControlRawData(usersRaw)
if errInNewUsers != nil {
return nil, errInNewUsers
}
return users, nil
}

func GetTeamInfoByIdentifier(targetTeamIdentifier string) (*repository.Team, error) {
// init sdk
instance, err := supervisior.NewSupervisior()
Expand Down
9 changes: 9 additions & 0 deletions internal/repository/action.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import (
"time"

"github.com/google/uuid"
"github.com/illacloud/builder-backend/internal/util/resourcelist"
"github.com/illacloud/builder-backend/pkg/db"

"go.uber.org/zap"
Expand Down Expand Up @@ -85,6 +86,14 @@ func (action *Action) ExportConfig() *ActionConfig {
return ac
}

func (action *Action) ExportDisplayName() string {
return action.Name
}

func (action *Action) ExportTypeInString() string {
return resourcelist.GetResourceIDMappedType(action.Type)
}

func (action *Action) IsPublic() bool {
ac := action.ExportConfig()
return ac.Public
Expand Down
File renamed without changes.
48 changes: 48 additions & 0 deletions internal/repository/action_for_export.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package repository

import (
"time"

"github.com/google/uuid"
"github.com/illacloud/builder-backend/internal/idconvertor"
)

type ActionForExport struct {
ID string `json:"actionId"`
UID uuid.UUID `json:"uid"`
TeamID string `json:"teamID"`
App string `json:"-"`
Version int `json:"-"`
Resource string `json:"resourceId,omitempty"`
DisplayName string `json:"displayName"`
Type string `json:"actionType"`
Template map[string]interface{} `json:"content"`
Transformer map[string]interface{} `json:"transformer"`
TriggerMode string `json:"triggerMode"`
Config *ActionConfig `json:"config"`
CreatedAt time.Time `json:"createdAt,omitempty"`
CreatedBy string `json:"createdBy,omitempty"`
UpdatedAt time.Time `json:"updatedAt,omitempty"`
UpdatedBy string `json:"updatedBy,omitempty"`
}

func NewActionForExport(action *Action) *ActionForExport {
return &ActionForExport{
ID: idconvertor.ConvertIntToString(action.ID),
UID: action.UID,
TeamID: idconvertor.ConvertIntToString(action.TeamID),
App: idconvertor.ConvertIntToString(action.App),
Version: action.Version,
Resource: idconvertor.ConvertIntToString(action.Resource),
DisplayName: action.ExportDisplayName(),
Type: action.ExportTypeInString(),
Template: action.Template,
Transformer: action.Transformer,
TriggerMode: action.TriggerMode,
Config: action.ExportConfig(),
CreatedAt: action.CreatedAt,
CreatedBy: idconvertor.ConvertIntToString(action.CreatedBy),
UpdatedAt: action.UpdatedAt,
UpdatedBy: idconvertor.ConvertIntToString(action.UpdatedBy),
}
}
Loading

0 comments on commit dec31e2

Please sign in to comment.