Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Pulling feat/list-content into develop #233

Merged
merged 34 commits into from
Aug 16, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
34 commits
Select commit Hold shift + click to select a range
c4edaab
feat(arangodb/statement.go): add new AQL queries for content listing …
cybersiddhu Aug 13, 2024
5a53cc6
feat(arangodb.go): add getListContentStatement to handle content retr…
cybersiddhu Aug 13, 2024
ccbb4b9
feat(repository.go): add ListContents method and ContentListNotFoundE…
cybersiddhu Aug 13, 2024
981d5dc
feat(arangodb.go): add ListContents method to fetch paginated content…
cybersiddhu Aug 13, 2024
32ddc74
feat(arangodb_test.go): add TestListContents to validate content list…
cybersiddhu Aug 13, 2024
2c1437b
test(arangodb_test.go): reduce test data size and enhance content lis…
cybersiddhu Aug 14, 2024
91aba76
refactor(arangodb_test.go): extract content creation and validation i…
cybersiddhu Aug 14, 2024
43501e6
chore(.gitignore): add .plandex to ignore list to prevent tracking of…
cybersiddhu Aug 14, 2024
96c4dd8
refactor(arangodb_test.go): move ListContents tests to separate file
cybersiddhu Aug 14, 2024
cf02284
feat(arangodb_list_test.go): add createCustomTestContents function to…
cybersiddhu Aug 14, 2024
cef3aa0
feat(arangodb_list_test.go): add custom content creation in tests for…
cybersiddhu Aug 14, 2024
ed9c07d
refactor(arangodb_list_test.go): parameterize namespace and name in t…
cybersiddhu Aug 14, 2024
b8ea6be
feat(arangodb_list_test.go): add tests for content listing with filters
cybersiddhu Aug 14, 2024
7dd31c4
feat(arangodb_list_test.go): add comprehensive test cases for content…
cybersiddhu Aug 14, 2024
ca56d82
refactor(arangodb_list_test.go): modularize test cases for content li…
cybersiddhu Aug 14, 2024
79ba2b8
refactor(arangodb_list_test.go): centralize test case struct and gene…
cybersiddhu Aug 15, 2024
f7ea20d
feat(go.mod): update go-genproto to latest version and add new depend…
cybersiddhu Aug 15, 2024
45e4217
feat(arangodb/field.go): add FilterMap function to map filter attribu…
cybersiddhu Aug 15, 2024
180f40d
feat(service.go): add query parsing and AQL statement generation for …
cybersiddhu Aug 15, 2024
eec7386
feat(service.go): add ListContents method to ContentService for conte…
cybersiddhu Aug 15, 2024
cd8fcb2
feat(service_test.go): add validateListContents function to enhance t…
cybersiddhu Aug 15, 2024
53a0e9f
feat(service_test.go): add storeMultipleContents function to handle b…
cybersiddhu Aug 15, 2024
90b2afb
feat(service_test.go): add TestListContentsService to validate conten…
cybersiddhu Aug 15, 2024
879f3a5
refactor(service_test.go): encapsulate parameters of storeMultipleCon…
cybersiddhu Aug 15, 2024
13e9000
fix(service.go): correct pagination logic in ListContents function
cybersiddhu Aug 16, 2024
c92cfbb
feat(service_test.go): extend TestListContentsService to validate pag…
cybersiddhu Aug 16, 2024
c033cac
fix(service.go): enhance error messages to include underlying errors
cybersiddhu Aug 16, 2024
c46d4fd
refactor(service.go): remove unused jsonapi import and Healthz method
cybersiddhu Aug 16, 2024
e14b21f
refactor(service.go): improve variable naming and error messages in f…
cybersiddhu Aug 16, 2024
af022e0
fix(service.go): handle generic errors in ListContents function
cybersiddhu Aug 16, 2024
81da92a
chore(.gitignore): add .aider* to ignore list to prevent tracking of …
cybersiddhu Aug 16, 2024
6727c32
feat(service_test.go): add tests for content filtering in ListContent…
cybersiddhu Aug 16, 2024
2d55411
test(service_test.go): rename and reformat test function for clarity …
cybersiddhu Aug 16, 2024
0e144fd
feat(service_test.go): enhance ListContentsService tests with structu…
cybersiddhu Aug 16, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
vendor/
.plandex
.aider*
4 changes: 3 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ require (
github.com/arangodb/go-driver v1.6.2
github.com/dictyBase/aphgrpc v1.4.2
github.com/dictyBase/arangomanager v0.4.0
github.com/dictyBase/go-genproto v0.0.0-20231030202356-522cb6f9976a
github.com/dictyBase/go-genproto v0.0.0-20240815171842-0da89d7f57e4
github.com/go-playground/validator/v10 v10.22.0
github.com/golang/protobuf v1.5.4
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0
Expand All @@ -19,11 +19,13 @@ require (
github.com/arangodb/go-velocypack v0.0.0-20200318135517-5af53c29c67e // indirect
github.com/cpuguy83/go-md2man/v2 v2.0.4 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/emirpasic/gods v1.18.1 // indirect
github.com/fatih/structs v1.1.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/gogo/protobuf v1.3.2 // indirect
github.com/jinzhu/now v1.1.5 // indirect
github.com/klauspost/compress v1.17.2 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mwitkow/go-proto-validators v0.2.0 // indirect
Expand Down
6 changes: 4 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,9 @@ github.com/dictyBase/aphgrpc v1.4.2 h1:jkNyIpUBATNVNTM99TfAHln8UEpzyvNNNuM2+UY6t
github.com/dictyBase/aphgrpc v1.4.2/go.mod h1:rzi2U95QntAuS6XpqespgZmQ8Ujo2Sq2R5FyhW5adA8=
github.com/dictyBase/arangomanager v0.4.0 h1:+HgmadUY0qXFMLfZocktynbERkX/FgWzC3vd/MMebnU=
github.com/dictyBase/arangomanager v0.4.0/go.mod h1:SmElsQJN3EbTjfYCkjS7/uyUkNVwaO2qJB9Mqrs0ND8=
github.com/dictyBase/go-genproto v0.0.0-20231030202356-522cb6f9976a h1:V0xN+gehQLCJrqFPI1nNd8wCIi6Z0ZQgmoZ6dmkPlV0=
github.com/dictyBase/go-genproto v0.0.0-20231030202356-522cb6f9976a/go.mod h1:KY6iUqXl1lLq81WTW9u5DfZE58xM61PsGLSLwwtePlk=
github.com/dictyBase/go-genproto v0.0.0-20240815171842-0da89d7f57e4 h1:kxY0rlODJu8qk5jXv9dzeOpOl3hV8r66y1YByPKCDIs=
github.com/dictyBase/go-genproto v0.0.0-20240815171842-0da89d7f57e4/go.mod h1:KY6iUqXl1lLq81WTW9u5DfZE58xM61PsGLSLwwtePlk=
github.com/emirpasic/gods v1.18.1 h1:FXtiHYKDGKCW2KzwZKx0iC0PQmdlorYgdFG9jPXJ1Bc=
github.com/emirpasic/gods v1.18.1/go.mod h1:8tpGGwCnJ5H4r6BWwaV6OrWmMoPhUl5jm/FMNAnJvWQ=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.1-0.20191026205805-5f8ba28d4473/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
Expand Down Expand Up @@ -84,6 +85,7 @@ github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0 h1:UH//fgunKIs4JdUbpDl1VZCDaL56wXCB/5+wF6uHfaI=
github.com/grpc-ecosystem/go-grpc-middleware v1.4.0/go.mod h1:g5qyo/la0ALbONm6Vbp88Yd8NsDy6rZz+RcrMPxvld8=
github.com/grpc-ecosystem/grpc-gateway v1.11.3/go.mod h1:vNeuVxBJEsws4ogUvrchl83t/GYV9WGTSLVdBhOQFDY=
github.com/jinzhu/now v1.1.5 h1:/o9tlHleP7gOFmsnYNz3RGnqzefHA47wQpKrrdTIwXQ=
github.com/jinzhu/now v1.1.5/go.mod h1:d3SSVoowX0Lcu0IBviAWJpolVfI5UJVZZ7cO71lE/z8=
github.com/kisielk/errcheck v1.2.0/go.mod h1:/BMXB+zMLi60iA8Vv6Ksmxu/1UDYcXs4uQLJ+jE2L00=
github.com/kisielk/errcheck v1.5.0/go.mod h1:pFxgyoBC7bSaBwPgfKdkLd5X25qrDl4LWUI2bnpBCr8=
Expand Down
91 changes: 82 additions & 9 deletions internal/app/service/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,12 @@ import (
"strconv"

"github.com/dictyBase/aphgrpc"
"github.com/dictyBase/go-genproto/dictybaseapis/api/jsonapi"
"github.com/dictyBase/arangomanager/query"
"github.com/dictyBase/go-genproto/dictybaseapis/content"
"github.com/dictyBase/modware-content/internal/message"
"github.com/dictyBase/modware-content/internal/model"
"github.com/dictyBase/modware-content/internal/repository"
"github.com/dictyBase/modware-content/internal/repository/arangodb"
"github.com/go-playground/validator/v10"
"github.com/golang/protobuf/ptypes/empty"
)
Expand Down Expand Up @@ -59,13 +60,6 @@ func NewContentService(srvP *Params) (*ContentService, error) {
}, nil
}

func (srv *ContentService) Healthz(
ctx context.Context,
rdr *jsonapi.HealthzIdRequest,
) (*empty.Empty, error) {
return &empty.Empty{}, nil
}

func (srv *ContentService) GetContentBySlug(
ctx context.Context,
rdr *content.ContentRequest,
Expand Down Expand Up @@ -130,7 +124,8 @@ func (srv *ContentService) buildContent(
UpdatedAt: aphgrpc.TimestampProto(mcont.UpdatedOn),
Content: mcont.Content,
},
}}
},
}
}

