This commit is contained in:
2026-03-07 19:23:00 +07:00
parent 6ad47cbc38
commit 856f12f2e3
12 changed files with 116 additions and 177 deletions
@@ -0,0 +1,11 @@
package models
type Application struct {
Name string `json:"name"`
}
func NewApplication(name string) *Application {
return &Application{
Name: name,
}
}
@@ -0,0 +1,31 @@
package models
type Door struct {
Code string `json:"code"`
Name string `json:"name"`
Show bool `json:"show"`
}
func NewDoor(
code string,
name string,
opts ...DoorOpt,
) *Door {
door := &Door{
Code: code,
Name: name,
}
for _, opt := range opts {
opt(door)
}
return door
}
type DoorOpt func(door *Door) error
func WithDoorShow(show bool) DoorOpt {
return func(door *Door) error {
door.Show = show
return nil
}
}
@@ -0,0 +1,62 @@
package models
type Place struct {
Code string `json:"code"`
Name string `json:"name"`
Text string `json:"text"`
Applications []*Application `json:"applications,omitempty"`
Hidden bool `json:"hidden"`
Doors []*Door `json:"doors"`
}
func NewPlace(
code string,
name string,
text string,
opts ...PlaceOpt,
) *Place {
p := &Place{
Code: code,
Name: name,
Text: text,
}
for _, opt := range opts {
opt(p)
}
return p
}
func NewNotFoundPlace(code string) *Place {
return NewPlace(code, "Не найдено", "Такой точки не существует.")
}
func NewClientErrorPlace(code string) *Place {
return NewPlace(code, "Не найдено", "Детективы, внимательно читайте правила.")
}
type PlaceOpt func(place *Place) error
func WithPlaceApplication(applications ...*Application) PlaceOpt {
return func(place *Place) error {
for _, application := range applications {
place.Applications = append(place.Applications, application)
}
return nil
}
}
func WithPlaceHidden(hidden bool) PlaceOpt {
return func(place *Place) error {
place.Hidden = hidden
return nil
}
}
func WithPlaceDoors(doors ...*Door) PlaceOpt {
return func(place *Place) error {
for _, door := range doors {
place.Doors = append(place.Doors, door)
}
return nil
}
}
@@ -0,0 +1,5 @@
package models
type Story struct {
Places []*Place `json:"places"`
}