diff --git a/server/go.mod b/server/go.mod index 15bc209965..d5ede6b8d6 100644 --- a/server/go.mod +++ b/server/go.mod @@ -26,7 +26,7 @@ require ( github.com/paulmach/go.geojson v1.4.0 github.com/pkg/errors v0.9.1 github.com/ravilushqa/otelgqlgen v0.15.0 - github.com/reearth/reearthx v0.0.0-20240403021819-5cbc45bf18eb + github.com/reearth/reearthx v0.0.0-20240809042445-586dfb9c441b github.com/samber/lo v1.39.0 github.com/spf13/afero v1.11.0 github.com/square/mongo-lock v0.0.0-20201208161834-4db518ed7fb2 diff --git a/server/go.sum b/server/go.sum index 3a6dfb0b38..52d0e61405 100644 --- a/server/go.sum +++ b/server/go.sum @@ -509,8 +509,8 @@ github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZN github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= github.com/ravilushqa/otelgqlgen v0.15.0 h1:U85nrlweMXTGaMChUViYM39/MXBZVeVVlpuHq+6eECQ= github.com/ravilushqa/otelgqlgen v0.15.0/go.mod h1:o+1Eju0VySmgq2BP8Vupz2YrN21Bj7D7imBqu3m2uB8= -github.com/reearth/reearthx v0.0.0-20240403021819-5cbc45bf18eb h1:K0azcAIwDhuyZw60ib69g/wgNVy0FgLhl2XUWtr4Y5A= -github.com/reearth/reearthx v0.0.0-20240403021819-5cbc45bf18eb/go.mod h1:d1WXkdCVzSoc8pl3vW9/9yKfk4fdoZQZhX8Ot8jqgnc= +github.com/reearth/reearthx v0.0.0-20240809042445-586dfb9c441b h1:1flLX4/85flJme++BapI9bi81I1mkd2qJ5nBVpTAXY4= +github.com/reearth/reearthx v0.0.0-20240809042445-586dfb9c441b/go.mod h1:d1WXkdCVzSoc8pl3vW9/9yKfk4fdoZQZhX8Ot8jqgnc= github.com/robertkrimen/godocdown v0.0.0-20130622164427-0bfa04905481/go.mod h1:C9WhFzY47SzYBIvzFqSvHIR6ROgDo4TtdTuRaOMjF/s= github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ= github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4= diff --git a/server/internal/infrastructure/mongo/project.go b/server/internal/infrastructure/mongo/project.go index 613d512c84..5c1079c085 100644 --- a/server/internal/infrastructure/mongo/project.go +++ b/server/internal/infrastructure/mongo/project.go @@ -4,8 +4,6 @@ import ( "context" "fmt" "regexp" - "sort" - "strings" "github.com/reearth/reearth/server/internal/infrastructure/mongo/mongodoc" "github.com/reearth/reearth/server/internal/usecase/repo" @@ -94,28 +92,7 @@ func (r *Project) FindByWorkspace(ctx context.Context, id accountdomain.Workspac }) } - projects, pageInfo, err := r.paginate(ctx, filter, uFilter.Sort, uFilter.Pagination) - - if err != nil { - return projects, pageInfo, err - } - - if uFilter.Sort != nil { - s := *uFilter.Sort - sort.SliceStable(projects, func(i, j int) bool { - switch s { - case project.SortTypeID: - return projects[i].ID().Compare(projects[j].ID()) < 0 - case project.SortTypeUpdatedAt: - return projects[i].UpdatedAt().Before(projects[j].UpdatedAt()) - case project.SortTypeName: - return strings.Compare(strings.ToLower(projects[i].Name()), strings.ToLower(projects[j].Name())) < 0 - } - return false - }) - } - - return projects, pageInfo, err + return r.paginate(ctx, filter, uFilter.Sort, uFilter.Pagination) } func (r *Project) FindByPublicName(ctx context.Context, name string) (*project.Project, error) { @@ -196,8 +173,13 @@ func (r *Project) findOne(ctx context.Context, filter any, filterByWorkspaces bo func (r *Project) paginate(ctx context.Context, filter any, sort *project.SortType, pagination *usecasex.Pagination) ([]*project.Project, *usecasex.PageInfo, error) { var usort *usecasex.Sort if sort != nil { - usort = &usecasex.Sort{ - Key: string(*sort), + switch *sort { + case project.SortTypeName: + usort = &usecasex.Sort{Key: "name", Reverted: false} + case project.SortTypeID: + usort = &usecasex.Sort{Key: "createdAt", Reverted: false} + case project.SortTypeUpdatedAt: + usort = &usecasex.Sort{Key: "updatedAt", Reverted: true} } }