Skip to content

Commit

Permalink
ForRent should contain reference
Browse files Browse the repository at this point in the history
for refresh session
  • Loading branch information
drypa committed Mar 23, 2024
1 parent 9e2cf06 commit 5ad723d
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
2 changes: 1 addition & 1 deletion backend/device/for_rent.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@ package device
import "receipt_collector/nalogru/device"

type ForRent struct {
device.Device
*device.Device
IsRent bool
}
17 changes: 7 additions & 10 deletions backend/device/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ func NewService(ctx context.Context, r *repository.Repository) (*Service, error)
for i, v := range all {
v.Update = s.updateDeviceFunc(ctx, &v)
s.devices[i] = ForRent{
Device: v,
Device: &v,
IsRent: false,
}
}
Expand All @@ -39,7 +39,7 @@ func (s *Service) Add(ctx context.Context, d *device.Device) error {
d.Update = s.updateDeviceFunc(ctx, d)

forRent := ForRent{
Device: *d,
Device: d,
IsRent: false,
}
s.devices = append(s.devices, forRent)
Expand All @@ -62,7 +62,7 @@ func (s *Service) Rent(ctx context.Context) (*device.Device, error) {
for _, v := range s.devices {
if v.IsRent == false {
s.rent(&v)
return &v.Device, nil
return v.Device, nil
}
}
return nil, errors.New("no available devices found")
Expand Down Expand Up @@ -110,20 +110,17 @@ func (s *Service) Free(_ context.Context, device *device.Device) error {
func (s *Service) All(_ context.Context) []*device.Device {
res := make([]*device.Device, len(s.devices))
for i, d := range s.devices {
res[i] = &d.Device
res[i] = d.Device
}
return res
}

func (s *Service) GetByUserId(ctx context.Context, userId string) (*device.Device, error) {
devices, err := s.r.All(ctx)
if err != nil {
return nil, err
}
devices := s.All(ctx)
for _, d := range devices {
if d.UserId == userId {
d.Update = s.updateDeviceFunc(ctx, &d)
return &d, nil
d.Update = s.updateDeviceFunc(ctx, d)
return d, nil
}
}
return nil, nil
Expand Down
4 changes: 2 additions & 2 deletions backend/workers/settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,12 @@ import (

const intervalEnvironmentVariable = "GET_RECEIPT_WORKER_INTERVAL"

//Settings for Worker.
// Settings for Worker.
type Settings struct {
Interval time.Duration
}

//ReadFromEnvironment creates Settings from environment variables.
// ReadFromEnvironment creates Settings from environment variables.
func ReadFromEnvironment() Settings {
workerIntervalString := os.Getenv(intervalEnvironmentVariable)

Expand Down

0 comments on commit 5ad723d

Please sign in to comment.