func (srv *ContentService) StoreContent(
Expand Down Expand Up @@ -187,3 +182,81 @@ func (srv *ContentService) DeleteContent(

return &empty.Empty{}, nil
}

func (srv *ContentService) ListContents(
ctx context.Context,
req *content.ListParameters,
) (*content.ContentCollection, error) {
limit := int64(10)
if req.Limit > 0 {
limit = req.Limit
}
astmt, err := filterStrToQuery(req.Filter)
if err != nil {
return nil, aphgrpc.HandleInvalidParamError(ctx, err)
}
cntModel, err := srv.repo.ListContents(req.Cursor, limit, astmt)
if err != nil {
if repository.IsContentListNotFound(err) {
return nil, aphgrpc.HandleNotFoundError(ctx, err)
}
return nil, aphgrpc.HandleGetError(ctx, err)
}
cntDataSlice := make([]*content.ContentCollection_Data, 0)
for _, cntD := range cntModel {
cntDataSlice = append(cntDataSlice, &content.ContentCollection_Data{
Id: cntD.Key,
Attributes: &content.ContentAttributes{
Name: cntD.Name,
Namespace: cntD.Namespace,
Slug: cntD.Slug,
CreatedBy: cntD.CreatedBy,
UpdatedBy: cntD.UpdatedBy,
Content: cntD.Content,
CreatedAt: aphgrpc.TimestampProto(cntD.CreatedOn),
UpdatedAt: aphgrpc.TimestampProto(cntD.UpdatedOn),
},
})
}

cnt := &content.ContentCollection{}
if len(cntDataSlice) == int(limit)+1 {
cnt.Data = cntDataSlice[:len(cntDataSlice)-1]
cnt.Meta = &content.Meta{
Limit: limit,
NextCursor: cntModel[len(cntModel)-1].CreatedOn.UnixMilli(),
}
return cnt, nil
}
cnt.Data = cntDataSlice
cnt.Meta = &content.Meta{Limit: req.Limit}
Comment on lines +231 to +232
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fix Meta assignment for consistency.

Ensure that the Meta limit is consistently assigned, even when the data slice is equal to the limit.

-  cnt.Meta = &content.Meta{Limit: req.Limit}
+  cnt.Meta = &content.Meta{Limit: limit}

Committable suggestion was skipped due to low confidence.

return cnt, nil
}

func filterStrToQuery(filter string) (string, error) {
var empty string
if len(filter) == 0 {
return empty, nil
}
parsedStr, err := query.ParseFilterString(filter)
if err != nil {
return empty, fmt.Errorf(
"error in parsing filter string '%s': %w",
filter,
err,
)
}
queryStr, err := query.GenQualifiedAQLFilterStatement(
arangodb.FilterMap(),
parsedStr,
)
if err != nil {
return empty, fmt.Errorf(
"error in generating AQL statement for filter '%s': %w",
filter,
err,
)
}

return queryStr, nil
}
Loading
Loading