Skip to content

Commit

Permalink
add followers and followings model
Browse files Browse the repository at this point in the history
  • Loading branch information
juunini committed Oct 26, 2023
1 parent f1507cd commit af5ec3c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 6 deletions.
2 changes: 2 additions & 0 deletions models/migrate.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,7 @@ func Migrate() {
&UserKeyPair{},
&UserInbox{},
&RemoteUserPublicKey{},
&UserFollower{},
&UserFollowing{},
)
}
14 changes: 8 additions & 6 deletions models/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@ import (
)

type User struct {
ID string `gorm:"primaryKey"`
Profile UserProfile `gorm:"foreignKey:ID;constraint:OnDelete:CASCADE;"`
KeyPair UserKeyPair `gorm:"foreignKey:ID;constraint:OnDelete:CASCADE;"`
Inbox UserInbox `gorm:"foreignKey:To;constraint:OnDelete:CASCADE;"`
CreatedAt time.Time
DeletedAt gorm.DeletedAt
ID string `gorm:"primaryKey"`
CreatedAt time.Time
DeletedAt gorm.DeletedAt
Profile UserProfile `gorm:"foreignKey:ID;constraint:OnDelete:CASCADE;"`
KeyPair UserKeyPair `gorm:"foreignKey:ID;constraint:OnDelete:CASCADE;"`
Inbox UserInbox `gorm:"foreignKey:To;constraint:OnDelete:CASCADE;"`
Followers []UserFollower `gorm:"foreignKey:ID;constraint:OnDelete:CASCADE;"`
Followings []UserFollowing `gorm:"foreignKey:ID;constraint:OnDelete:CASCADE;"`
}

func (u User) Exists() bool {
Expand Down
9 changes: 9 additions & 0 deletions models/user_follower.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package models

import "time"

type UserFollower struct {
ID string `gorm:"primaryKey;uniqueIndex:idx_user_follower;"`
Follower string `gorm:"type:text;uniqueIndex:idx_user_follower;"`
CreatedAt time.Time
}
9 changes: 9 additions & 0 deletions models/user_following.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package models

import "time"

type UserFollowing struct {
ID string `gorm:"primaryKey;uniqueIndex:idx_user_following;"`
Following string `gorm:"type:text;uniqueIndex:idx_user_following;"`
CreatedAt time.Time
}

0 comments on commit af5ec3c

Please sign in to comment.