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 5 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
52 changes: 52 additions & 0 deletions internal/repository/arangodb/arangodb.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,3 +216,55 @@ func (arp *arangorepository) EditContent(
func (arp *arangorepository) Dbh() *manager.Database {
return arp.database
}

func (arp *arangorepository) ListContents(
cursor int64,
limit int64,
filter string,
) ([]*model.ContentDoc, error) {
bindVars := map[string]interface{}{
"@content_collection": arp.content.Name(),
"limit": limit + 1,
}
if cursor != 0 {
bindVars["cursor"] = cursor
}
stmt := getListContentStatement(filter, cursor)
res, err := arp.database.SearchRows(stmt, bindVars)
if err != nil {
return nil, fmt.Errorf("error in searching rows %s", err)
}
if res.IsEmpty() {
return nil, &repository.ContentListNotFoundError{}
}

contentModel := make([]*model.ContentDoc, 0)
for res.Scan() {
m := &model.ContentDoc{}
if err := res.Read(m); err != nil {
return nil, fmt.Errorf(
"error in reading data to structure %s",
err,
)
}
contentModel = append(contentModel, m)
}

return contentModel, nil
}

func getListContentStatement(filter string, cursor int64) string {
var stmt string
switch {
case len(filter) > 0 && cursor == 0:
stmt = fmt.Sprintf(ContentListFilter, filter)
case len(filter) > 0 && cursor != 0:
stmt = fmt.Sprintf(ContentListFilterWithCursor, filter)
case len(filter) == 0 && cursor == 0:
stmt = ContentList
case len(filter) == 0 && cursor != 0:
stmt = ContentListWithCursor
}

return stmt
}
38 changes: 38 additions & 0 deletions internal/repository/arangodb/arangodb_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ package arangodb

import (
"encoding/json"
"fmt"
"regexp"
"strconv"
"testing"
"time"
Expand Down Expand Up @@ -87,6 +89,42 @@ func TestGetContentBySlug(t *testing.T) {
testContentProperties(assert, sct, nct)
}

func TestListContents(t *testing.T) {
t.Parallel()
assert, repo := setUp(t)
defer tearDown(repo)
for i := 0; i < 19; i++ {
_, err := repo.AddContent(
testutils.NewStoreContent(fmt.Sprintf("gallery-%d", i), "genome"),
)
assert.NoErrorf(
err,
"expect no error from creating gallery genome content %s",
err,
)
}
clist, err := repo.ListContents(0, 4, "")
assert.NoError(err, "expect no error from listing content")
assert.Len(clist, 5, "should have 5 content entries")
nrxp := regexp.MustCompile(`gallery-\d+`)
for _, cnt := range clist {
assert.Equal(
cnt.Namespace,
"genome",
"should match the genome namespace",
)
assert.Regexp(nrxp, cnt.Name, "should match gallery names")
}
assert.True(
clist[0].CreatedOn.After(clist[1].CreatedOn),
"first gallery record should be created after the second one",
)
assert.False(
clist[2].CreatedOn.After(clist[1].CreatedOn),
"third gallery record should not be created after the second one",
)
}

func TestGetContent(t *testing.T) {
t.Parallel()
assert, repo := setUp(t)
Expand Down
29 changes: 28 additions & 1 deletion internal/repository/arangodb/statement.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,34 @@ const (
LIMIT 1
RETURN cnt
`

ContentList = `
FOR cnt IN @@content_collection
SORT cnt.created_on DESC
LIMIT @limit
RETURN cnt
`
ContentListWithCursor = `
FOR cnt IN @@content_collection
FILTER cnt.created_on <= DATE_ISO8601(@cursor)
SORT cnt.created_on DESC
LIMIT @limit
RETURN cnt
`
ContentListFilter = `
FOR cnt IN @@content_collection
%s
SORT cnt.created_on DESC
LIMIT @limit
RETURN cnt
`
ContentListFilterWithCursor = `
FOR cnt IN @@content_collection
FILTER cnt.created_on <= DATE_ISO8601(@cursor)
%s
SORT cnt.created_on DESC
LIMIT @limit
RETURN cnt
`
ContentInsert = `
INSERT {
name: @name,
Expand Down
19 changes: 19 additions & 0 deletions internal/repository/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,5 +15,24 @@ type ContentRepository interface {
cnt *content.ExistingContentAttributes,
) (*model.ContentDoc, error)
DeleteContent(cid int64) error
ListContents(
cursor int64,
limit int64,
filter string,
) ([]*model.ContentDoc, error)
Dbh() *manager.Database
}

type ContentListNotFoundError struct{}

func (al *ContentListNotFoundError) Error() string {
return "annotation list not found"
}

func IsContentListNotFound(err error) bool {
if _, ok := err.(*ContentListNotFoundError); ok {
return true
}

return false
}
Loading