Realm operations now available in authkit

This commit is contained in:
2024-10-31 22:08:51 +08:00
parent 2b4f71e732
commit c3619f6d25
7 changed files with 295 additions and 129 deletions

View File

@ -1,6 +1,10 @@
package models
import "gorm.io/datatypes"
import (
"git.solsynth.dev/hypernet/nexus/pkg/nex"
"git.solsynth.dev/hypernet/passport/pkg/proto"
"gorm.io/datatypes"
)
type Realm struct {
BaseModel
@ -17,6 +21,22 @@ type Realm struct {
AccountID uint `json:"account_id"`
}
func NewRealmFromProto(proto *proto.RealmInfo) Realm {
return Realm{
BaseModel: BaseModel{
ID: uint(proto.GetId()),
},
Alias: proto.GetAlias(),
Name: proto.GetName(),
Description: proto.GetDescription(),
Avatar: &proto.Avatar,
Banner: &proto.Banner,
IsPublic: proto.GetIsPublic(),
IsCommunity: proto.GetIsCommunity(),
AccessPolicy: nex.DecodeMap(proto.GetAccessPolicy()),
}
}
type RealmMember struct {
BaseModel
@ -26,3 +46,14 @@ type RealmMember struct {
Account Account `json:"account"`
PowerLevel int `json:"power_level"`
}
func NewRealmMemberFromProto(proto *proto.RealmMemberInfo) RealmMember {
return RealmMember{
BaseModel: BaseModel{
ID: uint(proto.GetId()),
},
RealmID: uint(proto.GetRealmId()),
AccountID: uint(proto.GetUserId()),
PowerLevel: int(proto.GetPowerLevel()),
}
}