owner

package
v0.0.0-...-6d561a7 Latest Latest
Warning

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

Go to latest
Published: Aug 5, 2026 License: Apache-2.0 Imports: 14 Imported by: 0

Documentation

Overview

Package owner owns Petclinic owners, pets, visits, and pet types.

Index

Constants

This section is empty.

Variables

View Source
var ErrOwnerNotFound = errors.New("owner not found")

ErrOwnerNotFound reports a missing owner identity.

View Source
var ErrPetNotFound = errors.New("pet not found")

ErrPetNotFound reports a pet identity outside its requested owner.

Functions

This section is empty.

Types

type Controller

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

Controller serves the Petclinic owner workflows.

@Controller

func NewController

func NewController(
	owners Repository,
	messages *i18n.Catalog,
) (*Controller, error)

NewController constructs the owner HTTP boundary.

func (*Controller) Create

func (controller *Controller) Create(
	ctx context.Context,
	request OwnerFormRequest,
	binding web.BindingResult,
) (view.Result, error)

Create validates and persists a new owner.

@Post("/owners/new")

func (*Controller) EditForm

func (controller *Controller) EditForm(
	ctx context.Context,
	request OwnerIDRequest,
) (view.Result, error)

EditForm renders one persisted owner for editing.

@Get("/owners/{ownerId}/edit")

func (*Controller) Find

func (controller *Controller) Find(
	ctx context.Context,
	request FindOwnersRequest,
) (view.Result, error)

Find searches owners by last-name prefix with Petclinic pagination.

@Get("/owners")

func (*Controller) FindForm

func (controller *Controller) FindForm(
	_ context.Context,
	request FindOwnerFormRequest,
) (view.Result, error)

FindForm renders the owner search form.

@Get("/owners/find")

func (*Controller) NewForm

func (controller *Controller) NewForm(
	_ context.Context,
	request NewOwnerRequest,
) (view.Result, error)

NewForm renders an empty owner form.

@Get("/owners/new")

func (*Controller) Show

func (controller *Controller) Show(
	ctx context.Context,
	request OwnerIDRequest,
) (view.Result, error)

Show renders one owner aggregate.

@Get("/owners/{ownerId}")

func (*Controller) Update

func (controller *Controller) Update(
	ctx context.Context,
	request EditOwnerRequest,
	binding web.BindingResult,
) (view.Result, error)

Update validates and persists owner field changes without replacing pets.

@Post("/owners/{ownerId}/edit")

type EditOwnerRequest

type EditOwnerRequest struct {
	OwnerID   int    `path:"ownerId"`
	Language  string `header:"Accept-Language"`
	FirstName string `form:"firstName,required"`
	LastName  string `form:"lastName,required"`
	Address   string `form:"address,required"`
	City      string `form:"city,required"`
	Telephone string `form:"telephone,required"`
}

EditOwnerRequest binds a protected path identity and editable fields.

func (EditOwnerRequest) Apply

func (request EditOwnerRequest) Apply(value *Owner)

Apply updates editable fields while preserving identity and pets.

type EditPetRequest

type EditPetRequest struct {
	OwnerID   int    `path:"ownerId"`
	PetID     int    `path:"petId"`
	Language  string `header:"Accept-Language"`
	Name      string `form:"name,required"`
	BirthDate string `form:"birthDate,required"`
	TypeID    int    `form:"type,required"`
}

EditPetRequest binds an existing pet and its editable fields.

type FindOwnerFormRequest

type FindOwnerFormRequest struct {
	Language string `header:"Accept-Language"`
}

FindOwnerFormRequest binds browser language preferences for owner search.

type FindOwnersModel

type FindOwnersModel struct {
	presentation.Page
	LastName string
	Errors   []validation.Violation
}

FindOwnersModel renders owner search input and failures.

type FindOwnersRequest

type FindOwnersRequest struct {
	LastName string `query:"lastName"`
	Page     int    `query:"page"`
	Language string `header:"Accept-Language"`
}

FindOwnersRequest binds the owner prefix and optional one-based page.

type NewOwnerRequest

type NewOwnerRequest struct {
	Language string `header:"Accept-Language"`
}

