models

package
v0.0.0-...-b51db10 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 12, 2020 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Migrate

func Migrate(db *gorm.DB)

Migrate models using ORM

func SerializeParagraphs

func SerializeParagraphs(paragraphs []Paragraph) []common.JSON

SerializeParagraphs serializes multiple paragraphs into JSON-format

func SerializePosts

func SerializePosts(posts []Post) []common.JSON

SerializePosts serializes a list posts

func SerializeTopics

func SerializeTopics(topics []Topic) []common.JSON

SerializeTopics serializes a list of topics

func SerializeUsers

func SerializeUsers(users []User) []common.JSON

SerializeUsers serializes a list of users

Types

type Follow

type Follow struct {
	gorm.Model
	Following    User
	FollowingID  uint
	FollowedBy   User
	FollowedByID uint
}

Follow data model

func (*Follow) Serialize

func (follow *Follow) Serialize() common.JSON

Serialize serializes the followed model to just show user

type FollowedTopic

type FollowedTopic struct {
	gorm.Model
	User          User
	UserID        uint
	FollowedTopic Topic
	TopicID       uint
}

FollowedTopic bypasses using many2many and makes code cleaner

type Paragraph

type Paragraph struct {
	gorm.Model
	Type    string
	Content string
	PostID  uint
	UUID    string
}

Paragraph struct stores the post's content

func GetParagraphsRelatedToPost

func GetParagraphsRelatedToPost(post Post) ([]Paragraph, bool)

GetParagraphsRelatedToPost gets all the paragraphs in a post

func (*Paragraph) Serialize

func (p *Paragraph) Serialize() common.JSON

Serialize paragraph data

type Post

type Post struct {
	gorm.Model
	Text        string
	Title       string
	Likes       int
	Description string
	ImageURL    string
	User        User
	UserID      uint
	UUID        string
	Paragraphs  []Paragraph
	TopicID     uint
}

Post data model

func FindOnePost

func FindOnePost(condition interface{}) (Post, error)

FindOnePost finds a post matching the given condition

func GetPostWithID

func GetPostWithID(id string) (Post, bool)

GetPostWithID returns a post correspodding to given id

func GetPosts

func GetPosts(offset, limit int) ([]Post, bool)

GetPosts returns a list of posts within a given offset and limit range

func GetPostsFromUser

func GetPostsFromUser(user User) ([]Post, bool)

GetPostsFromUser gets all the posts related to a given user

func GetPostsRelatedToTopic

func GetPostsRelatedToTopic(topic Topic) ([]Post, bool)

GetPostsRelatedToTopic finds all posts in the topic's category

func (*Post) Delete

func (post *Post) Delete()

func (*Post) Save

func (post *Post) Save()

func (*Post) Serialize

func (p *Post) Serialize() common.JSON

Serialize post data

type PostLike

type PostLike struct {
	gorm.Model
	LikedPostID uint
	UserID      uint
}

PostLike model helps keeping track of if a user has already liked a post

func FindPostLikeModel

func FindPostLikeModel(condition interface{}) (PostLike, error)

FindPostLikeModel finds a single postLike model matching given condition

type Topic

type Topic struct {
	gorm.Model
	Title       string
	Description string
	UUID        string
	URL         string
	UserID      uint
	User        User
}

Topic data model

func FindOneTopic

func FindOneTopic(condition interface{}) (Topic, error)

FindOneTopic finds a single topic with the given condition

func GetAllTopics

func GetAllTopics() ([]Topic, bool)

GetAllTopics gets all in the database

func GetAllUsersTopics

func GetAllUsersTopics(user User) ([]Topic, bool)

GetAllUsersTopics returns all the topics created by the given user

func (*Topic) Delete

func (topic *Topic) Delete()

Delete deletes the given topic's entry from the database

func (*Topic) Save

func (topic *Topic) Save()

func (*Topic) Serialize

func (t *Topic) Serialize() common.JSON

Serialize formats topic to JSON-format

type User

type User struct {
	gorm.Model
	Username     string
	PasswordHash string
	UUID         string
	URL          string
}

User data model

func FindOneUser

func FindOneUser(condition interface{}) (User, error)

FindOneUser finds a single topic with the given condition

func (*User) CheckPassword

func (u *User) CheckPassword(password string) error

CheckPassword checks if user's password is the given password

func (*User) Delete

func (user *User) Delete()

func (*User) IsFollowing

func (u *User) IsFollowing(following User) bool

IsFollowing checks for a follow model between 2 users

func (*User) IsFollowingTopic

func (u *User) IsFollowingTopic(topic Topic) bool

IsFollowingTopic checks if a user is following a certain topic

func (*User) Read

func (u *User) Read(m common.JSON)

func (*User) Save

func (user *User) Save()

func (*User) Serialize

func (u *User) Serialize() common.JSON

Serialize user data

func (*User) SetPassword

func (u *User) SetPassword(newPassword string) error

SetPassword sets a new hashed password to the user

func (*User) UnFollow

func (u *User) UnFollow(unFollowUser User) error

UnFollow removes a follow model between 2 users

func (*User) UnFollowTopic

func (u *User) UnFollowTopic(topic Topic) error

UnFollowTopic removes a user's following of a topic

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL