diff --git a/pkg/models/realms.go b/pkg/models/realms.go index 4e5154b..c5482a4 100644 --- a/pkg/models/realms.go +++ b/pkg/models/realms.go @@ -1,5 +1,13 @@ package models +type RealmType = int + +const ( + RealmTypePublic = RealmType(iota) + RealmTypeRestricted + RealmTypePrivate +) + type Realm struct { BaseModel @@ -8,7 +16,7 @@ type Realm struct { Articles []Article `json:"article"` Moments []Moment `json:"moments"` Members []RealmMember `json:"members"` - IsPublic bool `json:"is_public"` + RealmType RealmType `json:"realm_type"` AccountID uint `json:"account_id"` } diff --git a/pkg/server/realms_api.go b/pkg/server/realms_api.go index 649f4f8..14cdcdc 100644 --- a/pkg/server/realms_api.go +++ b/pkg/server/realms_api.go @@ -60,14 +60,14 @@ func createRealm(c *fiber.Ctx) error { var data struct { Name string `json:"name" validate:"required"` Description string `json:"description"` - IsPublic bool `json:"is_public"` + RealmType int `json:"realm_type"` } if err := BindAndValidate(c, &data); err != nil { return err } - realm, err := services.NewRealm(user, data.Name, data.Description, data.IsPublic) + realm, err := services.NewRealm(user, data.Name, data.Description, data.RealmType) if err != nil { return fiber.NewError(fiber.StatusBadRequest, err.Error()) } @@ -150,7 +150,7 @@ func editRealm(c *fiber.Ctx) error { var data struct { Name string `json:"name" validate:"required"` Description string `json:"description"` - IsPublic bool `json:"is_public"` + RealmType int `json:"realm_type"` } if err := BindAndValidate(c, &data); err != nil { @@ -165,7 +165,7 @@ func editRealm(c *fiber.Ctx) error { return fiber.NewError(fiber.StatusNotFound, err.Error()) } - realm, err := services.EditRealm(realm, data.Name, data.Description, data.IsPublic) + realm, err := services.EditRealm(realm, data.Name, data.Description, data.RealmType) if err != nil { return fiber.NewError(fiber.StatusBadRequest, err.Error()) } diff --git a/pkg/services/posts.go b/pkg/services/posts.go index aa6a6f3..c6f0c98 100644 --- a/pkg/services/posts.go +++ b/pkg/services/posts.go @@ -274,7 +274,7 @@ func NewPost[T models.PostInterface](item T) (T, error) { } if item.GetRealm() != nil { - if !item.GetRealm().IsPublic { + if item.GetRealm().RealmType != models.RealmTypePublic { var member models.RealmMember if err := database.C.Where(&models.RealmMember{ RealmID: item.GetRealm().ID, diff --git a/pkg/services/realms.go b/pkg/services/realms.go index 3f74d2b..f162258 100644 --- a/pkg/services/realms.go +++ b/pkg/services/realms.go @@ -38,7 +38,7 @@ func ListRealmIsAvailable(user models.Account) ([]models.Realm, error) { }) if err := database.C.Where(&models.Realm{ - IsPublic: true, + RealmType: models.RealmTypePublic, }).Or("id IN ?", idx).Find(&realms).Error; err != nil { return realms, err } @@ -46,12 +46,12 @@ func ListRealmIsAvailable(user models.Account) ([]models.Realm, error) { return realms, nil } -func NewRealm(user models.Account, name, description string, isPublic bool) (models.Realm, error) { +func NewRealm(user models.Account, name, description string, realmType int) (models.Realm, error) { realm := models.Realm{ Name: name, Description: description, AccountID: user.ID, - IsPublic: isPublic, + RealmType: realmType, Members: []models.RealmMember{ {AccountID: user.ID}, }, @@ -86,10 +86,10 @@ func KickRealmMember(user models.Account, target models.Realm) error { return database.C.Delete(&member).Error } -func EditRealm(realm models.Realm, name, description string, isPublic bool) (models.Realm, error) { +func EditRealm(realm models.Realm, name, description string, realmType int) (models.Realm, error) { realm.Name = name realm.Description = description - realm.IsPublic = isPublic + realm.RealmType = realmType err := database.C.Save(&realm).Error diff --git a/pkg/views/index.html b/pkg/views/index.html index 26caf57..cf6b46c 100644 --- a/pkg/views/index.html +++ b/pkg/views/index.html @@ -2,7 +2,7 @@
- +