NewOwnerRequest binds browser language preferences for owner creation.

type NewPetRequest

type NewPetRequest struct {
	OwnerID  int    `path:"ownerId"`
	Language string `header:"Accept-Language"`
}

NewPetRequest binds the owner identity for a new pet form.

type NewVisitRequest

type NewVisitRequest struct {
	OwnerID  int    `path:"ownerId"`
	PetID    int    `path:"petId"`
	Language string `header:"Accept-Language"`
}

NewVisitRequest binds the owner and pet identities for a visit form.

type Owner

type Owner struct {
	model.Person
	Address   string
	City      string
	Telephone string
	Pets      []Pet
}

Owner is a person responsible for zero or more pets.

func (*Owner) AddPet

func (owner *Owner) AddPet(pet Pet) error

AddPet adds one new pet and rejects nil receivers or persisted duplicates.

func (*Owner) AddVisit

func (owner *Owner) AddVisit(
	petID model.ID,
	visit Visit,
) error

AddVisit adds a visit to an existing pet.

func (*Owner) Clone

func (owner *Owner) Clone() Owner

Clone returns a deep value copy suitable for repository boundaries.

func (*Owner) PetByID

func (owner *Owner) PetByID(id model.ID) (Pet, bool)

PetByID returns a defensive copy of one persisted pet.

func (*Owner) PetByName

func (owner *Owner) PetByName(
	name string,
	ignoreNew bool,
) (Pet, bool)

PetByName returns a case-insensitive defensive copy. New pets can be omitted while validating an edit against already-persisted siblings.

func (*Owner) Validate

func (owner *Owner) Validate() (validation.Errors, error)

Validate returns the Petclinic owner form constraints in stable field order.

type OwnerDetailsModel

type OwnerDetailsModel struct {
	presentation.Page
	Owner Owner
}

OwnerDetailsModel renders one complete owner aggregate.

type OwnerFormModel

type OwnerFormModel struct {
	presentation.Page
	Owner    Owner
	Errors   []validation.Violation
	Creating bool
}

OwnerFormModel renders create and edit forms.

type OwnerFormRequest

type OwnerFormRequest struct {
	Language  string `header:"Accept-Language"`
	FirstName string `form:"firstName,required"`
	LastName  string `form:"lastName,required"`
	Address   string `form:"address,required"`
	City      string `form:"city,required"`
	Telephone string `form:"telephone,required"`
}

OwnerFormRequest binds only the editable owner fields.

func (OwnerFormRequest) Owner

func (request OwnerFormRequest) Owner() Owner

Owner returns a new aggregate without accepting caller-owned identities.

type OwnerIDRequest

type OwnerIDRequest struct {
	OwnerID  int    `path:"ownerId"`
	Language string `header:"Accept-Language"`
}

OwnerIDRequest binds one persisted owner identity.

type OwnerPetRequest

type OwnerPetRequest struct {
	OwnerID  int    `path:"ownerId"`
	PetID    int    `path:"petId"`
	Language string `header:"Accept-Language"`
}

OwnerPetRequest binds one pet inside its owner aggregate.

type OwnersListModel

type OwnersListModel struct {
	presentation.Page
	Owners       []Owner
	LastName     string
	CurrentPage  int
	TotalPages   int
	TotalItems   int
	PreviousPage int
	NextPage     int
	HasPrevious  bool
	HasNext      bool
}

OwnersListModel renders one deterministic owner result page.

type Pet

type Pet struct {
	model.NamedEntity
	BirthDate time.Time
	Type      PetType
	Visits    []Visit
}

Pet is an animal owned by one Petclinic owner.

func (*Pet) AddVisit

func (pet *Pet) AddVisit(visit Visit) error

AddVisit adds one new visit and keeps visits ordered by date then identity.

func (*Pet) Clone

func (pet *Pet) Clone() Pet

Clone returns a deep value copy.

func (*Pet) Validate

func (pet *Pet) Validate(today time.Time) (validation.Errors, error)

Validate returns stable Petclinic pet constraints.

type PetController

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

PetController serves pet creation and editing inside an owner aggregate.

@Controller

func NewPetController

func NewPetController(
	owners Repository,
	petTypes PetTypeRepository,
	messages *i18n.Catalog,
) (*PetController, error)

NewPetController constructs the pet HTTP boundary.

func (*PetController) Create

func (controller *PetController) Create(
	ctx context.Context,
	request PetFormRequest,
	binding web.BindingResult,
) (view.Result, error)

Create validates and adds a pet to one owner.

@Post("/owners/{ownerId}/pets/new")

func (*PetController) EditForm

func (controller *PetController) EditForm(
	ctx context.Context,
	request OwnerPetRequest,
) (view.Result, error)

EditForm renders one existing pet for editing.

@Get("/owners/{ownerId}/pets/{petId}/edit")

func (*PetController) NewForm

func (controller *PetController) NewForm(
	ctx context.Context,
	request NewPetRequest,
) (view.Result, error)

NewForm renders a new-pet form for one owner.

@Get("/owners/{ownerId}/pets/new")

func (*PetController) Update

func (controller *PetController) Update(
	ctx context.Context,
	request EditPetRequest,
	binding web.BindingResult,
) (view.Result, error)

Update validates and replaces one pet while preserving its visits.

@Post("/owners/{ownerId}/pets/{petId}/edit")

type PetFormModel

type PetFormModel struct {
	presentation.Page
	Owner    Owner
	Pet      Pet
	PetTypes []PetType
	Errors   []validation.Violation
	Creating bool
}

PetFormModel is the immutable create/edit pet view model.

type PetFormRequest

type PetFormRequest struct {
	OwnerID   int    `path:"ownerId"`
	Language  string `header:"Accept-Language"`
	Name      string `form:"name,required"`
	BirthDate string `form:"birthDate,required"`
	TypeID    int    `form:"type,required"`
}

PetFormRequest binds a new pet and its protected owner identity.

type PetType

type PetType struct {
	model.NamedEntity
}

PetType classifies an animal, such as cat, dog, or hamster.

type PetTypeRepository

type PetTypeRepository interface {
	FindAll(context.Context) ([]PetType, error)
}

PetTypeRepository lists the stable pet-type reference catalog.

type Repository

type Repository interface {
	FindByID(context.Context, model.ID) (Owner, bool, error)
	FindByLastName(
		context.Context,
		string,
		int,
		int,
	) ([]Owner, int, error)
	Save(context.Context, Owner) (Owner, error)
}

Repository persists complete owner aggregates.

type Visit

type Visit struct {
	model.BaseEntity
	Date        time.Time
	Description string
}

Visit records veterinary care for one pet.

func (Visit) Validate

func (visit Visit) Validate() (validation.Errors, error)

Validate returns stable visit constraints.

type VisitController

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

VisitController serves visit registration inside a pet aggregate.

@Controller

func NewVisitController

func NewVisitController(
	owners Repository,
	messages *i18n.Catalog,
) (*VisitController, error)

NewVisitController constructs the visit HTTP boundary.

func (*VisitController) Create

func (controller *VisitController) Create(
	ctx context.Context,
	request VisitFormRequest,
	binding web.BindingResult,
) (view.Result, error)

Create validates and persists one visit.

@Post("/owners/{ownerId}/pets/{petId}/visits/new")

func (*VisitController) NewForm

func (controller *VisitController) NewForm(
	ctx context.Context,
	request NewVisitRequest,
) (view.Result, error)

NewForm renders a visit form with the pet's visit history.

@Get("/owners/{ownerId}/pets/{petId}/visits/new")

type VisitFormModel

type VisitFormModel struct {
	presentation.Page
	Owner  Owner
	Pet    Pet
	Visit  Visit
	Errors []validation.Violation
}

VisitFormModel is the immutable new-visit view model.

type VisitFormRequest

type VisitFormRequest struct {
	OwnerID     int    `path:"ownerId"`
	PetID       int    `path:"petId"`
	Language    string `header:"Accept-Language"`
	Date        string `form:"date,required"`
	Description string `form:"description,required"`
}

VisitFormRequest binds a new visit and protected aggregate identities.

Jump to

Keyboard shortcuts

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