Usage value object

master
Caj Larsson 3 years ago
parent 7274e08b9a
commit 443c9b9376

@ -11,6 +11,7 @@ type Namespace struct {
LastSeen time.Time LastSeen time.Time
AllowanceDuration time.Duration AllowanceDuration time.Duration
FileQuota FileSizeQuota FileQuota FileSizeQuota
Usage Usage
} }
var ( var (

@ -32,3 +32,28 @@ func (f *FileSizeQuota) Remove(size int64) error {
return nil return nil
} }
type Usage struct {
Uploads int64
UploadB int64
Downloads int64
DownloadB int64
}
func (u Usage) Uploaded(size int64) Usage {
return Usage{
u.Uploads + 1,
u.UploadB + size,
u.Downloads,
u.DownloadB,
}
}
func (u Usage) Downloaded(size int64) Usage {
return Usage{
u.Uploads,
u.UploadB,
u.Downloads + 1,
u.DownloadB + size,
}
}

@ -38,6 +38,7 @@ func (s SwampFileService) getOrCreateNs(namespace_in string) *namespace.Namespac
time.Now(), time.Now(),
s.default_allowance_duration, s.default_allowance_duration,
namespace.FileSizeQuota{s.default_allowance_bytes, 0}, namespace.FileSizeQuota{s.default_allowance_bytes, 0},
namespace.Usage{0, 0, 0, 0},
} }
created_ns, err := s.namespace_repo.Create(new_ns) created_ns, err := s.namespace_repo.Create(new_ns)

@ -16,7 +16,14 @@ func TestUserAgentRepo(t *testing.T) {
is.NoErr(err) is.NoErr(err)
is.Equal(len(all), 0) is.Equal(len(all), 0)
ns := namespace.Namespace{23, "n1", time.Now(), time.Duration(time.Hour * 3), namespace.FileSizeQuota{1000, 0}} ns := namespace.Namespace{
23,
"n1",
time.Now(),
time.Duration(time.Hour * 3),
namespace.FileSizeQuota{1000, 0},
namespace.Usage{0, 0, 0, 0},
}
ns1, _ := r.Create(ns) ns1, _ := r.Create(ns)
ns.Name = "n2" ns.Name = "n2"

Loading…
Cancel
Save