conduit

package
v0.0.0-...-78b87b3 Latest Latest
Warning

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

Go to latest
Published: Aug 9, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrDuplicateEmail    = errors.New("duplicate email")
	ErrDuplicateUsername = errors.New("duplicate username")
	ErrNotFound          = errors.New("record not found")
	ErrUnAuthorized      = errors.New("unauthorized")
	ErrInternal          = errors.New("internal error")
)

Functions

This section is empty.

Types

type Article

type Article struct {
	ID             uint      `json:"-"`
	Title          string    `json:"title"`
	Body           string    `json:"body"`
	Description    string    `json:"description"`
	Favorited      bool      `json:"favorited"`
	FavoritesCount int64     `json:"favoritesCount" db:"favorites_count"`
	FavoritedBy    []*User   `json:"-"`
	Slug           string    `json:"slug"`
	AuthorID       uint      `json:"-" db:"author_id"`
	Author         *User     `json:"-"`
	AuthorProfile  *Profile  `json:"author"`
	Tags           []*Tag    `json:"tagList"`
	CreatedAt      time.Time `json:"createdAt" db:"created_at"`
	UpdatedAt      time.Time `json:"updatedAt" db:"updated_at"`
}

func (*Article) AddTags

func (a *Article) AddTags(_tags ...string)

func (*Article) SetAuthorProfile

func (a *Article) SetAuthorProfile(currentUser *User)

func (*Article) UserHasFavorite

func (a *Article) UserHasFavorite(currentUser *User) bool

type ArticleFilter

type ArticleFilter struct {
	ID             *uint
	Title          *string
	Description    *string
	AuthorID       *uint
	AuthorUsername *string
	Tag            *string
	Slug           *string
	FavoritedBy    *string

	Limit  int
	Offset int
}

type ArticlePatch

type ArticlePatch struct {
	Title       *string
	Body        *string
	Description *string
	Slug        *string
	Tags        []Tag
}

type ArticleService

type ArticleService interface {
	CreateArticle(context.Context, *Article) error
	ArticleBySlug(context.Context, string) (*Article, error)
	Articles(context.Context, ArticleFilter) ([]*Article, error)
	ArticleFeed(context.Context, *User, ArticleFilter) ([]*Article, error)
	FavoriteArticle(ctx context.Context, userID uint, article *Article) error
	UnfavoriteArticle(ctx context.Context, userID uint, article *Article) error
	UpdateArticle(context.Context, *Article, ArticlePatch) error
	DeleteArticle(context.Context, uint) error
}

type Comment

type Comment struct {
	ID            uint      `json:"id"`
	ArticleID     uint      `json:"-" db:"article_id"`
	Article       *Article  `json:"-"`
	AuthorID      uint      `json:"-" db:"author_id"`
	Author        *User     `json:"-"`
	AuthorProfile *Profile  `json:"author"`
	Body          string    `json:"body"`
	CreatedAt     time.Time `json:"createdAt" db:"created_at"`
}

func (*Comment) SetAuthorProfile

func (c *Comment) SetAuthorProfile(currentUser *User)

type CommentFilter

type CommentFilter struct {
	ID        *uint
	ArticleID *uint
	AuthorID  *uint

	Limit  int
	Offset int
}

type CommentService

type CommentService interface {
	CreateComment(context.Context, *Comment) error
	CommentByID(context.Context, uint) (*Comment, error)
	Comments(context.Context, CommentFilter) ([]*Comment, error)
	DeleteComment(context.Context, uint) error
}

type Following

type Following struct {
	ID          uint  `json:"id"`
	FollowingID uint  `json:"following_id" db:"following_id"`
	Following   *User `json:"following"`
	FollowerID  uint  `json:"follower_id" db:"follower_id"`
	Follower    *User `json:"follower"`
}

type Profile

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

type Tag

type Tag struct {
	ID   uint
	Name string
}

func (Tag) MarshalJSON

func (t Tag) MarshalJSON() ([]byte, error)

type TagFilter

type TagFilter struct {
	Name *string

	Limit  int
	Offset int
}

type TagService

type TagService interface {
	Tags(context.Context, TagFilter) ([]*Tag, error)
}

type User

type User struct {
	ID           uint      `json:"-"`
	Email        string    `json:"email,omitempty"`
	Username     string    `json:"username,omitempty"`
	Bio          string    `json:"bio,omitempty"`
	Image        string    `json:"image,omitempty"`
	Token        string    `json:"token,omitempty"`
	Following    []*User   `json:"-"`
	Followers    []*User   `json:"-"`
	PasswordHash string    `json:"-" db:"password_hash"`
	CreatedAt    time.Time `json:"-" db:"created_at"`
	UpdatedAt    time.Time `json:"-" db:"updated_at"`
}
var AnonymousUser User

func (*User) IsAnonymous

func (u *User) IsAnonymous() bool

func (*User) IsFollowing

func (me *User) IsFollowing(user *User) bool

func (*User) Profile

func (u *User) Profile() *Profile

func (*User) ProfileWithFollow

func (u *User) ProfileWithFollow(_u *User) *Profile

func (*User) SetPassword

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

func (User) VerifyPassword

func (u User) VerifyPassword(password string) bool

type UserFilter

type UserFilter struct {
	ID       *uint
	Email    *string
	Username *string

	Limit  int
	Offset int
}

type UserPatch

type UserPatch struct {
	Email        *string `json:"email"`
	Username     *string `json:"username"`
	Image        *string `json:"image"`
	Bio          *string `json:"bio"`
	PasswordHash *string `json:"-" db:"password_hash"`
}

type UserService

type UserService interface {
	Authenticate(ctx context.Context, email, password string) (*User, error)

	CreateUser(context.Context, *User) error

	UserByID(context.Context, uint) (*User, error)

	UserByEmail(context.Context, string) (*User, error)

	UserByUsername(context.Context, string) (*User, error)

	Users(context.Context, UserFilter) ([]*User, error)

	UpdateUser(context.Context, *User, UserPatch) error

	// FollowUser creates a following relationship as follower follows user
	FollowUser(ctx context.Context, user, follower *User) error

	// UnFollowUser removes the following relationship as follower unfollows user
	UnFollowUser(ctx context.Context, user, follower *User) error

	DeleteUser(context.Context, uint) error
}

Jump to

Keyboard shortcuts

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