From 313f6b8d4f26fa60bb4a727b7b2c7ad88a1ce916 Mon Sep 17 00:00:00 2001 From: LittleSheep Date: Wed, 11 Sep 2024 22:31:30 +0800 Subject: [PATCH] :sparkles: Realm avatar, banner and access policy --- .idea/dataSources.local.xml | 2 +- .idea/workspace.xml | 14 +++++---- pkg/internal/models/realms.go | 19 +++++++----- pkg/internal/server/api/realms_api.go | 44 +++++++++++++++++---------- 4 files changed, 49 insertions(+), 30 deletions(-) diff --git a/.idea/dataSources.local.xml b/.idea/dataSources.local.xml index 331a5b8..839bfe2 100644 --- a/.idea/dataSources.local.xml +++ b/.idea/dataSources.local.xml @@ -1,6 +1,6 @@ - + " diff --git a/.idea/workspace.xml b/.idea/workspace.xml index 6ce3afb..8b424ea 100644 --- a/.idea/workspace.xml +++ b/.idea/workspace.xml @@ -4,9 +4,11 @@ - + + - + + - @@ -178,7 +179,8 @@ - true diff --git a/pkg/internal/models/realms.go b/pkg/internal/models/realms.go index bbb5b32..39c3d36 100644 --- a/pkg/internal/models/realms.go +++ b/pkg/internal/models/realms.go @@ -1,15 +1,20 @@ package models +import "gorm.io/datatypes" + type Realm struct { BaseModel - Alias string `json:"alias" gorm:"uniqueIndex"` - Name string `json:"name"` - Description string `json:"description"` - Members []RealmMember `json:"members"` - IsPublic bool `json:"is_public"` - IsCommunity bool `json:"is_community"` - AccountID uint `json:"account_id"` + Alias string `json:"alias" gorm:"uniqueIndex"` + Name string `json:"name"` + Description string `json:"description"` + Members []RealmMember `json:"members"` + Avatar *string `json:"avatar"` + Banner *string `json:"banner"` + AccessPolicy datatypes.JSONMap `json:"access_policy"` + IsPublic bool `json:"is_public"` + IsCommunity bool `json:"is_community"` + AccountID uint `json:"account_id"` } type RealmMember struct { diff --git a/pkg/internal/server/api/realms_api.go b/pkg/internal/server/api/realms_api.go index 1a34a90..728209e 100644 --- a/pkg/internal/server/api/realms_api.go +++ b/pkg/internal/server/api/realms_api.go @@ -57,11 +57,14 @@ func createRealm(c *fiber.Ctx) error { user := c.Locals("user").(models.Account) var data struct { - Alias string `json:"alias" validate:"required,lowercase,min=4,max=32"` - Name string `json:"name" validate:"required"` - Description string `json:"description"` - IsPublic bool `json:"is_public"` - IsCommunity bool `json:"is_community"` + Alias string `json:"alias" validate:"required,lowercase,min=4,max=32"` + Name string `json:"name" validate:"required"` + Description string `json:"description"` + Avatar *string `json:"avatar"` + Banner *string `json:"banner"` + AccessPolicy map[string]any `json:"access_policy"` + IsPublic bool `json:"is_public"` + IsCommunity bool `json:"is_community"` } if err := exts.BindAndValidate(c, &data); err != nil { @@ -69,12 +72,15 @@ func createRealm(c *fiber.Ctx) error { } realm, err := services.NewRealm(models.Realm{ - Alias: data.Alias, - Name: data.Name, - Description: data.Description, - IsPublic: data.IsPublic, - IsCommunity: data.IsCommunity, - AccountID: user.ID, + Alias: data.Alias, + Name: data.Name, + Description: data.Description, + Avatar: data.Avatar, + Banner: data.Banner, + AccessPolicy: data.AccessPolicy, + IsPublic: data.IsPublic, + IsCommunity: data.IsCommunity, + AccountID: user.ID, }, user) if err != nil { @@ -91,11 +97,14 @@ func editRealm(c *fiber.Ctx) error { id, _ := c.ParamsInt("realmId", 0) var data struct { - Alias string `json:"alias" validate:"required,lowercase,min=4,max=32"` - Name string `json:"name" validate:"required"` - Description string `json:"description"` - IsPublic bool `json:"is_public"` - IsCommunity bool `json:"is_community"` + Alias string `json:"alias" validate:"required,lowercase,min=4,max=32"` + Name string `json:"name" validate:"required"` + Description string `json:"description"` + Avatar *string `json:"avatar"` + Banner *string `json:"banner"` + AccessPolicy map[string]any `json:"access_policy"` + IsPublic bool `json:"is_public"` + IsCommunity bool `json:"is_community"` } if err := exts.BindAndValidate(c, &data); err != nil { @@ -113,6 +122,9 @@ func editRealm(c *fiber.Ctx) error { realm.Alias = data.Alias realm.Name = data.Name realm.Description = data.Description + realm.Avatar = data.Avatar + realm.Banner = data.Banner + realm.AccessPolicy = data.AccessPolicy realm.IsPublic = data.IsPublic realm.IsCommunity = data.IsCommunity