models

package
v0.0.0-...-d92368f Latest Latest
Warning

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

Go to latest
Published: May 3, 2023 License: MIT Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDB

func GetDB(connStr string) (*gorm.DB, error)

func GetSecret

func GetSecret() []byte

func InitDB

func InitDB(db *gorm.DB)

Types

type Answer

type Answer struct {
	gorm.Model
	Body       string     `gorm:"type:text;not null" json:"body"`
	Likes      Likes      `gorm:"foreignkey:LikesID" json:"likes"`
	LikesID    int        `json:"-"`
	Comments   []*Comment `gorm:"many2many:answer_comments" json:"comments"`
	Author     *User      `gorm:"foreignkey:AuthorID" json:"author"`
	AuthorID   int        `json:"-"`
	Question   *Question  `gorm:"foreignkey:QuestionID" json:"question"`
	QuestionID int        `json:"-"`
}

type AnswerInfo

type AnswerInfo struct {
	Body       string `json:"body"`
	QuestionID int    `json:"question_id"`
}

type Comment

type Comment struct {
	gorm.Model
	Body     string     `gorm:"type:text;not null" json:"body"`
	Likes    Likes      `gorm:"foreignkey:LikesID" json:"likes"`
	LikesID  int        `json:"-"`
	Replies  []*Comment `gorm:"many2many:comment_replies" json:"replies"`
	Author   *User      `gorm:"foreignkey:AuthorID" json:"author"`
	AuthorID int        `json:"author_id"`
}

type Likes

type Likes struct {
	gorm.Model
	Amount int `gorm:"type:int;not null;default:0" json:"amount"`
}

type Question

type Question struct {
	gorm.Model
	Title    string     `gorm:"type:varchar(255);not null" json:"title" binding:"required"`
	Body     string     `gorm:"type:text;not null" json:"body" binding:"required"`
	Likes    Likes      `gorm:"foreignkey:LikesID" json:"likes"`
	LikesID  int        `json:"-"`
	Answers  []*Answer  `gorm:"many2many:question_answers" json:"answers"`
	Comments []*Comment `gorm:"many2many:question_comments" json:"comments"`
	Author   *User      `gorm:"foreignkey:AuthorID" json:"author"`
	AuthorID int        `json:"-"`
}

type QuestionsQuery

type QuestionsQuery struct {
	SortType   string `json:"sortType"`
	Page       int    `json:"page"`
	NumPerPage int    `json:"numPerPage"`
}

type User

type User struct {
	gorm.Model
	Username  string      `gorm:"type:varchar(255);not null;unique" json:"username"`
	Email     string      `gorm:"type:varchar(255);not null;unique" json:"-"`
	Password  string      `gorm:"type:varchar(255);not null" json:"-"`
	Questions []*Question `gorm:"many2many:user_questions" json:"questions"`
}

type UserInfo

type UserInfo struct {
	Username string `json:"username"`
	Email    string `json:"email"`
	Password string `json:"password"`
}

Jump to

Keyboard shortcuts

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