init
This commit is contained in:
26
backend/internal/models/social_rating.go
Normal file
26
backend/internal/models/social_rating.go
Normal file
@@ -0,0 +1,26 @@
|
||||
package models
|
||||
|
||||
import "time"
|
||||
|
||||
type SocialRatingOperation struct {
|
||||
ID uint `json:"id" gorm:"primaryKey"`
|
||||
TargetUserID uint `json:"targetUserId" gorm:"not null;index"`
|
||||
TargetUser User `json:"-" gorm:"foreignKey:TargetUserID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
|
||||
ActorUserID *uint `json:"actorUserId,omitempty" gorm:"index"`
|
||||
ActorUser *User `json:"-" gorm:"foreignKey:ActorUserID;constraint:OnUpdate:CASCADE,OnDelete:SET NULL"`
|
||||
Delta int `json:"delta" gorm:"not null"`
|
||||
OperationType string `json:"operationType" gorm:"size:32;not null;index"`
|
||||
Reason string `json:"reason,omitempty" gorm:"size:255"`
|
||||
Source string `json:"source,omitempty" gorm:"size:64;index"`
|
||||
BalanceAfter int `json:"balanceAfter" gorm:"not null"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
}
|
||||
|
||||
type UserSocialRating struct {
|
||||
UserID uint `json:"userId" gorm:"primaryKey"`
|
||||
User User `json:"-" gorm:"foreignKey:UserID;constraint:OnUpdate:CASCADE,OnDelete:CASCADE"`
|
||||
Score int `json:"score" gorm:"not null;default:0;index"`
|
||||
LastOperationID *uint `json:"lastOperationId,omitempty" gorm:"index"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
23
backend/internal/models/user.go
Normal file
23
backend/internal/models/user.go
Normal file
@@ -0,0 +1,23 @@
|
||||
package models
|
||||
|
||||
import (
|
||||
"time"
|
||||
|
||||
"gorm.io/gorm"
|
||||
)
|
||||
|
||||
type User struct {
|
||||
ID uint `json:"id" gorm:"primaryKey"`
|
||||
Email string `json:"email" gorm:"size:255;uniqueIndex;not null"`
|
||||
PasswordHash string `json:"-" gorm:"size:255;not null"`
|
||||
IsAdmin bool `json:"isAdmin" gorm:"not null;default:false;index"`
|
||||
SocialRating *UserSocialRating `json:"socialRating,omitempty" gorm:"foreignKey:UserID"`
|
||||
CreatedAt time.Time `json:"createdAt"`
|
||||
UpdatedAt time.Time `json:"updatedAt"`
|
||||
}
|
||||
|
||||
func (u *User) AfterCreate(tx *gorm.DB) error {
|
||||
return tx.FirstOrCreate(&UserSocialRating{}, UserSocialRating{
|
||||
UserID: u.ID,
|
||||
}).Error
|
||||
}
|
||||
Reference in New Issue
Block a user