Skip to content

Commit

Permalink
fix: don't use a pointer for comments_count to omit 0 values
Browse files Browse the repository at this point in the history
  • Loading branch information
ayoubfaouzi committed Oct 11, 2024
1 parent e82aa96 commit 86e9aaa
Show file tree
Hide file tree
Showing 6 changed files with 8 additions and 18 deletions.
1 change: 0 additions & 1 deletion internal/behavior/repostitory.go
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,6 @@ func (r repository) Events(ctx context.Context, id string, offset,
}

i++

}
}

Expand Down
6 changes: 1 addition & 5 deletions internal/comment/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -97,11 +97,7 @@ func (s service) Create(ctx context.Context, req CreateCommentRequest) (
}

// Update comments count on file object.
commentsCount := 0
if file.CommentsCount != nil {
commentsCount = *file.CommentsCount + 1
}
err = s.fileSvc.Patch(ctx, req.SHA256, "comments_count", commentsCount)
err = s.fileSvc.Patch(ctx, req.SHA256, "comments_count", file.CommentsCount+1)
if err != nil {
return Comment{}, err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/entity/file.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ type File struct {
Histogram []int `json:"histogram,omitempty"`
ByteEntropy []int `json:"byte_entropy,omitempty"`
Ml map[string]interface{} `json:"ml,omitempty"`
CommentsCount *int `json:"comments_count,omitempty"`
CommentsCount int `json:"comments_count"`
Format string `json:"file_format,omitempty"`
Extension string `json:"file_extension,omitempty"`
DefaultBhvReport interface{} `json:"default_behavior_report,omitempty"`
Expand Down
11 changes: 3 additions & 8 deletions internal/file/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -378,12 +378,7 @@ func (r resource) comments(c echo.Context) error {
return err
}

commentsCount := 0
if file.CommentsCount != nil {
commentsCount = *file.CommentsCount
}

pages := pagination.NewFromRequest(c.Request(), commentsCount)
pages := pagination.NewFromRequest(c.Request(), file.CommentsCount)
comments, err := r.service.Comments(
ctx, c.Param("sha256"), pages.Offset(), pages.Limit())
if err != nil {
Expand Down Expand Up @@ -461,7 +456,7 @@ func (r resource) rescan(c echo.Context) error {
}
}

err := r.service.Rescan(ctx, c.Param("sha256"), scanCfg)
err := r.service.ReScan(ctx, c.Param("sha256"), scanCfg)
if err != nil {
return err
}
Expand Down Expand Up @@ -538,7 +533,7 @@ func (r resource) generatePresignedURL(c echo.Context) error {
// @Security Bearer || {}
func (r resource) metaUI(c echo.Context) error {
ctx := c.Request().Context()
fileSummary, err := r.service.Summary(ctx, c.Param("sha256"))
fileSummary, err := r.service.MetaUI(ctx, c.Param("sha256"))
if err != nil {
return err
}
Expand Down
2 changes: 1 addition & 1 deletion internal/file/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -260,7 +260,7 @@ func (r repository) MetaUI(ctx context.Context, id string) (
params["loggedInUser"] = "_none_"
}

query = r.db.N1QLQuery[dbcontext.FileSummary]
query = r.db.N1QLQuery[dbcontext.MetaUI]
err := r.db.Query(ctx, query, params, &results)
if err != nil {
return nil, err
Expand Down
4 changes: 2 additions & 2 deletions internal/file/service.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ type Service interface {
Summary(ctx context.Context, id string) (interface{}, error)
Like(ctx context.Context, id string) error
Unlike(ctx context.Context, id string) error
Rescan(ctx context.Context, id string, input FileScanRequest) error
ReScan(ctx context.Context, id string, input FileScanRequest) error
Comments(ctx context.Context, id string, offset, limit int) (
[]interface{}, error)
CountStrings(ctx context.Context, id string, queryString string) (int, error)
Expand Down Expand Up @@ -411,7 +411,7 @@ func (s service) Unlike(ctx context.Context, sha256 string) error {
return s.userSvc.Unlike(ctx, user.ID(), sha256)
}

func (s service) Rescan(ctx context.Context, sha256 string, input FileScanRequest) error {
func (s service) ReScan(ctx context.Context, sha256 string, input FileScanRequest) error {

// Serialize the msg to send to the orchestrator.
msg, err := json.Marshal(FileScanCfg{SHA256: sha256, FileScanRequest: input})
Expand Down

0 comments on commit 86e9aaa

Please sign in to comment.