github.com/seeker-insurance/kit@v0.0.13/brewerydb/endpoints/request/location.go (about)

     1  package request
     2  
     3  import "time"
     4  import "github.com/seeker-insurance/kit/brewerydb/structs"
     5  
     6  const (
     7  	errMustSetLocation BadRequestError = "must set one of the following attributes: locality, postalCode, region"
     8  	errBadPage         BadRequestError = "page must be and int >=0"
     9  )
    10  
    11  type Location struct {
    12  	structs.Address
    13  
    14  	Page int      `json:"p,omitempty"`
    15  	IDs  []string `json:"ids,omitempty"`
    16  
    17  	IsPrimary      bool                   `json:"isPrimary,omitempty"`
    18  	InPlanning     bool                   `json:"inPlanning,omitempty"`
    19  	IsClosed       bool                   `json:"isClosed,omitempty"`
    20  	LocationType   []structs.LocationType `json:"locationType,omitempty"`
    21  	CountryIsoCode string                 `json:"countryIsoCode,omitempty"`
    22  	Since          time.Time              `json:"since,omitempty"`
    23  	Status         string                 `json:"status,omitempty"`
    24  }
    25  
    26  func (loc Location) Valid() error {
    27  	if loc.Locality == "" && loc.Region == "" && loc.PostalCode == "" {
    28  		return errMustSetLocation
    29  	} else if loc.Page < 0 {
    30  		return errBadPage
    31  	}
    32  	return nil
    33  }
    34  
    35  type BadRequestError string
    36  
    37  func (err BadRequestError) Error() string { return string(err) }