diff --git a/handlers.go b/handlers.go index 72b0641..ec479a8 100644 --- a/handlers.go +++ b/handlers.go @@ -94,7 +94,9 @@ func Handler() http.Handler { r{handleLister(CharacteristicService{}), "GET", "/characteristics"}, r{handleGetter(CharacteristicService{}), "GET", "/characteristics/{Id:.+}"}, r{handleLister(SpeciesService{}), "GET", "/species"}, + r{handleCreater(SpeciesService{}), "POST", "/species"}, r{handleGetter(SpeciesService{}), "GET", "/species/{Id:.+}"}, + r{handleUpdater(SpeciesService{}), "PUT", "/species/{Id:.+}"}, } for _, route := range routes { diff --git a/species.go b/species.go index f8f02e0..83d0ae8 100644 --- a/species.go +++ b/species.go @@ -121,3 +121,34 @@ func (s SpeciesService) get(id int64, genus string) (entity, error) { } return &species, nil } + +func (s SpeciesService) update(id int64, e *entity, claims Claims) error { + species := (*e).(*Species) + species.UpdatedBy = claims.Sub + species.UpdatedAt = currentTime() + species.Id = id + + count, err := DBH.Update(species.SpeciesBase) + if err != nil { + return err + } + if count != 1 { + return ErrSpeciesNotUpdated + } + return nil +} + +func (s SpeciesService) create(e *entity, claims Claims) error { + species := (*e).(*Species) + ct := currentTime() + species.CreatedBy = claims.Sub + species.CreatedAt = ct + species.UpdatedBy = claims.Sub + species.UpdatedAt = ct + + err := DBH.Insert(species.SpeciesBase) + if err != nil { + return err + } + return nil +}