♻️ Use the new dealer BaseUser and remove ExternalID

This commit is contained in:
2024-09-11 23:42:46 +08:00
parent aab0724653
commit a131a5bf86
20 changed files with 65 additions and 163 deletions

View File

@ -1,21 +1,12 @@
package models
// Account profiles basically fetched from Hydrogen.Passport
// But cache at here for better usage
// At the same time this model can make relations between local models
type Account struct {
BaseModel
import "git.solsynth.dev/hydrogen/dealer/pkg/hyper"
Name string `json:"name"`
Nick string `json:"nick"`
Avatar string `json:"avatar"`
Banner string `json:"banner"`
Description string `json:"description"`
EmailAddress string `json:"email_address"`
PowerLevel int `json:"power_level"`
Posts []Post `json:"posts" gorm:"foreignKey:AuthorID"`
Reactions []Reaction `json:"reactions"`
ExternalID uint `json:"external_id"`
type Account struct {
hyper.BaseUser
Posts []Post `json:"posts" gorm:"foreignKey:AuthorID"`
Reactions []Reaction `json:"reactions"`
TotalUpvote int `json:"total_upvote"`
TotalDownvote int `json:"total_downvote"`

View File

@ -1,17 +0,0 @@
package models
import (
"time"
"gorm.io/datatypes"
"gorm.io/gorm"
)
type JSONMap = datatypes.JSONType[map[string]any]
type BaseModel struct {
ID uint `json:"id" gorm:"primaryKey"`
CreatedAt time.Time `json:"created_at"`
UpdatedAt time.Time `json:"updated_at"`
DeletedAt gorm.DeletedAt `json:"deleted_at" gorm:"index"`
}

View File

@ -1,7 +1,9 @@
package models
import "git.solsynth.dev/hydrogen/dealer/pkg/hyper"
type Tag struct {
BaseModel
hyper.BaseModel
Alias string `json:"alias" gorm:"uniqueIndex" validate:"lowercase"`
Name string `json:"name"`
@ -10,7 +12,7 @@ type Tag struct {
}
type Category struct {
BaseModel
hyper.BaseModel
Alias string `json:"alias" gorm:"uniqueIndex" validate:"lowercase,alphanum"`
Name string `json:"name"`

View File

@ -3,6 +3,7 @@ package models
import (
"time"
"git.solsynth.dev/hydrogen/dealer/pkg/hyper"
"gorm.io/datatypes"
)
@ -22,7 +23,7 @@ const (
)
type Post struct {
BaseModel
hyper.BaseModel
Type string `json:"type"`
Body datatypes.JSONMap `json:"body"`

View File

@ -1,15 +1,9 @@
package models
// Realm profiles basically fetched from Hydrogen.Passport
// But cache at here for better usage and database relations
type Realm struct {
BaseModel
import "git.solsynth.dev/hydrogen/dealer/pkg/hyper"
Alias string `json:"alias"`
Name string `json:"name"`
Description string `json:"description"`
Posts []Post `json:"posts"`
IsPublic bool `json:"is_public"`
IsCommunity bool `json:"is_community"`
ExternalID uint `json:"external_id"`
type Realm struct {
hyper.BaseRealm
Posts []Post `json:"posts"`
}