Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

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

20 changes: 20 additions & 0 deletions builder/store/database/namespace.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"context"
"time"

"github.com/uptrace/bun"
"opencsg.com/csghub-server/common/errorx"
)

Expand All @@ -13,6 +14,7 @@ type NamespaceStore interface {
FindByUUID(ctx context.Context, uuid string) (Namespace, error)
Exists(ctx context.Context, path string) (bool, error)
ExistsByUUID(ctx context.Context, uuid string) (bool, error)
FindByUUIDs(ctx context.Context, uuids []string) ([]Namespace, error)
}

type NamespaceStoreImpl struct {
Expand Down Expand Up @@ -49,6 +51,7 @@ type Namespace struct {
func (s *NamespaceStoreImpl) FindByPath(ctx context.Context, path string) (namespace Namespace, err error) {
namespace.Path = path
err = s.db.Operator.Core.NewSelect().Model(&namespace).Relation("User").Where("path = ?", path).Scan(ctx)
err = errorx.HandleDBError(err, errorx.Ctx().Set("namespace", path))
return
}

Expand Down Expand Up @@ -81,3 +84,20 @@ func (s *NamespaceStoreImpl) FindByUUID(ctx context.Context, uuid string) (names
}
return namespace, nil
}

func (s *NamespaceStoreImpl) FindByUUIDs(ctx context.Context, uuids []string) (namespaces []Namespace, err error) {
if len(uuids) == 0 {
return namespaces, nil
}

err = s.db.Operator.Core.
NewSelect().
Model(&namespaces).
Where("uuid IN (?)", bun.In(uuids)).
Scan(ctx)
if err != nil {
return namespaces, errorx.HandleDBError(err, errorx.Ctx().Set("uuids", uuids))
}

return namespaces, nil
}
26 changes: 14 additions & 12 deletions common/types/accounting.go
Original file line number Diff line number Diff line change
Expand Up @@ -449,6 +449,8 @@ type RechargeResp struct {
UpdatedAt time.Time `json:"updated_at"`
Description string `json:"description"`
UserName string `json:"user_name"`
EntityType string `json:"entity_type"`
OrgName string `json:"org_name"`
}

const RechargeExtraType = "recharge"
Expand Down Expand Up @@ -531,18 +533,18 @@ type RechargesIndexResp struct {
}

type PresentIndexResp struct {
ID int64 `json:"id"`
EventUUID string `json:"event_uuid"`
UserUUID string `json:"user_uuid"`
UserName string `json:"user_name"`
ActivityID int64 `json:"activity_id"`
Value float64 `json:"value"`
OpUID string `json:"op_uid"`
OpDesc string `json:"op_desc"`
ParticipantUUID string `json:"participant_uuid"`
ExpireAt time.Time `json:"expire_at"`
Status AccountPresentStatus `json:"status"`
CreatedAt time.Time `json:"created_at"`
ID int64 `json:"id"`
EventUUID string `json:"event_uuid"`
UserUUID string `json:"user_uuid"`
UserName string `json:"user_name"`
ActivityID int64 `json:"activity_id"`
Value float64 `json:"value"`
OpUID string `json:"op_uid"`
OpDesc string `json:"op_desc"`
ParticipantUUID string `json:"participant_uuid"`
ExpireAt time.Time `json:"expire_at"`
Status AccountPresentStatus `json:"status"`
CreatedAt time.Time `json:"created_at"`
}

type PresentsIndexResp struct {
Expand Down
4 changes: 3 additions & 1 deletion component/accounting.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ type accountingComponentImpl struct {
accountingClient accounting.AccountingClient
userStore database.UserStore
orgStore database.OrgStore
namespaceStore database.NamespaceStore
memberStore database.MemberStore
deployTaskStore database.DeployTaskStore
userSvcClient rpc.UserSvcClient
Expand Down Expand Up @@ -65,7 +66,8 @@ func NewAccountingComponent(config *config.Config) (AccountingComponent, error)
userSvcClient: userRpcClient,
notificationSvcClient: rpc.NewNotificationSvcHttpClient(fmt.Sprintf("%s:%d", config.Notification.Host, config.Notification.Port),
rpc.AuthWithApiKey(config.APIToken)),
config: config,
config: config,
namespaceStore: database.NewNamespaceStore(),
}, nil
}

Expand Down
Loading