forked from mirrors/homebox
location endpoints
This commit is contained in:
parent
9583847f94
commit
c7cfb4335b
10 changed files with 395 additions and 51 deletions
|
@ -21,6 +21,7 @@ func (r *EntLocationRepository) Get(ctx context.Context, ID uuid.UUID) (*ent.Loc
|
|||
func (r *EntLocationRepository) GetAll(ctx context.Context, groupId uuid.UUID) ([]*ent.Location, error) {
|
||||
return r.db.Location.Query().
|
||||
Where(location.HasGroupWith(group.ID(groupId))).
|
||||
WithGroup().
|
||||
All(ctx)
|
||||
}
|
||||
|
||||
|
|
|
@ -3,13 +3,15 @@ package services
|
|||
import "github.com/hay-kot/content/backend/internal/repo"
|
||||
|
||||
type AllServices struct {
|
||||
User *UserService
|
||||
Admin *AdminService
|
||||
User *UserService
|
||||
Admin *AdminService
|
||||
Location *LocationService
|
||||
}
|
||||
|
||||
func NewServices(repos *repo.AllRepos) *AllServices {
|
||||
return &AllServices{
|
||||
User: &UserService{repos},
|
||||
Admin: &AdminService{repos},
|
||||
User: &UserService{repos},
|
||||
Admin: &AdminService{repos},
|
||||
Location: &LocationService{repos},
|
||||
}
|
||||
}
|
||||
|
|
|
@ -24,6 +24,22 @@ func ToLocationOut(location *ent.Location, err error) (*types.LocationOut, error
|
|||
}, err
|
||||
}
|
||||
|
||||
func (svc *LocationService) GetAll(ctx context.Context, groupId uuid.UUID) ([]*types.LocationOut, error) {
|
||||
panic("not implemented")
|
||||
func (svc *LocationService) Create(ctx context.Context, groupId uuid.UUID, data types.LocationCreate) (*types.LocationOut, error) {
|
||||
location, err := svc.repos.Locations.Create(ctx, groupId, data)
|
||||
return ToLocationOut(location, err)
|
||||
}
|
||||
|
||||
func (svc *LocationService) GetAll(ctx context.Context, groupId uuid.UUID) ([]*types.LocationOut, error) {
|
||||
locations, err := svc.repos.Locations.GetAll(ctx, groupId)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
locationsOut := make([]*types.LocationOut, len(locations))
|
||||
for i, location := range locations {
|
||||
locationOut, _ := ToLocationOut(location, nil)
|
||||
locationsOut[i] = locationOut
|
||||
}
|
||||
|
||||
return locationsOut, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue