models

package
v0.0.0-...-747cc42 Latest Latest
Warning

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

Go to latest
Published: Sep 3, 2022 License: MIT Imports: 2 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Answer

type Answer struct {
	gorm.Model
	Text       string
	QuestionID uint `gorm:"type:int REFERENCES questions(id)"`
	Question   Question
	UserID     uint `gorm:"type:int REFERENCES users(id)"`
	User       User
}

Answer by me

type Question

type Question struct {
	gorm.Model
	ToUser     User
	ToUserID   uint `gorm:"type:int REFERENCES users(id)"`
	Text       string
	AnswerID   *uint `gorm:"default: null"`
	FromUser   User
	FromUserID uint `gorm:"type:int REFERENCES users(id)"`
}

Question asked by users

type User

type User struct {
	gorm.Model
	Email             string `gorm:"type:varchar(100);unique_index"`
	Name              string
	HashedPassword    []byte
	Answers           []Answer
	QuestionsReceived []Question `gorm:"FOREIGNKEY:ToUserID"`
	QuestionsSent     []Question `gorm:"FOREIGNKEY:FromUserID"`
}

User type

func NewUser

func NewUser(email string, name string, password string) (*User, error)

NewUser creates a new user

func (*User) Answer

func (user *User) Answer(q *Question, answer string) *Answer

Answer the specified question

func (*User) Ask

func (user *User) Ask(other *User, question string) *Question

Ask creates a new question that is asked from user to user askee

func (*User) Verify

func (user *User) Verify(password string) bool

Verify user password

Jump to

Keyboard shortcuts

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