diff --git a/dataswamp/namespace/entities.go b/dataswamp/namespace/entities.go index f26dc1f..28a32ff 100644 --- a/dataswamp/namespace/entities.go +++ b/dataswamp/namespace/entities.go @@ -11,6 +11,7 @@ type Namespace struct { LastSeen time.Time AllowanceDuration time.Duration FileQuota FileSizeQuota + Usage Usage } var ( diff --git a/dataswamp/namespace/valueobjects.go b/dataswamp/namespace/valueobjects.go index 5b0e4a6..d47f04f 100644 --- a/dataswamp/namespace/valueobjects.go +++ b/dataswamp/namespace/valueobjects.go @@ -32,3 +32,28 @@ func (f *FileSizeQuota) Remove(size int64) error { 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, + } +} diff --git a/dataswamp/services.go b/dataswamp/services.go index 6ed4a10..a9fae27 100644 --- a/dataswamp/services.go +++ b/dataswamp/services.go @@ -38,6 +38,7 @@ func (s SwampFileService) getOrCreateNs(namespace_in string) *namespace.Namespac time.Now(), s.default_allowance_duration, namespace.FileSizeQuota{s.default_allowance_bytes, 0}, + namespace.Usage{0, 0, 0, 0}, } created_ns, err := s.namespace_repo.Create(new_ns) diff --git a/infrastructure/memory/namespace/repository_test.go b/infrastructure/memory/namespace/repository_test.go index efd0869..e68cc1a 100644 --- a/infrastructure/memory/namespace/repository_test.go +++ b/infrastructure/memory/namespace/repository_test.go @@ -16,7 +16,14 @@ func TestUserAgentRepo(t *testing.T) { is.NoErr(err) 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) ns.Name = "n2"