diff --git a/gc/service/service.go b/gc/service/service.go
index a78ea35..f7b1fcd 100644
--- a/gc/service/service.go
+++ b/gc/service/service.go
@@ -51,7 +51,7 @@ func (s *service) Run(ctx context.Context) error {
for _, version := range versions {
log.WithFields(log.Fields{
"container": container,
- "version": version,
+ "version": version.Name,
}).Debugf("listing objects ...")
var (
@@ -69,9 +69,9 @@ func (s *service) Run(ctx context.Context) error {
var objects []string = []string{}
- total, objects, err = s.cfg.MdRepo.ListObjects(ctx, container, version, offset, defaultLimit)
+ total, objects, err = s.cfg.MdRepo.ListObjects(ctx, container, version.Name, offset, defaultLimit)
if err != nil {
- return errors.Wrapf(err, "error listing objects for container `%s`; version `%s`", container, version)
+ return errors.Wrapf(err, "error listing objects for container `%s`; version `%s`", container, version.Name)
}
if total == 0 {
@@ -81,29 +81,29 @@ func (s *service) Run(ctx context.Context) error {
if !s.cfg.DryRun {
log.WithFields(log.Fields{
"container": container,
- "version": version,
+ "version": version.Name,
"amount": len(objects),
}).Info("Performing actual metadata deletion: objects")
- err = s.cfg.MdRepo.DeleteObject(ctx, container, version, objects...)
+ err = s.cfg.MdRepo.DeleteObject(ctx, container, version.Name, objects...)
if err != nil {
- return errors.Wrapf(err, "error removing object from `%s/%s (%d objects)`", container, version, len(objects))
+ return errors.Wrapf(err, "error removing object from `%s/%s (%d objects)`", container, version.Name, len(objects))
}
}
}
log.WithFields(log.Fields{
"container": container,
- "version": version,
+ "version": version.Name,
}).Debug("deleting version ...")
if !s.cfg.DryRun {
log.WithFields(log.Fields{
"container": container,
- "version": version,
+ "version": version.Name,
}).Info("Performing actual metadata deletion: version")
- err = s.cfg.MdRepo.DeleteVersion(ctx, container, version)
+ err = s.cfg.MdRepo.DeleteVersion(ctx, container, version.Name)
if err != nil {
return err
}
diff --git a/gc/service/service_test.go b/gc/service/service_test.go
index 099c9fd..fecdd58 100644
--- a/gc/service/service_test.go
+++ b/gc/service/service_test.go
@@ -8,6 +8,7 @@ import (
log "github.com/sirupsen/logrus"
"github.com/stretchr/testify/suite"
+ "github.com/teran/archived/models"
repoMock "github.com/teran/archived/repositories/metadata/mock"
)
@@ -18,7 +19,9 @@ func init() {
func (s *serviceTestSuite) TestAll() {
call1 := s.repoMock.On("ListContainers").Return([]string{"container1"}, nil).Once()
- call2 := s.repoMock.On("ListUnpublishedVersionsByContainer", "container1").Return([]string{"version1"}, nil).Once().NotBefore(call1)
+ call2 := s.repoMock.On("ListUnpublishedVersionsByContainer", "container1").Return([]models.Version{
+ {Name: "version1"},
+ }, nil).Once().NotBefore(call1)
call3 := s.repoMock.On("ListObjects", "container1", "version1", uint64(0), uint64(1000)).Return(uint64(3), []string{"obj1", "obj2", "obj3"}, nil).Once().NotBefore(call2)
call4 := s.repoMock.On("DeleteObject", "container1", "version1", []string{"obj1", "obj2", "obj3"}).Return(nil).Once().NotBefore(call3)
call5 := s.repoMock.On("ListObjects", "container1", "version1", uint64(0), uint64(1000)).Return(uint64(0), []string{}, nil).Once().NotBefore(call4)
diff --git a/models/version.go b/models/version.go
new file mode 100644
index 0000000..b146cc3
--- /dev/null
+++ b/models/version.go
@@ -0,0 +1,9 @@
+package models
+
+import "time"
+
+type Version struct {
+ Name string
+ IsPublished bool
+ CreatedAt time.Time
+}
diff --git a/presenter/manager/grpc/handlers.go b/presenter/manager/grpc/handlers.go
index 5414298..ee9b113 100644
--- a/presenter/manager/grpc/handlers.go
+++ b/presenter/manager/grpc/handlers.go
@@ -76,8 +76,13 @@ func (h *handlers) ListVersions(ctx context.Context, in *v1.ListVersionsRequest)
return nil, err
}
+ versionNames := []string{}
+ for _, v := range versions {
+ versionNames = append(versionNames, v.Name)
+ }
+
return &v1.ListVersionsResponse{
- Versions: versions,
+ Versions: versionNames,
}, nil
}
diff --git a/presenter/publisher/html/handlers.go b/presenter/publisher/html/handlers.go
index f69fca5..96b8634 100644
--- a/presenter/publisher/html/handlers.go
+++ b/presenter/publisher/html/handlers.go
@@ -12,6 +12,7 @@ import (
echo "github.com/labstack/echo/v4"
log "github.com/sirupsen/logrus"
+ "github.com/teran/archived/models"
"github.com/teran/archived/service"
)
@@ -81,7 +82,7 @@ func (h *handlers) VersionIndex(c echo.Context) error {
CurrentPage uint64
PagesCount uint64
Container string
- Versions []string
+ Versions []models.Version
}
return c.Render(http.StatusOK, "version-list.html", &data{
diff --git a/presenter/publisher/html/handlers_test.go b/presenter/publisher/html/handlers_test.go
index 4f15b77..76dc661 100644
--- a/presenter/publisher/html/handlers_test.go
+++ b/presenter/publisher/html/handlers_test.go
@@ -10,6 +10,7 @@ import (
echo "github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/stretchr/testify/suite"
+ "github.com/teran/archived/models"
"github.com/teran/archived/service"
)
@@ -20,7 +21,9 @@ func (s *handlersTestSuite) TestContainerIndex() {
}
func (s *handlersTestSuite) TestVersionIndex() {
- s.serviceMock.On("ListPublishedVersionsByPage", "test-container-1", uint64(1)).Return(uint64(100), []string{"20241011121314"}, nil).Once()
+ s.serviceMock.On("ListPublishedVersionsByPage", "test-container-1", uint64(1)).Return(uint64(100), []models.Version{
+ {Name: "20241011121314"},
+ }, nil).Once()
s.compareHTMLResponse(s.srv.URL+"/test-container-1/", "testdata/versions.html.sample")
}
@@ -51,7 +54,7 @@ func (s *handlersTestSuite) TestGetObject() {
}
func (s *handlersTestSuite) TestErrNotFound() {
- s.serviceMock.On("ListPublishedVersionsByPage", "test-container-1", uint64(1)).Return(uint64(100), []string(nil), service.ErrNotFound).Once()
+ s.serviceMock.On("ListPublishedVersionsByPage", "test-container-1", uint64(1)).Return(uint64(100), []models.Version(nil), service.ErrNotFound).Once()
s.compareHTMLResponse(s.srv.URL+"/test-container-1/", "testdata/404.html.sample")
s.serviceMock.On("ListObjectsByPage", "test-container-1", "20240101010101", uint64(1)).Return(uint64(100), []string(nil), service.ErrNotFound).Once()
diff --git a/presenter/publisher/html/templates/version-list.html b/presenter/publisher/html/templates/version-list.html
index e26bc95..3c5c152 100644
--- a/presenter/publisher/html/templates/version-list.html
+++ b/presenter/publisher/html/templates/version-list.html
@@ -2,7 +2,7 @@
{{ template "header" . }}
..
{{- range $version := .Versions }}
- {{ $version }}/
+ {{ $version.Name }}/
{{- else }}
No versions found
{{- end }} diff --git a/repositories/metadata/metadata.go b/repositories/metadata/metadata.go index f3260dc..22d81c6 100644 --- a/repositories/metadata/metadata.go +++ b/repositories/metadata/metadata.go @@ -5,7 +5,8 @@ import ( "github.com/pkg/errors" - "github.com/teran/archived/exporter/models" + emodels "github.com/teran/archived/exporter/models" + "github.com/teran/archived/models" ) var ErrNotFound = errors.New("not found") @@ -17,10 +18,10 @@ type Repository interface { CreateVersion(ctx context.Context, container string) (string, error) GetLatestPublishedVersionByContainer(ctx context.Context, container string) (string, error) - ListAllVersionsByContainer(ctx context.Context, container string) ([]string, error) - ListPublishedVersionsByContainer(ctx context.Context, container string) ([]string, error) - ListPublishedVersionsByContainerAndPage(ctx context.Context, container string, offset, limit uint64) (uint64, []string, error) - ListUnpublishedVersionsByContainer(ctx context.Context, container string) ([]string, error) + ListAllVersionsByContainer(ctx context.Context, container string) ([]models.Version, error) + ListPublishedVersionsByContainer(ctx context.Context, container string) ([]models.Version, error) + ListPublishedVersionsByContainerAndPage(ctx context.Context, container string, offset, limit uint64) (uint64, []models.Version, error) + ListUnpublishedVersionsByContainer(ctx context.Context, container string) ([]models.Version, error) MarkVersionPublished(ctx context.Context, container, version string) error DeleteVersion(ctx context.Context, container, version string) error @@ -33,5 +34,5 @@ type Repository interface { GetBlobKeyByObject(ctx context.Context, container, version, key string) (string, error) EnsureBlobKey(ctx context.Context, key string, size uint64) error - CountStats(ctx context.Context) (*models.Stats, error) + CountStats(ctx context.Context) (*emodels.Stats, error) } diff --git a/repositories/metadata/mock/mock.go b/repositories/metadata/mock/mock.go index 479dc57..5445db7 100644 --- a/repositories/metadata/mock/mock.go +++ b/repositories/metadata/mock/mock.go @@ -4,7 +4,8 @@ import ( "context" "github.com/stretchr/testify/mock" - "github.com/teran/archived/exporter/models" + emodels "github.com/teran/archived/exporter/models" + "github.com/teran/archived/models" "github.com/teran/archived/repositories/metadata" ) @@ -43,24 +44,24 @@ func (m *Mock) GetLatestPublishedVersionByContainer(_ context.Context, container return args.String(0), args.Error(1) } -func (m *Mock) ListAllVersionsByContainer(_ context.Context, container string) ([]string, error) { +func (m *Mock) ListAllVersionsByContainer(_ context.Context, container string) ([]models.Version, error) { args := m.Called(container) - return args.Get(0).([]string), args.Error(1) + return args.Get(0).([]models.Version), args.Error(1) } -func (m *Mock) ListPublishedVersionsByContainer(_ context.Context, container string) ([]string, error) { +func (m *Mock) ListPublishedVersionsByContainer(_ context.Context, container string) ([]models.Version, error) { args := m.Called(container) - return args.Get(0).([]string), args.Error(1) + return args.Get(0).([]models.Version), args.Error(1) } -func (m *Mock) ListPublishedVersionsByContainerAndPage(_ context.Context, container string, offset, limit uint64) (uint64, []string, error) { +func (m *Mock) ListPublishedVersionsByContainerAndPage(_ context.Context, container string, offset, limit uint64) (uint64, []models.Version, error) { args := m.Called(container, offset, limit) - return args.Get(0).(uint64), args.Get(1).([]string), args.Error(2) + return args.Get(0).(uint64), args.Get(1).([]models.Version), args.Error(2) } -func (m *Mock) ListUnpublishedVersionsByContainer(_ context.Context, container string) ([]string, error) { +func (m *Mock) ListUnpublishedVersionsByContainer(_ context.Context, container string) ([]models.Version, error) { args := m.Called(container) - return args.Get(0).([]string), args.Error(1) + return args.Get(0).([]models.Version), args.Error(1) } func (m *Mock) MarkVersionPublished(_ context.Context, container, version string) error { @@ -108,7 +109,7 @@ func (m *Mock) EnsureBlobKey(_ context.Context, key string, size uint64) error { return args.Error(0) } -func (m *Mock) CountStats(ctx context.Context) (*models.Stats, error) { +func (m *Mock) CountStats(ctx context.Context) (*emodels.Stats, error) { args := m.Called() - return args.Get(0).(*models.Stats), args.Error(1) + return args.Get(0).(*emodels.Stats), args.Error(1) } diff --git a/repositories/metadata/postgresql/versions.go b/repositories/metadata/postgresql/versions.go index 91d04e3..44a000d 100644 --- a/repositories/metadata/postgresql/versions.go +++ b/repositories/metadata/postgresql/versions.go @@ -2,10 +2,13 @@ package postgresql import ( "context" + "time" sq "github.com/Masterminds/squirrel" "github.com/pkg/errors" ptr "github.com/teran/go-ptr" + + "github.com/teran/archived/models" ) const defaultLimit uint64 = 1000 @@ -81,26 +84,26 @@ func (r *repository) GetLatestPublishedVersionByContainer(ctx context.Context, c return versionName, nil } -func (r *repository) ListPublishedVersionsByContainer(ctx context.Context, container string) ([]string, error) { +func (r *repository) ListPublishedVersionsByContainer(ctx context.Context, container string) ([]models.Version, error) { _, versions, err := r.listVersionsByContainer(ctx, container, ptr.Bool(true), 0, 0) return versions, err } -func (r *repository) ListAllVersionsByContainer(ctx context.Context, container string) ([]string, error) { +func (r *repository) ListAllVersionsByContainer(ctx context.Context, container string) ([]models.Version, error) { _, versions, err := r.listVersionsByContainer(ctx, container, nil, 0, 0) return versions, err } -func (r *repository) ListUnpublishedVersionsByContainer(ctx context.Context, container string) ([]string, error) { +func (r *repository) ListUnpublishedVersionsByContainer(ctx context.Context, container string) ([]models.Version, error) { _, versions, err := r.listVersionsByContainer(ctx, container, ptr.Bool(false), 0, 0) return versions, err } -func (r *repository) ListPublishedVersionsByContainerAndPage(ctx context.Context, container string, offset, limit uint64) (uint64, []string, error) { +func (r *repository) ListPublishedVersionsByContainerAndPage(ctx context.Context, container string, offset, limit uint64) (uint64, []models.Version, error) { return r.listVersionsByContainer(ctx, container, ptr.Bool(true), offset, limit) } -func (r *repository) listVersionsByContainer(ctx context.Context, container string, isPublished *bool, offset, limit uint64) (uint64, []string, error) { +func (r *repository) listVersionsByContainer(ctx context.Context, container string, isPublished *bool, offset, limit uint64) (uint64, []models.Version, error) { if limit == 0 { limit = defaultLimit } @@ -140,7 +143,7 @@ func (r *repository) listVersionsByContainer(ctx context.Context, container stri } rows, err := selectQuery(ctx, r.db, psql. - Select("name"). + Select("name", "is_published", "created_at"). From("versions"). Where(condition). OrderBy("created_at DESC"). @@ -151,12 +154,21 @@ func (r *repository) listVersionsByContainer(ctx context.Context, container stri } defer rows.Close() - result := []string{} + result := []models.Version{} for rows.Next() { - var r string - if err := rows.Scan(&r); err != nil { + var ( + r models.Version + createdAt time.Time + ) + + if err := rows.Scan(&r.Name, &r.IsPublished, &createdAt); err != nil { return 0, nil, errors.Wrap(err, "error decoding database result") } + r.CreatedAt = time.Date( + createdAt.Year(), createdAt.Month(), createdAt.Day(), + createdAt.Hour(), createdAt.Minute(), createdAt.Second(), createdAt.Nanosecond(), + time.UTC, + ) result = append(result, r) } diff --git a/repositories/metadata/postgresql/versions_test.go b/repositories/metadata/postgresql/versions_test.go index 186a635..a94557e 100644 --- a/repositories/metadata/postgresql/versions_test.go +++ b/repositories/metadata/postgresql/versions_test.go @@ -1,6 +1,11 @@ package postgresql -import "github.com/teran/archived/repositories/metadata" +import ( + "time" + + "github.com/teran/archived/models" + "github.com/teran/archived/repositories/metadata" +) func (s *postgreSQLRepositoryTestSuite) TestVersionsOperations() { s.tp.On("Now").Return("2024-07-07T10:11:12Z").Times(4) @@ -22,11 +27,21 @@ func (s *postgreSQLRepositoryTestSuite) TestVersionsOperations() { listC1, err := s.repo.ListAllVersionsByContainer(s.ctx, "container1") s.Require().NoError(err) - s.Require().Equal([]string{"20240707101112"}, listC1) + s.Require().Equal([]models.Version{ + { + Name: "20240707101112", + CreatedAt: time.Date(2024, 7, 7, 10, 11, 12, 0, time.UTC), + }, + }, listC1) listC2, err := s.repo.ListAllVersionsByContainer(s.ctx, "container2") s.Require().NoError(err) - s.Require().Equal([]string{"20240707111213"}, listC2) + s.Require().Equal([]models.Version{ + { + Name: "20240707111213", + CreatedAt: time.Date(2024, 7, 7, 11, 12, 13, 0, time.UTC), + }, + }, listC2) } func (s *postgreSQLRepositoryTestSuite) TestPublishVersion() { @@ -40,22 +55,39 @@ func (s *postgreSQLRepositoryTestSuite) TestPublishVersion() { list, err := s.repo.ListAllVersionsByContainer(s.ctx, "container1") s.Require().NoError(err) - s.Require().Equal([]string{"20240707101112"}, list) + s.Require().Equal([]models.Version{ + { + Name: "20240707101112", + CreatedAt: time.Date(2024, 7, 7, 10, 11, 12, 0, time.UTC), + }, + }, list) list, err = s.repo.ListPublishedVersionsByContainer(s.ctx, "container1") s.Require().NoError(err) - s.Require().Equal([]string{}, list) + s.Require().Equal([]models.Version{}, list) err = s.repo.MarkVersionPublished(s.ctx, "container1", version) s.Require().NoError(err) list, err = s.repo.ListAllVersionsByContainer(s.ctx, "container1") s.Require().NoError(err) - s.Require().Equal([]string{"20240707101112"}, list) + s.Require().Equal([]models.Version{ + { + Name: "20240707101112", + IsPublished: true, + CreatedAt: time.Date(2024, 7, 7, 10, 11, 12, 0, time.UTC), + }, + }, list) list, err = s.repo.ListPublishedVersionsByContainer(s.ctx, "container1") s.Require().NoError(err) - s.Require().Equal([]string{"20240707101112"}, list) + s.Require().Equal([]models.Version{ + { + Name: "20240707101112", + IsPublished: true, + CreatedAt: time.Date(2024, 7, 7, 10, 11, 12, 0, time.UTC), + }, + }, list) } func (s *postgreSQLRepositoryTestSuite) TestListAllVersionsByContainerErrors() { @@ -107,12 +139,29 @@ func (s *postgreSQLRepositoryTestSuite) TestVersionsPagination() { total, listByPage, err := s.repo.ListPublishedVersionsByContainerAndPage(s.ctx, "container1", 0, 5) s.Require().NoError(err) s.Require().Equal(uint64(2), total) - s.Require().Equal([]string{version3, version1}, listByPage) + s.Require().Equal([]models.Version{ + { + Name: version3, + IsPublished: true, + CreatedAt: time.Date(2024, 7, 7, 10, 11, 14, 0, time.UTC), + }, + { + Name: version1, + IsPublished: true, + CreatedAt: time.Date(2024, 7, 7, 10, 11, 12, 0, time.UTC), + }, + }, listByPage) total, listByPage, err = s.repo.ListPublishedVersionsByContainerAndPage(s.ctx, "container1", 1, 2) s.Require().NoError(err) s.Require().Equal(uint64(2), total) - s.Require().Equal([]string{version1}, listByPage) + s.Require().Equal([]models.Version{ + { + Name: version1, + IsPublished: true, + CreatedAt: time.Date(2024, 7, 7, 10, 11, 12, 0, time.UTC), + }, + }, listByPage) } func (s *postgreSQLRepositoryTestSuite) TestDeleteVersion() { @@ -141,22 +190,54 @@ func (s *postgreSQLRepositoryTestSuite) TestDeleteVersion() { versions1, err := s.repo.ListAllVersionsByContainer(s.ctx, "container1") s.Require().NoError(err) - s.Require().Equal([]string{version2, version1}, versions1) + s.Require().Equal([]models.Version{ + { + Name: version2, + CreatedAt: time.Date(2024, 7, 7, 10, 11, 13, 0, time.UTC), + }, + { + Name: version1, + CreatedAt: time.Date(2024, 7, 7, 10, 11, 12, 0, time.UTC), + }, + }, versions1) versions2, err := s.repo.ListAllVersionsByContainer(s.ctx, "container2") s.Require().NoError(err) - s.Require().Equal([]string{version4, version3}, versions2) + s.Require().Equal([]models.Version{ + { + Name: version4, + CreatedAt: time.Date(2024, 7, 7, 10, 11, 15, 0, time.UTC), + }, + { + Name: version3, + CreatedAt: time.Date(2024, 7, 7, 10, 11, 14, 0, time.UTC), + }, + }, versions2) err = s.repo.DeleteVersion(s.ctx, "container1", version1) s.Require().NoError(err) versions1, err = s.repo.ListAllVersionsByContainer(s.ctx, "container1") s.Require().NoError(err) - s.Require().Equal([]string{version2}, versions1) + s.Require().Equal([]models.Version{ + { + Name: version2, + CreatedAt: time.Date(2024, 7, 7, 10, 11, 13, 0, time.UTC), + }, + }, versions1) versions2, err = s.repo.ListAllVersionsByContainer(s.ctx, "container2") s.Require().NoError(err) - s.Require().Equal([]string{version4, version3}, versions2) + s.Require().Equal([]models.Version{ + { + Name: version4, + CreatedAt: time.Date(2024, 7, 7, 10, 11, 15, 0, time.UTC), + }, + { + Name: version3, + CreatedAt: time.Date(2024, 7, 7, 10, 11, 14, 0, time.UTC), + }, + }, versions2) } func (s *postgreSQLRepositoryTestSuite) TestGetLatestPublishedVersionByContainer() { diff --git a/service/mock.go b/service/mock.go index c80ff16..6ece97d 100644 --- a/service/mock.go +++ b/service/mock.go @@ -4,6 +4,7 @@ import ( "context" "github.com/stretchr/testify/mock" + "github.com/teran/archived/models" ) var ( @@ -39,19 +40,19 @@ func (m *Mock) CreateVersion(_ context.Context, container string) (id string, er return args.String(0), args.Error(1) } -func (m *Mock) ListAllVersions(_ context.Context, container string) ([]string, error) { +func (m *Mock) ListAllVersions(_ context.Context, container string) ([]models.Version, error) { args := m.Called(container) - return args.Get(0).([]string), args.Error(1) + return args.Get(0).([]models.Version), args.Error(1) } -func (m *Mock) ListPublishedVersions(_ context.Context, container string) ([]string, error) { +func (m *Mock) ListPublishedVersions(_ context.Context, container string) ([]models.Version, error) { args := m.Called(container) - return args.Get(0).([]string), args.Error(1) + return args.Get(0).([]models.Version), args.Error(1) } -func (m *Mock) ListPublishedVersionsByPage(_ context.Context, container string, pageNum uint64) (uint64, []string, error) { +func (m *Mock) ListPublishedVersionsByPage(_ context.Context, container string, pageNum uint64) (uint64, []models.Version, error) { args := m.Called(container, pageNum) - return args.Get(0).(uint64), args.Get(1).([]string), args.Error(2) + return args.Get(0).(uint64), args.Get(1).([]models.Version), args.Error(2) } func (m *Mock) PublishVersion(_ context.Context, container, id string) error { diff --git a/service/service.go b/service/service.go index 3701983..94fad78 100644 --- a/service/service.go +++ b/service/service.go @@ -5,6 +5,7 @@ import ( "github.com/pkg/errors" + "github.com/teran/archived/models" "github.com/teran/archived/repositories/blob" "github.com/teran/archived/repositories/metadata" ) @@ -18,7 +19,7 @@ type Manager interface { DeleteContainer(ctx context.Context, name string) error CreateVersion(ctx context.Context, container string) (id string, err error) - ListAllVersions(ctx context.Context, container string) ([]string, error) + ListAllVersions(ctx context.Context, container string) ([]models.Version, error) PublishVersion(ctx context.Context, container, id string) error DeleteVersion(ctx context.Context, container, id string) error @@ -32,8 +33,8 @@ type Manager interface { type Publisher interface { ListContainers(ctx context.Context) ([]string, error) - ListPublishedVersions(ctx context.Context, container string) ([]string, error) - ListPublishedVersionsByPage(ctx context.Context, container string, pageNum uint64) (uint64, []string, error) + ListPublishedVersions(ctx context.Context, container string) ([]models.Version, error) + ListPublishedVersionsByPage(ctx context.Context, container string, pageNum uint64) (uint64, []models.Version, error) ListObjectsByPage(ctx context.Context, container, versionID string, pageNum uint64) (uint64, []string, error) GetObjectURL(ctx context.Context, container, versionID, key string) (string, error) @@ -86,12 +87,12 @@ func (s *service) CreateVersion(ctx context.Context, container string) (id strin return version, mapMetadataErrors(err) } -func (s *service) ListPublishedVersions(ctx context.Context, container string) ([]string, error) { +func (s *service) ListPublishedVersions(ctx context.Context, container string) ([]models.Version, error) { versions, err := s.mdRepo.ListPublishedVersionsByContainer(ctx, container) return versions, mapMetadataErrors(err) } -func (s *service) ListPublishedVersionsByPage(ctx context.Context, container string, pageNum uint64) (uint64, []string, error) { +func (s *service) ListPublishedVersionsByPage(ctx context.Context, container string, pageNum uint64) (uint64, []models.Version, error) { if pageNum < 1 { pageNum = 1 } @@ -111,7 +112,7 @@ func (s *service) ListPublishedVersionsByPage(ctx context.Context, container str return totalPages, versions, mapMetadataErrors(err) } -func (s *service) ListAllVersions(ctx context.Context, container string) ([]string, error) { +func (s *service) ListAllVersions(ctx context.Context, container string) ([]models.Version, error) { versions, err := s.mdRepo.ListAllVersionsByContainer(ctx, container) return versions, mapMetadataErrors(err) } diff --git a/service/service_test.go b/service/service_test.go index a894f8d..70d9476 100644 --- a/service/service_test.go +++ b/service/service_test.go @@ -7,6 +7,7 @@ import ( "github.com/pkg/errors" "github.com/stretchr/testify/suite" + "github.com/teran/archived/models" blobRepoMock "github.com/teran/archived/repositories/blob/mock" "github.com/teran/archived/repositories/metadata" mdRepoMock "github.com/teran/archived/repositories/metadata/mock" @@ -89,28 +90,32 @@ func (s *serviceTestSuite) TestListContainers() { } func (s *serviceTestSuite) TestListPublishedVersions() { - s.mdRepoMock.On("ListPublishedVersionsByContainer", "container").Return([]string{ - "version1", "version2", + s.mdRepoMock.On("ListPublishedVersionsByContainer", "container").Return([]models.Version{ + {Name: "version1"}, + {Name: "version2"}, }, nil).Once() versions, err := s.svc.ListPublishedVersions(s.ctx, "container") s.Require().NoError(err) - s.Require().Equal([]string{ - "version1", "version2", + s.Require().Equal([]models.Version{ + {Name: "version1"}, + {Name: "version2"}, }, versions) } func (s *serviceTestSuite) TestListPublishedVersionsByPage() { s.mdRepoMock. On("ListPublishedVersionsByContainerAndPage", "container", uint64(450), uint64(50)). - Return(uint64(1000), []string{ - "version1", "version2", + Return(uint64(1000), []models.Version{ + {Name: "version1"}, + {Name: "version2"}, }, nil).Once() total, versions, err := s.svc.ListPublishedVersionsByPage(s.ctx, "container", 10) s.Require().NoError(err) - s.Require().Equal([]string{ - "version1", "version2", + s.Require().Equal([]models.Version{ + {Name: "version1"}, + {Name: "version2"}, }, versions) s.Require().Equal(uint64(20), total) }