Skip to content

Commit

Permalink
Merge pull request #32 from ankush-003/pr_branch
Browse files Browse the repository at this point in the history
Some updates
  • Loading branch information
ankush-003 authored May 7, 2024
2 parents 0baff43 + 7441aba commit d9fb4f3
Show file tree
Hide file tree
Showing 11 changed files with 172 additions and 701 deletions.
636 changes: 0 additions & 636 deletions dashboard/package-lock.json

Large diffs are not rendered by default.

5 changes: 3 additions & 2 deletions middleware/docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@ services:
networks:
- test
environment:
- HOST = "rest-server"
- HOST=rest-server

rest-server:
build: ./rest_server
container_name: rest-server
networks:
- test
ports:
- "8000:8000"
- "8000:8000"

# redis:
# image: redis/redis-stack
Expand Down
25 changes: 13 additions & 12 deletions middleware/rest_server/controllers/userController.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package controllers
import (
"Rest_server/database"
helper "Rest_server/helpers"

// middleware "Rest_server/middleware"
"Rest_server/models"
"context"
Expand Down Expand Up @@ -223,23 +224,23 @@ func GetUsers() gin.HandlerFunc {
page = 1
}

startIndex := (page - 1) * recordPerPage
startIndex, err = strconv.Atoi(c.Query("startIndex"))
// startIndex := (page - 1) * recordPerPage
startIndex, _ := strconv.Atoi(c.Query("startIndex"))

matchStage := bson.D{{"$match", bson.D{{}}}}
groupStage := bson.D{{"$group", bson.D{
{"_id", bson.D{{"_id", "null"}}},
{"total_count", bson.D{{"$sum", 1}}},
{"data", bson.D{{"$push", "$$ROOT"}}}}}}
matchStage := bson.D{{Key: "$match", Value: bson.D{{}}}}
groupStage := bson.D{{Key: "$group", Value: bson.D{
{Key: "_id", Value: bson.D{{Key: "_id", Value: "null"}}},
{Key: "total_count", Value: bson.D{{Key: "$sum", Value: 1}}},
{Key: "data", Value: bson.D{{Key: "$push", Value: "$$ROOT"}}}}}}
projectStage := bson.D{
{"$project", bson.D{
{"_id", 0},
{"total_count", 1},
{"user_items", bson.D{{"$slice", []interface{}{"$data", startIndex, recordPerPage}}}}}}}

{Key: "$project", Value: bson.D{
{Key: "_id", Value: 0},
{Key: "total_count", Value: 1},
{Key: "user_items", Value: bson.D{{Key: "$slice", Value: []interface{}{"$data", startIndex, recordPerPage}}}}}}}
result, err := userCollection.Aggregate(ctx, mongo.Pipeline{
matchStage, groupStage, projectStage})
defer cancel()

if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": "error occured while listing user items"})
}
Expand Down
56 changes: 39 additions & 17 deletions middleware/rest_server/go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,47 +3,69 @@ module Rest_server
go 1.22.1

require (
github.com/ankush-003/alerts-simulation-and-remediation/middleware/sim v0.0.0-20240505052255-7f4005cc1089 // indirect
github.com/bytedance/sonic v1.11.3 // indirect
github.com/ankush-003/alerts-simulation-and-remediation/middleware/sim v0.0.0-20240505055622-0baff43d0113
github.com/dgrijalva/jwt-go v3.2.0+incompatible
github.com/gin-gonic/gin v1.10.0
github.com/go-playground/validator/v10 v10.20.0
github.com/google/uuid v1.6.0
github.com/joho/godotenv v1.5.1
go.mongodb.org/mongo-driver v1.15.0
golang.org/x/crypto v0.23.0
)

