models

package
v0.0.0-...-b23e817 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2023 License: Apache-2.0 Imports: 8 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Author

type Author struct {
	ID       uuid.UUID `json:"id"`
	Username string    `json:"username"`
}

type Comment

type Comment struct {
	ID        uuid.UUID `json:"id"`
	UserID    uuid.UUID `json:"user_id" gorm:"size:191"`
	RecipeID  uuid.UUID `json:"recipe_id" gorm:"size:191"`
	Content   string    `json:"content"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	User      User      `json:"commenter"`
}

func (*Comment) BeforeCreate

func (c *Comment) BeforeCreate(tx *gorm.DB) error

func (*Comment) MapResponse

func (c *Comment) MapResponse() CommentResponse

type CommentResponse

type CommentResponse struct {
	ID        uuid.UUID `json:"id"`
	Content   string    `json:"content"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
	User      Author    `json:"commenter"`
}

type Recipe

type Recipe struct {
	ID           uuid.UUID `json:"id"`
	UserID       uuid.UUID `json:"user_id" gorm:"size:191"`
	Title        string    `json:"title"`
	Portion      int       `json:"portion"`
	CookingTime  int       `json:"cooking_time"`
	Description  string    `json:"description"`
	Ingredients  string    `json:"ingredients"`
	Instructions string    `json:"instructions"`
	Tags         string    `json:"tags"`
	CreatedAt    time.Time `json:"created_at"`
	UpdatedAt    time.Time `json:"updated_at"`
	User         User      `json:"author"`
}

func (*Recipe) BeforeCreate

func (r *Recipe) BeforeCreate(tx *gorm.DB) error

func (*Recipe) MapResponse

func (r *Recipe) MapResponse() RecipeResponse

type RecipeResponse

type RecipeResponse struct {
	ID           uuid.UUID         `json:"id"`
	Title        string            `json:"title"`
	Portion      int               `json:"portion"`
	CookingTime  int               `json:"cooking_time"`
	Description  string            `json:"description,omitempty"`
	Ingredients  string            `json:"ingredients,omitempty"`
	Instructions string            `json:"instructions"`
	Tags         string            `json:"tags"`
	CreatedAt    time.Time         `json:"created_at"`
	UpdatedAt    time.Time         `json:"updated_at"`
	User         Author            `json:"author"`
	Comments     []CommentResponse `json:"comments"`
}

type Response

type Response struct {
	Code    int         `json:"code"`
	Message string      `json:"message"`
	Errors  []string    `json:"errors"`
	Data    interface{} `json:"data"`
}

func StatusBadGateway

func StatusBadGateway(errors []string) Response

func StatusBadRequest

func StatusBadRequest(errors []string) Response

func StatusCreated

func StatusCreated(data interface{}) Response

func StatusOk

func StatusOk(data interface{}) Response

func StatusUnauthorized

func StatusUnauthorized(errors []string) Response

type User

type User struct {
	ID        uuid.UUID `json:"id"`
	Username  string    `json:"username"`
	Email     string    `json:"email"`
	Password  string    `json:"password,omitempty"`
	CreatedAt time.Time `json:"created_at"`
	UpdatedAt time.Time `json:"updated_at"`
}

func (*User) BeforeCreate

func (u *User) BeforeCreate(tx *gorm.DB) error

GORM HOOKS CREATE USER ID AND HASH PASSWORD

func (*User) ComparePassword

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

func (*User) GenerateToken

func (u *User) GenerateToken() (string, error)

func (*User) HashPassword

func (u *User) HashPassword() error

func (*User) Sanitize

func (u *User) Sanitize()

type UserWithToken

type UserWithToken struct {
	User
	Token string `json:"token"`
}

Jump to

Keyboard shortcuts

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