Friends api

This commit is contained in:
2024-04-06 01:07:36 +08:00
parent 0b436c0a1e
commit 6850f64fe3
12 changed files with 366 additions and 32 deletions

View File

@ -11,24 +11,32 @@ import (
type Account struct {
BaseModel
Name string `json:"name" gorm:"uniqueIndex"`
Nick string `json:"nick"`
Description string `json:"description"`
Avatar string `json:"avatar"`
Banner string `json:"banner"`
Profile AccountProfile `json:"profile"`
PersonalPage AccountPage `json:"personal_page"`
Sessions []AuthSession `json:"sessions"`
Challenges []AuthChallenge `json:"challenges"`
Factors []AuthFactor `json:"factors"`
Contacts []AccountContact `json:"contacts"`
Events []ActionEvent `json:"events"`
MagicTokens []MagicToken `json:"-" gorm:"foreignKey:AssignTo"`
ThirdClients []ThirdClient `json:"clients"`
Name string `json:"name" gorm:"uniqueIndex"`
Nick string `json:"nick"`
Description string `json:"description"`
Avatar string `json:"avatar"`
Banner string `json:"banner"`
ConfirmedAt *time.Time `json:"confirmed_at"`
PowerLevel int `json:"power_level"`
Profile AccountProfile `json:"profile"`
PersonalPage AccountPage `json:"personal_page"`
Contacts []AccountContact `json:"contacts"`
Sessions []AuthSession `json:"sessions"`
Challenges []AuthChallenge `json:"challenges"`
Factors []AuthFactor `json:"factors"`
Events []ActionEvent `json:"events"`
MagicTokens []MagicToken `json:"-" gorm:"foreignKey:AssignTo"`
ThirdClients []ThirdClient `json:"clients"`
Notifications []Notification `json:"notifications" gorm:"foreignKey:RecipientID"`
NotifySubscribers []NotificationSubscriber `json:"notify_subscribers"`
ConfirmedAt *time.Time `json:"confirmed_at"`
PowerLevel int `json:"power_level"`
Friendships []AccountFriendship `json:"friendships" gorm:"foreignKey:AccountID"`
RelatedFriendships []AccountFriendship `json:"related_friendships" gorm:"foreignKey:RelatedID"`
}
func (v Account) GetPrimaryEmail() AccountContact {
@ -64,3 +72,21 @@ type AccountContact struct {
VerifiedAt *time.Time `json:"verified_at"`
AccountID uint `json:"account_id"`
}
type FriendshipStatus = int8
const (
FriendshipPending = FriendshipStatus(iota)
FriendshipActive
FriendshipBlocked
)
type AccountFriendship struct {
BaseModel
AccountID uint `json:"account_id"`
RelatedID uint `json:"related_id"`
Account Account `json:"account"`
Related Account `json:"related"`
Status FriendshipStatus `json:"status"`
}