http

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Jul 14, 2024 License: GPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func ErrorMiddleware

func ErrorMiddleware(logger *zap.Logger) fiber.Handler

func RespondWithError

func RespondWithError(ctx *fiber.Ctx, err error) error

Types

type AddTargetNotesRequest

type AddTargetNotesRequest struct {
	Notes []string `json:"notes"`
}

func (AddTargetNotesRequest) Validate

func (r AddTargetNotesRequest) Validate() error

type AddTargetRequest

type AddTargetRequest struct {
	Name    string `json:"name"`
	Country string `json:"country"`
}

func (AddTargetRequest) Validate

func (r AddTargetRequest) Validate() error

type AddTargetsRequest

type AddTargetsRequest struct {
	Targets []AddTargetRequest `json:"targets"`
}

func (AddTargetsRequest) Params

func (AddTargetsRequest) Validate

func (r AddTargetsRequest) Validate() error

type BaseResponse

type BaseResponse struct {
	Ok bool `json:"ok"`
}

type Cat

type Cat struct {
	ID              int       `json:"id"`
	Name            string    `json:"name"`
	ExperienceYears int16     `json:"experience_years"`
	Breed           string    `json:"breed"`
	Salary          int       `json:"salary"`
	CreatedAt       time.Time `json:"created_at"`
	UpdatedAt       time.Time `json:"updated_at"`
}

func CatFromModel

func CatFromModel(cat *models.Cat) Cat

type CreateCatRequest

type CreateCatRequest struct {
	Name       string `json:"name"`
	Breed      string `json:"breed"`
	Experience int    `json:"experience"`
	Salary     int    `json:"salary"`
}

func (CreateCatRequest) Validate

func (r CreateCatRequest) Validate() error

type CreateCatResponse

type CreateCatResponse struct {
	BaseResponse
	ID int `json:"id"`
}

type CreateMissionRequest

type CreateMissionRequest struct {
	Targets []AddTargetRequest `json:"targets"`
}

func (CreateMissionRequest) Params

func (CreateMissionRequest) Validate

func (r CreateMissionRequest) Validate() error

type CreateMissionResponse

type CreateMissionResponse struct {
	BaseResponse
	ID int `json:"id"`
}

type Error

type Error struct {
	Ok       bool           `json:"ok"`
	Code     codes.Code     `json:"code"`
	Message  string         `json:"message"`
	Metadata map[string]any `json:"metadata,omitempty"`
}

type GetCatResponse

type GetCatResponse struct {
	BaseResponse
	Cat Cat `json:"cat"`
}

type GetCatsResponse

type GetCatsResponse struct {
	BaseResponse
	Cats []Cat `json:"cats"`
}

type GetMissionResponse

type GetMissionResponse struct {
	BaseResponse
	Mission MissionFull `json:"mission"`
}

type GetMissionTargetsResponse

type GetMissionTargetsResponse struct {
	BaseResponse
	Targets []TargetFull `json:"targets"`
}

type GetMissionsRequest

type GetMissionsRequest struct {
	CatID *int `query:"cat_id"`
}

type GetMissionsResponse

type GetMissionsResponse struct {
	BaseResponse
	Missions []Mission `json:"missions"`
}

type GetTargetResponse

type GetTargetResponse struct {
	BaseResponse
	Target TargetFull `json:"target"`
}

type Handler

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

func (Handler) AddMissionTargets

func (h Handler) AddMissionTargets(ctx *fiber.Ctx) error

func (Handler) AddTargetNote

func (h Handler) AddTargetNote(ctx *fiber.Ctx) error

func (Handler) CompleteMissionByID

func (h Handler) CompleteMissionByID(ctx *fiber.Ctx) error

func (Handler) CompleteTargetByID

func (h Handler) CompleteTargetByID(ctx *fiber.Ctx) error

func (Handler) CreateCat

func (h Handler) CreateCat(ctx *fiber.Ctx) error

func (Handler) CreateMission

func (h Handler) CreateMission(ctx *fiber.Ctx) error

func (Handler) DeleteCatByID

func (h Handler) DeleteCatByID(ctx *fiber.Ctx) error

func (Handler) DeleteMissionByID

func (h Handler) DeleteMissionByID(ctx *fiber.Ctx) error

func (Handler) DeleteTargetByID

func (h Handler) DeleteTargetByID(ctx *fiber.Ctx) error

func (Handler) GetCatByID

func (h Handler) GetCatByID(ctx *fiber.Ctx) error

func (Handler) GetCats

