diff --git a/internal/file/api.go b/internal/file/api.go index 4834965..aceb9eb 100644 --- a/internal/file/api.go +++ b/internal/file/api.go @@ -368,8 +368,13 @@ func (r resource) comments(c echo.Context) error { if err != nil { return err } - count := file.CommentsCount - pages := pagination.NewFromRequest(c.Request(), *count) + + count := 0 + if file.CommentsCount != nil { + count = *file.CommentsCount + } + + pages := pagination.NewFromRequest(c.Request(), count) comments, err := r.service.Comments( ctx, c.Param("sha256"), pages.Offset(), pages.Limit()) if err != nil { diff --git a/internal/file/repository.go b/internal/file/repository.go index cd2334a..c4f70ca 100644 --- a/internal/file/repository.go +++ b/internal/file/repository.go @@ -150,7 +150,7 @@ func (r repository) Query(ctx context.Context, offset, limit int, fields []strin for _, u := range res.([]interface{}) { file := entity.File{} b, _ := json.Marshal(u) - _ = json.Unmarshal(b, &file) + _ = json.Unmarshal(b, &file) files = append(files, file) } return files, nil @@ -204,6 +204,10 @@ func (r repository) Comments(ctx context.Context, id string, offset, if err != nil { return nil, err } + + if len(results.([]interface{})) == 0 { + return []interface{}{}, nil + } return results.([]interface{}), nil } diff --git a/internal/user/repository.go b/internal/user/repository.go index 308161f..0c70d70 100644 --- a/internal/user/repository.go +++ b/internal/user/repository.go @@ -244,6 +244,9 @@ func (r repository) Likes(ctx context.Context, id string, offset, if err != nil { return nil, err } + if len(results.([]interface{})) == 0 { + return []interface{}{}, nil + } return results.([]interface{}), nil } @@ -274,6 +277,9 @@ func (r repository) Followers(ctx context.Context, id string, offset, if err != nil { return nil, err } + if len(results.([]interface{})) == 0 { + return []interface{}{}, nil + } return results.([]interface{}), nil } @@ -304,6 +310,9 @@ func (r repository) Following(ctx context.Context, id string, offset, if err != nil { return nil, err } + if len(results.([]interface{})) == 0 { + return []interface{}{}, nil + } return results.([]interface{}), nil } @@ -333,6 +342,9 @@ func (r repository) Submissions(ctx context.Context, id string, offset, if err != nil { return nil, err } + if len(results.([]interface{})) == 0 { + return []interface{}{}, nil + } return results.([]interface{}), nil } @@ -363,6 +375,9 @@ func (r repository) Comments(ctx context.Context, id string, offset, if err != nil { return nil, err } + if len(results.([]interface{})) == 0 { + return []interface{}{}, nil + } return results.([]interface{}), nil }