htmgo/sandbox/features/patient/patient-service.go

50 lines
972 B
Go
Raw Normal View History

package patient
import (
"errors"
"github.com/google/uuid"
2024-09-17 17:13:22 +00:00
"github.com/labstack/echo/v4"
2024-09-13 21:33:50 +00:00
"starter-template/database"
"time"
)
type Patient struct {
Name string
ReasonForVisit string
AppointmentDate time.Time
LocationName string
}
type Service struct {
2024-09-17 17:13:22 +00:00
ctx echo.Context
}
2024-09-17 17:13:22 +00:00
func NewService(ctx echo.Context) *Service {
return &Service{}
}
type CreatePatientRequest struct {
Name string
ReasonForVisit string
LocationName string
}
func (c *Service) Create(request CreatePatientRequest) error {
time.Sleep(time.Second)
database.HSet("patients", uuid.New().String(), Patient{
Name: request.Name,
ReasonForVisit: request.ReasonForVisit,
AppointmentDate: time.Now(),
LocationName: "New York",
})
return errors.New("error creating patient")
}
func (c *Service) List() ([]*Patient, error) {
patients, err := database.HList[Patient]("patients")
if err != nil {
return nil, err
}
return patients, nil
}