feat: initial building endpoints
This commit is contained in:
@@ -177,3 +177,29 @@ func (s *DataStore) DeleteCategoryByID(id uint64) (bool, error) {
|
||||
}
|
||||
return true, nil
|
||||
}
|
||||
|
||||
func (s *DataStore) GetBuildings(offset, limit uint64) ([]*types.Building, error) {
|
||||
var buildings []*types.Building
|
||||
s.db.Order("id asc").Offset(int(offset)).Limit(int(limit)).Find(&buildings)
|
||||
if len(buildings) == 0 {
|
||||
return nil, fmt.Errorf("no buildings found")
|
||||
}
|
||||
return buildings, nil
|
||||
}
|
||||
|
||||
func (s *DataStore) TotalBuildings() (int64, error) {
|
||||
var count int64
|
||||
if tx := s.db.Find(&types.Building{}).Count(&count); tx.Error != nil {
|
||||
return 0, tx.Error
|
||||
}
|
||||
return count, nil
|
||||
}
|
||||
|
||||
func (s *DataStore) GetBuildingByID(id uint64) (*types.Building, error) {
|
||||
var result types.Building
|
||||
tx := s.db.Model(&types.Building{}).Where("id = ?", id).First(&result)
|
||||
if tx.Error != nil {
|
||||
return nil, fmt.Errorf("building %d not found", id)
|
||||
}
|
||||
return &result, nil
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user