model

package
v0.0.0-...-cbbd1a2 Latest Latest
Warning

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

Go to latest
Published: Oct 5, 2022 License: Apache-2.0 Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Article

type Article struct {
	Id       uint
	AuthorId uint
	//Author         *User ` db:"-"`
	Title          string
	Slug           string
	Description    string
	Body           *string
	FavoritesCount int
	//FavoritedBy    []*User
	TagList []string ` db:"-"`
	//Comments  []Comment ` db:"-"`
	CreatedAt time.Time
	UpdatedAt time.Time
}

func Article_Create

func Article_Create(
	author User,
	title string,
	description string,
	body *string,
	tagList []string,
) Article

func (Article) Update

func (s Article) Update(src ArticlePatch) Article

Update returns an updated copy of the receiver. It does not change the slug when the title changes.

func (Article) WithAdjustedFavoriteCount

func (s Article) WithAdjustedFavoriteCount(delta int) Article

type ArticlePatch

type ArticlePatch struct {
	Title       *string
	Description *string
	Body        *string
	TagList     *[]string
}

type ArticlePlus

type ArticlePlus struct {
	Id             uint      `json:"-"`
	Slug           string    `json:"slug"`
	Author         Profile   `json:"author"`
	Title          string    `json:"title"`
	Description    string    `json:"description"`
	Body           *string   `json:"body"`
	TagList        []string  `json:"tagList"`
	CreatedAt      time.Time `json:"createdAt"`
	UpdatedAt      time.Time `json:"updatedAt"`
	Favorited      bool      `json:"favorited"`
	FavoritesCount int       `json:"favoritesCount"`
}

func ArticlePlus_FromArticle

func ArticlePlus_FromArticle(article Article, favorited bool, author Profile) ArticlePlus

func (ArticlePlus) ToArticle

func (s ArticlePlus) ToArticle() Article

type Comment

type Comment struct {
	Id        uint
	ArticleId uint
	AuthorId  uint
	Body      *string
	CreatedAt time.Time
	UpdatedAt time.Time
}

func Comment_Create

func Comment_Create(
	articleId uint,
	authorId uint,
	body *string,
) Comment

type Favorite

type Favorite struct {
	// UserId is the ID of the user that favors the article.
	UserId    uint
	ArticleId uint
}

type Following

type Following struct {
	FollowerId uint
	FolloweeId uint
	FollowedOn time.Time
}

type Profile

type Profile struct {
	UserId    uint    `json:"-"`
	Username  string  `json:"username"`
	Bio       *string `json:"bio"`
	Image     string  `json:"image"`
	Following bool    `json:"following"`
}

func Profile_FromUser

func Profile_FromUser(user User, follows bool) Profile

type Tag

type Tag struct {
	Id   uint
	Name string
}

type User

type User struct {
	Id           uint
	Username     string
	Email        string
	PasswordHash string
	PasswordSalt string // TODO: remove this field from code and databse
	Bio          *string
	ImageLink    string    `db:"image"`
	CreatedAt    time.Time `json:"-"`
	UpdatedAt    time.Time `json:"-"`
}

User represents a user account in the system

func User_Create

func User_Create(
	username string,
	email string,
	password string,
) User

func (User) Update

func (s User) Update(v UserPatch) User

type UserPatch

type UserPatch struct {
	Username  *string
	Email     *string
	Password  *string
	Bio       *string
	ImageLink *string
}

Jump to

Keyboard shortcuts

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