Implement creating food
This commit is contained in:
@@ -56,6 +56,21 @@ func (s *FoodService) GetRecent() ([]Food, error) {
|
||||
return res, nil
|
||||
}
|
||||
|
||||
func (s *FoodService) GetLastPer100(name string) (float32, error) {
|
||||
if s.db == nil || !s.db.Ready {
|
||||
return 0, fmt.Errorf("cannot get last per100, db is nil or is not ready")
|
||||
}
|
||||
|
||||
row := s.db.readConn.QueryRow("SELECT per100 FROM food WHERE food like ? ORDER BY rowid DESC LIMIT 1", name+"%")
|
||||
var per100 float32
|
||||
err := row.Scan(&per100)
|
||||
if err != nil {
|
||||
return 0, fmt.Errorf("error scanning row: %v", err)
|
||||
}
|
||||
|
||||
return per100, nil
|
||||
}
|
||||
|
||||
func (s *FoodService) Create(food Food) (Food, error) {
|
||||
if s.db == nil || !s.db.Ready {
|
||||
return food, fmt.Errorf("cannot create food, db is nil or is not ready")
|
||||
|
Reference in New Issue
Block a user