Enchance user profile

💥 Move description from account to profile
This commit is contained in:
LittleSheep 2025-03-02 12:00:29 +08:00
parent 4616f7cc93
commit 5979fd5b2c
4 changed files with 47 additions and 14 deletions

View File

@ -17,7 +17,6 @@ type Account struct {
Name string `json:"name" gorm:"uniqueIndex"` Name string `json:"name" gorm:"uniqueIndex"`
Nick string `json:"nick"` Nick string `json:"nick"`
Description string `json:"description"`
Avatar *string `json:"avatar"` Avatar *string `json:"avatar"`
Banner *string `json:"banner"` Banner *string `json:"banner"`
ConfirmedAt *time.Time `json:"confirmed_at"` ConfirmedAt *time.Time `json:"confirmed_at"`
@ -39,6 +38,9 @@ type Account struct {
Factors []AuthFactor `json:"factors,omitempty"` Factors []AuthFactor `json:"factors,omitempty"`
Relations []AccountRelationship `json:"relations,omitempty" gorm:"foreignKey:AccountID"` Relations []AccountRelationship `json:"relations,omitempty" gorm:"foreignKey:AccountID"`
// Keep this for backward compability
Description string `json:"description" gorm:"-"`
} }
func (v Account) GetAvatar() *string { func (v Account) GetAvatar() *string {

View File

@ -8,6 +8,7 @@ import (
) )
type AuthConfig struct { type AuthConfig struct {
AlwaysRisky bool `json:"always_risky"`
MaximumAuthSteps int `json:"maximum_auth_steps" validate:"required,min=1,max=99"` MaximumAuthSteps int `json:"maximum_auth_steps" validate:"required,min=1,max=99"`
} }

View File

@ -2,6 +2,8 @@ package models
import ( import (
"time" "time"
"gorm.io/datatypes"
) )
type AccountProfile struct { type AccountProfile struct {
@ -9,8 +11,21 @@ type AccountProfile struct {
FirstName string `json:"first_name"` FirstName string `json:"first_name"`
LastName string `json:"last_name"` LastName string `json:"last_name"`
Description string `json:"description"`
TimeZone string `json:"time_zone"`
Location string `json:"location"`
Pronouns string `json:"pronouns"`
Gender string `json:"gender"`
Links datatypes.JSONMap `json:"links"`
Experience uint64 `json:"experience"` Experience uint64 `json:"experience"`
LastSeenAt *time.Time `json:"last_seen_at"` LastSeenAt *time.Time `json:"last_seen_at"`
Birthday *time.Time `json:"birthday"` Birthday *time.Time `json:"birthday"`
AccountID uint `json:"account_id"` AccountID uint `json:"account_id"`
} }
type AccountPage struct {
BaseModel
Content string `json:"content"`
AccountID uint `json:"account_id"`
}

View File

@ -123,6 +123,11 @@ func updateUserinfo(c *fiber.Ctx) error {
Description string `json:"description"` Description string `json:"description"`
FirstName string `json:"first_name"` FirstName string `json:"first_name"`
LastName string `json:"last_name"` LastName string `json:"last_name"`
Location string `json:"location"`
TimeZone string `json:"time_zone"`
Gender string `json:"gender"`
Pronouns string `json:"pronouns"`
Links map[string]string `json:"links"`
Birthday time.Time `json:"birthday"` Birthday time.Time `json:"birthday"`
} }
@ -143,8 +148,18 @@ func updateUserinfo(c *fiber.Ctx) error {
return fiber.NewError(fiber.StatusInternalServerError, err.Error()) return fiber.NewError(fiber.StatusInternalServerError, err.Error())
} }
var links = make(map[string]any)
for k, v := range data.Links {
links[k] = v
}
account.Nick = data.Nick account.Nick = data.Nick
account.Description = data.Description account.Profile.Gender = data.Gender
account.Profile.Pronouns = data.Pronouns
account.Profile.Location = data.Location
account.Profile.TimeZone = data.TimeZone
account.Profile.Links = links
account.Profile.Description = data.Description
account.Profile.FirstName = data.FirstName account.Profile.FirstName = data.FirstName
account.Profile.LastName = data.LastName account.Profile.LastName = data.LastName
account.Profile.Birthday = &data.Birthday account.Profile.Birthday = &data.Birthday