Species update and create

This commit is contained in:
Matthew Dillon 2015-06-03 16:55:05 -08:00
parent ed1f795a01
commit d436a8c344
2 changed files with 33 additions and 0 deletions

View file

@ -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 {

View file

@ -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
}