cat

package
v0.0.0-...-b329bd3 Latest Latest
Warning

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

Go to latest
Published: May 5, 2024 License: MIT Imports: 20 Imported by: 0

Documentation

Index

Constants

View Source
const (
	Persian          CatRace = "Persian"
	MaineCoon        CatRace = "Maine Coon"
	Siamese          CatRace = "Siamese"
	Ragdoll          CatRace = "Ragdoll"
	Bengal           CatRace = "Bengal"
	Sphynx           CatRace = "Sphynx"
	BritishShorthair CatRace = "British Shorthair"
	Abyssinian       CatRace = "Abyssinian"
	ScottishFold     CatRace = "Scottish Fold"
	Birman           CatRace = "Birman"

	Male   CatSex = "male"
	Female CatSex = "female"
)

Variables

View Source
var (
	CatRacesInterface []interface{} = []interface{}{Persian, MaineCoon, Siamese, Ragdoll, Bengal, Sphynx, BritishShorthair, Abyssinian, ScottishFold, Birman}
	CatSexesInterface []interface{} = []interface{}{Male, Female}

	CatRaces []CatRace = []CatRace{Persian, MaineCoon, Siamese, Ragdoll, Bengal, Sphynx, BritishShorthair, Abyssinian, ScottishFold, Birman}
	CatSexes []CatSex  = []CatSex{Male, Female}
)
View Source
var (
	ErrCatNotFound      = errors.New("cat not found")
	ErrCatHasMatched    = errors.New("cat has matched befor")
	ErrValidationFailed = errors.New("validation failed")
)
View Source
var (
	AgeRegex = regexp.MustCompile("[<>]*\\d+")
)

Functions

This section is empty.

Types

type AgeSearchType

type AgeSearchType int
const (
	MoreThan AgeSearchType = iota
	LessThan
	EqualTo
	IgnoreAge
)

type Cat

type Cat struct {
	ID          int64
	UID         string
	UserID      int64
	Name        string
	Race        CatRace
	Sex         CatSex
	Age         int
	Description string
	HasMatched  bool
	ImageURLS   []string
	CreatedAt   time.Time
}

type CatRace

type CatRace string

type CatResponse

type CatResponse struct {
	ID          string    `json:"id"`
	Name        string    `json:"name"`
	Race        string    `json:"race"`
	Sex         string    `json:"sex"`
	AgeInMonth  int       `json:"ageInMonth"`
	ImageUrls   []string  `json:"imageUrls"`
	Description string    `json:"description"`
	HasMatched  bool      `json:"hasMatched"`
	CreatedAt   time.Time `json:"createdAt"`
}

type CatSex

type CatSex string

type CreateCatResponse

type CreateCatResponse struct {
	Id        string    `json:"id"`
	CreatedAt time.Time `json:"createdAt"`
}

type CreateUpdateCatPayload

type CreateUpdateCatPayload struct {
	Name        string   `json:"name"`
	Race        CatRace  `json:"race"`
	Sex         CatSex   `json:"sex"`
	AgeInMonth  int      `json:"ageInMonth"`
	Description string   `json:"description"`
	ImageURLS   []string `json:"imageUrls"`
}

func (CreateUpdateCatPayload) Validate

func (p CreateUpdateCatPayload) Validate() error

type Handler

type Handler struct {
	// contains filtered or unexported fields
}

func NewHandler

func NewHandler(service Service) *Handler

func (*Handler) CreateCat

func (h *Handler) CreateCat(w http.ResponseWriter, r *http.Request)

func (*Handler) DeleteCat

func (h *Handler) DeleteCat(w http.ResponseWriter, r *http.Request)

func (*Handler) GetCatList

func (h *Handler) GetCatList(w http.ResponseWriter, r *http.Request)

func (*Handler) UpdateCat

func (h *Handler) UpdateCat(w http.ResponseWriter, r *http.Request)

type HasMatchedSearchType

type HasMatchedSearchType int
const (
	HasMatched HasMatchedSearchType = iota
	HasNotMatched
	IgnoreHasMatched
)

type ListCatPayload

type ListCatPayload struct {
	ID         string `schema:"id" binding:"omitempty"`
	Limit      int    `schema:"limit" binding:"omitempty"`
	Offset     int    `schema:"offset" binding:"omitempty"`
	Race       string `schema:"race" binding:"omitempty"`
	Sex        string `schema:"sex" binding:"omitempty"`
	HasMatched string `schema:"hasMatched" binding:"omitempty"`
	AgeInMonth string `schema:"ageInMonth" binding:"omitempty"`
	Owned      bool   `schema:"owned" binding:"omitempty"`
	Search     string `schema:"search" binding:"omitempty"`

	Age            int
	AgeSearchType  AgeSearchType
	HasMatchedType HasMatchedSearchType
}

type OwnedSearchType

type OwnedSearchType int
const (
	Owned OwnedSearchType = iota
	NotOwned
)

type Repository

type Repository interface {
	List(ctx context.Context, req ListCatPayload, userID int64) ([]*Cat, error)
	GetByUIDAndUserID(ctx context.Context, id string, userID int64) (*Cat, error)
	GetByIDAndUserID(ctx context.Context, id int64, userID int64) (*Cat, error)
	GetByUID(ctx context.Context, uid string) (*Cat, error)
	Create(ctx context.Context, cat *Cat) (*Cat, error)
	Update(ctx context.Context, cat *Cat) error
	Delete(ctx context.Context, id string, userID int64) error
}

func NewRepository

func NewRepository(db *db.DB) Repository

type Service

type Service interface {
	List(ctx context.Context, req ListCatPayload, userID int64) ([]CatResponse, error)
	Create(ctx context.Context, req CreateUpdateCatPayload, userID int64) (*CreateCatResponse, error)
	Update(ctx context.Context, req CreateUpdateCatPayload, id string, userID int64) error
	Delete(ctx context.Context, id string, userID int64) error
}

func NewService

func NewService(repository Repository) Service

Jump to

Keyboard shortcuts

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