Documentation ¶
Index ¶
- func InitializeDB(connection string) error
- func StopDB()
- type Profile
- type Tag
- type User
- func (u User) CheckPassword(password string) bool
- func (u *User) FollowUser(username string) error
- func (u *User) GetProfile(following bool) Profile
- func (u *User) IsFollowingUser(username string) bool
- func (u *User) Save()
- func (u *User) UnFollowUser(username string) error
- func (u *User) UpdatePassword(newPassword string) error
- func (u *User) UpdateUser(newUser User)
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func InitializeDB ¶
InitializeDB create a connection with the database and migrates all models
Types ¶
type Profile ¶
type Profile struct { Username string `json:"username"` Bio string `json:"bio"` Image string `json:"image"` Following bool `json:"following"` }
Profile is a subset of the user model meant for presentation
func ProfileFromUser ¶
ProfileFromUser creates a new profile object from a user
type Tag ¶
type Tag struct { ID uint `json:"-" gorm:"unique;not null;primary_key"` Name string `json:"name" gorm:"unique;not null"` }
Tag describe article content
func (*Tag) MarshalJSON ¶
MarshalJSON encodes the tag as a single string
func (*Tag) UnmarshalJSON ¶
UnmarshalJSON decodes a tag from a single string
type User ¶
type User struct { ID uint `json:"-" gorm:"unique;not null;primary_key"` Username string `json:"username" gorm:"unique;not null"` Email string `json:"email" gorm:"unique;not null"` Bio string `json:"bio"` Image string `json:"image"` // image url? Hash string `json:"-" gorm:"not null"` Token string `json:"token" gorm:"-"` // Self referencing many 2 many relationship // http://gorm.io/docs/many_to_many.html Following []User `json:"-" gorm:"many2many:followings;association_jointable_foreignkey:follower_id"` }
User is a database model to hold user information
func (User) CheckPassword ¶
CheckPassword compares a given password to the users hashed password
func (*User) FollowUser ¶
FollowUser adds a new user to this users following list
func (*User) GetProfile ¶
GetProfile returns the profile for a user
func (*User) IsFollowingUser ¶
IsFollowingUser return bool indicating whether a user is in this users following list
func (*User) UnFollowUser ¶
UnFollowUser removes a user to this users following list
func (*User) UpdatePassword ¶
UpdatePassword hashes a new password and updates the stored hash (DOES NOT SAVE TO DB)
func (*User) UpdateUser ¶
UpdateUser updates fields on the User model, does not update password. (Does not save to db)