country

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2024 License: MIT Imports: 12 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrCountryNotFound    = server.NewHTTPError(http.StatusBadRequest, "COUNTRY_NOTFOUND", "Country not found")
	ErrCountryNameExisted = server.NewHTTPValidationError("Country name already exists")
)

Custom errors

Functions

func NewDB

func NewDB() *dbutil.DB

NewDB returns a new country database instance

func NewHTTP

func NewHTTP(svc Service, auth model.Auth, eg *echo.Group)

NewHTTP creates new country http service

Types

type Country

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

Country represents country application service

func New

func New(db *gorm.DB, cdb dbutil.Intf, rbacSvc rbac.Intf) *Country

New creates new country application service

func (*Country) Create

func (s *Country) Create(ctx context.Context, authUsr *model.AuthUser, data CreationData) (*model.Country, error)

Create creates a new country

func (*Country) Delete

func (s *Country) Delete(ctx context.Context, authUsr *model.AuthUser, id int) error

Delete deletes a country

func (*Country) List

func (s *Country) List(ctx context.Context, authUsr *model.AuthUser, lq *dbutil.ListQueryCondition, count *int64) ([]*model.Country, error)

List returns list of countrys

func (*Country) Update

func (s *Country) Update(ctx context.Context, authUsr *model.AuthUser, id int, data UpdateData) (*model.Country, error)

Update updates country information

func (*Country) View

func (s *Country) View(ctx context.Context, authUsr *model.AuthUser, id int) (*model.Country, error)

View returns single country

type CreationData

type CreationData struct {
	// example: Vietnam
	Name string `json:"name" validate:"required,min=3"`
	// example: vn
	Code string `json:"code" validate:"required,min=2,max=10"`
	// example: +84
	PhoneCode string `json:"phone_code" validate:"required,min=2,max=10"`
}

CreationData contains country data from json request

type HTTP

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

HTTP represents country http service

type ListResp

type ListResp struct {
	// example: [{"id": 1, "created_at": "2020-01-14T10:03:41Z", "updated_at": "2020-01-14T10:03:41Z", "name": "Singapore", "code": "SG", "phone_code": "+65"}]
	Data []*model.Country `json:"data"`
	// example: 1
	TotalCount int64 `json:"total_count"`
}

ListResp contains list of paginated countries and total numbers of countries

type Service

Service represents country application interface

type UpdateData

type UpdateData struct {
	// example: Vietnam
	Name *string `json:"name,omitempty" validate:"omitempty,min=3"`
	// example: vn
	Code *string `json:"code,omitempty" validate:"omitempty,min=2,max=10"`
	// example: +84
	PhoneCode *string `json:"phone_code,omitempty" validate:"omitempty,min=2,max=10"`
}

UpdateData contains country data from json request

Jump to

Keyboard shortcuts

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