func (h Handler) GetCats(ctx *fiber.Ctx) error

func (Handler) GetMissionByID

func (h Handler) GetMissionByID(ctx *fiber.Ctx) error

func (Handler) GetMissionTargets

func (h Handler) GetMissionTargets(ctx *fiber.Ctx) error

func (Handler) GetMissions

func (h Handler) GetMissions(ctx *fiber.Ctx) error

func (Handler) GetTargetByID

func (h Handler) GetTargetByID(ctx *fiber.Ctx) error

func (Handler) UpdateCatByID

func (h Handler) UpdateCatByID(ctx *fiber.Ctx) error

func (Handler) UpdateMissionByID

func (h Handler) UpdateMissionByID(ctx *fiber.Ctx) error

type Mission

type Mission struct {
	ID            int       `json:"id"`
	AssignedCatID *int      `json:"assigned_cat_id"`
	IsCompleted   bool      `json:"is_completed"`
	CreatedAt     time.Time `json:"created_at"`
	UpdatedAt     time.Time `json:"updated_at"`
}

func MissionFromModel

func MissionFromModel(mission *models.Mission) Mission

type MissionFull

type MissionFull struct {
	Mission
	Targets []Target `json:"targets"`
}

func MissionFullFromModel

func MissionFullFromModel(missionFull *models.MissionFull) MissionFull

type Note

type Note struct {
	ID        int       `json:"-"`
	TargetID  int       `json:"-"`
	Content   string    `json:"content"`
	CreatedAt time.Time `json:"created_at"`
}

func NoteFromModel

func NoteFromModel(note *models.Note) Note

type Server

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

func NewServer

func NewServer(cfg *config.Config, logger *zap.Logger, service Service) *Server

func (*Server) Shutdown

func (s *Server) Shutdown() error

func (*Server) Start

func (s *Server) Start() error

type Service

type Service interface {
	AddCat(ctx context.Context, params dto.CreateCatParams) (catID int, err error)
	GetCats(ctx context.Context) ([]*models.Cat, error)
	GetCatByID(ctx context.Context, catID int) (*models.Cat, error)
	UpdateCatByID(ctx context.Context, params dto.UpdateCatParams) error
	DeleteCatByID(ctx context.Context, catID int) error
	GetMissions(ctx context.Context, params dto.GetMissionsParams) ([]*models.Mission, error)
	CreateMission(ctx context.Context, params dto.CreateMissionParams) (missionID int, err error)
	AddMissionTargets(ctx context.Context, missionID int, newTargets []dto.CreateTargetParams) (err error)
	GetMissionByID(ctx context.Context, missionID int) (out *models.MissionFull, err error)
	UpdateMissionByID(ctx context.Context, params dto.UpdateMissionParams) (err error)
	DeleteMissionByID(ctx context.Context, missionID int) (err error)
	GetTargetsByMissionID(ctx context.Context, missionID int) (out []*models.TargetFull, err error)
	GetTargetByID(ctx context.Context, missionID int, targetID int) (out *models.TargetFull, err error)
	CompleteTargetByID(ctx context.Context, missionID int, targetID int) (err error)
	DeleteTargetByID(ctx context.Context, missionID int, targetID int) (err error)
	AddTargetNote(ctx context.Context, missionID int, targetID int, contents []string) (err error)
}

type Target

type Target struct {
	ID          int       `json:"id"`
	MissionID   int       `json:"mission_id"`
	IsCompleted bool      `json:"is_completed"`
	Name        string    `json:"name"`
	Country     string    `json:"country"`
	CreatedAt   time.Time `json:"created_at"`
	UpdatedAt   time.Time `json:"updated_at"`
}

Targets

func TargetFromModel

func TargetFromModel(target *models.Target) Target

type TargetFull

type TargetFull struct {
	Target
	Notes []Note `json:"notes"`
}

func TargetFullFromModel

func TargetFullFromModel(targetFull *models.TargetFull) TargetFull

type UpdateCatRequest

type UpdateCatRequest struct {
	CatID           int     `json:"-"`
	Name            *string `json:"name"`
	ExperienceYears *int    `json:"experience"`
	Salary          *int    `json:"salary"`
}

func (UpdateCatRequest) Validate

func (r UpdateCatRequest) Validate() error

type UpdateMissionRequest

type UpdateMissionRequest struct {
	AssignedCatID *int `json:"assigned_cat_id"`
}

func (UpdateMissionRequest) Validate

func (r UpdateMissionRequest) Validate() error

Jump to

Keyboard shortcuts

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