require (
github.com/IBM/sarama v1.43.1 // indirect
github.com/bytedance/sonic v1.11.6 // indirect
github.com/bytedance/sonic/loader v0.1.1 // indirect
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/chenzhuoyu/base64x v0.0.0-20230717121745-296ad89f973d // indirect
github.com/chenzhuoyu/iasm v0.9.1 // indirect
github.com/dgrijalva/jwt-go v3.2.0+incompatible // indirect
github.com/cloudwego/base64x v0.1.4 // indirect
github.com/cloudwego/iasm v0.2.0 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect
github.com/eapache/go-resiliency v1.6.0 // indirect
github.com/eapache/go-xerial-snappy v0.0.0-20230731223053-c322873962e3 // indirect
github.com/eapache/queue v1.1.0 // indirect
github.com/gabriel-vasile/mimetype v1.4.3 // indirect
github.com/gin-contrib/cors v1.7.0 // indirect
github.com/gin-contrib/cors v1.7.2 // indirect
github.com/gin-contrib/sse v0.1.0 // indirect
github.com/gin-gonic/gin v1.9.1 // indirect
github.com/go-playground/locales v0.14.1 // indirect
github.com/go-playground/universal-translator v0.18.1 // indirect
github.com/go-playground/validator/v10 v10.19.0 // indirect
github.com/goccy/go-json v0.10.2 // indirect
github.com/golang/snappy v0.0.4 // indirect
github.com/google/uuid v1.6.0 // indirect
github.com/joho/godotenv v1.5.1 // indirect
github.com/hashicorp/errwrap v1.1.0 // indirect
github.com/hashicorp/go-multierror v1.1.1 // indirect
github.com/hashicorp/go-uuid v1.0.3 // indirect
github.com/jcmturner/aescts/v2 v2.0.0 // indirect
github.com/jcmturner/dnsutils/v2 v2.0.0 // indirect
github.com/jcmturner/gofork v1.7.6 // indirect
github.com/jcmturner/gokrb5/v8 v8.4.4 // indirect
github.com/jcmturner/rpc/v2 v2.0.3 // indirect
github.com/json-iterator/go v1.1.12 // indirect
github.com/klauspost/compress v1.17.8 // indirect
github.com/klauspost/cpuid/v2 v2.2.7 // indirect
github.com/knz/go-libedit v1.10.1 // indirect
github.com/leodido/go-urn v1.4.0 // indirect
github.com/mattn/go-isatty v0.0.20 // indirect
github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
github.com/modern-go/reflect2 v1.0.2 // indirect
github.com/montanaflynn/stats v0.7.1 // indirect
github.com/pelletier/go-toml/v2 v2.2.0 // indirect
github.com/pelletier/go-toml/v2 v2.2.2 // indirect
github.com/pierrec/lz4/v4 v4.1.21 // indirect
github.com/rcrowley/go-metrics v0.0.0-20201227073835-cf1acfcdf475 // indirect
github.com/redis/go-redis/v9 v9.5.1 // indirect
github.com/twitchyliquid64/golang-asm v0.15.1 // indirect
github.com/ugorji/go/codec v1.2.12 // indirect
github.com/xdg-go/pbkdf2 v1.0.0 // indirect
github.com/xdg-go/scram v1.1.2 // indirect
github.com/xdg-go/stringprep v1.0.4 // indirect
github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect
go.mongodb.org/mongo-driver v1.15.0 // indirect
golang.org/x/arch v0.7.0 // indirect
golang.org/x/crypto v0.22.0 // indirect
golang.org/x/net v0.24.0 // indirect
github.com/youmark/pkcs8 v0.0.0-20240424034433-3c2c7870ae76 // indirect
golang.org/x/arch v0.8.0 // indirect
golang.org/x/net v0.25.0 // indirect
golang.org/x/sync v0.7.0 // indirect
golang.org/x/sys v0.19.0 // indirect
golang.org/x/text v0.14.0 // indirect
google.golang.org/protobuf v1.33.0 // indirect
golang.org/x/sys v0.20.0 // indirect
golang.org/x/text v0.15.0 // indirect
google.golang.org/protobuf v1.34.1 // indirect
gopkg.in/yaml.v3 v3.0.1 // indirect
)
Loading

0 comments on commit d9fb4f3

Please sign in to comment.