From 8e1af99e8457fc71a41289b7a237b3b7a499cf06 Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Fri, 15 Mar 2024 23:59:43 +0530 Subject: [PATCH 01/23] Enum Validator Added --- src/apis/data/trade-user-group/index.go | 4 +- src/apis/data/trade-user/index.go | 4 +- src/env/index.go | 4 +- .../base-enum-validator.interface.go | 10 ++ src/interfaces/base-symbol.enum.go | 30 ++-- src/interfaces/calculate-on-price.enum.go | 16 +- src/interfaces/calculate-symbol.enum.go | 19 ++- .../general-user-req-auth-status.enum.go | 18 +-- src/interfaces/order-entity.interface.go | 29 ++++ src/interfaces/order.enum.go | 139 ++++++++++++++++++ src/interfaces/user-roles.enum.go | 21 +-- 11 files changed, 231 insertions(+), 63 deletions(-) create mode 100644 src/interfaces/base-enum-validator.interface.go create mode 100644 src/interfaces/order-entity.interface.go create mode 100644 src/interfaces/order.enum.go diff --git a/src/apis/data/trade-user-group/index.go b/src/apis/data/trade-user-group/index.go index 41c3730..885533b 100644 --- a/src/apis/data/trade-user-group/index.go +++ b/src/apis/data/trade-user-group/index.go @@ -11,8 +11,8 @@ func AddTradeUserGroupAPIs(router fiber.Router) { { adminGroup := router.Group("/admin", middleware.AllowOnlyBigAdmins.Validate) adminGroup.Put("/createNewTradeGroup", apiCreateNewTradeGroup) - adminGroup.Post("/updateTradeGroup", apiUpdateTradeUserGroup) - adminGroup.Post("/updateTradeGroupProductMap", apiUpdateTradeUserGroupMap) + adminGroup.Patch("/updateTradeGroup", apiUpdateTradeUserGroup) + adminGroup.Patch("/updateTradeGroupProductMap", apiUpdateTradeUserGroupMap) } adminAndTradeGroup := router.Use(middleware.AllowAllAdminsAndTradeUsers.Validate) adminAndTradeGroup.Get("/getTradeGroupDetailsByID", apiGetTradeGroupDetailsById) diff --git a/src/apis/data/trade-user/index.go b/src/apis/data/trade-user/index.go index 0b0ea37..238af0d 100644 --- a/src/apis/data/trade-user/index.go +++ b/src/apis/data/trade-user/index.go @@ -8,6 +8,6 @@ import ( func AddTradeUserAPIs(router fiber.Router) { adminGroup := router.Use(middleware.AllowOnlyBigAdmins.Validate) adminGroup.Get("/getTradeUser", apiGetTradeUserDetails) - adminGroup.Post("/updateTradeUserDetails", apiUpdateTradeUserDetails) - adminGroup.Post("/updateTradeUserStatus", apiChangeTradeUserStatus) + adminGroup.Patch("/updateTradeUserDetails", apiUpdateTradeUserDetails) + adminGroup.Patch("/updateTradeUserStatus", apiChangeTradeUserStatus) } diff --git a/src/env/index.go b/src/env/index.go index 8fbc332..c5557aa 100644 --- a/src/env/index.go +++ b/src/env/index.go @@ -51,7 +51,7 @@ func init() { } errs := validator.Validator.Validate(Env) if len(errs) > 0 { - println(err) - panic(err) + println(errs) + panic(errs[0]) } } diff --git a/src/interfaces/base-enum-validator.interface.go b/src/interfaces/base-enum-validator.interface.go new file mode 100644 index 0000000..7fca385 --- /dev/null +++ b/src/interfaces/base-enum-validator.interface.go @@ -0,0 +1,10 @@ +package interfaces + +type EnumValidatorBase struct { + Data map[string]interface{} +} + +func (v *EnumValidatorBase) Validate(value string) bool { + _, ok := v.Data[value] + return ok +} diff --git a/src/interfaces/base-symbol.enum.go b/src/interfaces/base-symbol.enum.go index 0c35fb6..4763d0d 100644 --- a/src/interfaces/base-symbol.enum.go +++ b/src/interfaces/base-symbol.enum.go @@ -17,28 +17,24 @@ const ( ) var ( - symbolEnumMap = map[string]SymbolsEnum{ - "GOLD": SYMBOL_GOLD, - "SILVER": SYMBOL_SILVER, - "GOLD_MCX": SYMBOL_GOLD_MCX, - "SILVER_MCX": SYMBOL_SILVER_MCX, - "GOLD_NEXT": SYMBOL_GOLD_NEXT, - "SILVER_NEXT": SYMBOL_SILVER_NEXT, - "GOLD_SPOT": SYMBOL_GOLD_SPOT, - "SILVER_SPOT": SYMBOL_SILVER_SPOT, - "INR": SYMBOL_INR, + symbolEnumMap = EnumValidatorBase{ + Data: map[string]interface{}{ + "GOLD": SYMBOL_GOLD, + "SILVER": SYMBOL_SILVER, + "GOLD_MCX": SYMBOL_GOLD_MCX, + "SILVER_MCX": SYMBOL_SILVER_MCX, + "GOLD_NEXT": SYMBOL_GOLD_NEXT, + "SILVER_NEXT": SYMBOL_SILVER_NEXT, + "GOLD_SPOT": SYMBOL_GOLD_SPOT, + "SILVER_SPOT": SYMBOL_SILVER_SPOT, + "INR": SYMBOL_INR, + }, } ) func init() { - validator.RegisterEnumValidatorFunc("SymbolsEnum", ValidateEnumSymbolsEnum) + validator.RegisterEnumValidatorFunc("SymbolsEnum", symbolEnumMap.Validate) } - -func ValidateEnumSymbolsEnum(value string) bool { - _, ok := symbolEnumMap[value] - return ok -} - func (s SymbolsEnum) String() string { switch s { case SYMBOL_GOLD: diff --git a/src/interfaces/calculate-on-price.enum.go b/src/interfaces/calculate-on-price.enum.go index e4532c2..40302a7 100644 --- a/src/interfaces/calculate-on-price.enum.go +++ b/src/interfaces/calculate-on-price.enum.go @@ -11,25 +11,23 @@ const ( ) var ( - calculateOnPriceTypeMap = map[string]CalculateOnPriceType{ - "BID_ASK": CALCULATE_ON_BID_ASK, - "BID": CALCULATE_ON_BID, - "ASK": CALCULATE_ON_ASK, + calculateOnPriceTypeMap = EnumValidatorBase{ + Data: map[string]interface{}{ + "BID_ASK": CALCULATE_ON_BID_ASK, + "ASK": CALCULATE_ON_ASK, + "BID": CALCULATE_ON_BID, + }, } ) func init() { - validator.RegisterEnumValidatorFunc("CalculateOnPriceType", ValidateEnumCalculateOnPriceType) + validator.RegisterEnumValidatorFunc("CalculateOnPriceType", calculateOnPriceTypeMap.Validate) } // ValidateEnumCalculateOnPriceType checks if the given value is a valid calculateOnPriceType. // // value: the value to be validated as a calculateOnPriceType. // Returns: true if the value is a valid calculateOnPriceType, false otherwise. -func ValidateEnumCalculateOnPriceType(value string) bool { - _, ok := calculateOnPriceTypeMap[value] - return ok -} func (s CalculateOnPriceType) String() string { switch s { diff --git a/src/interfaces/calculate-symbol.enum.go b/src/interfaces/calculate-symbol.enum.go index dd750ab..6692384 100644 --- a/src/interfaces/calculate-symbol.enum.go +++ b/src/interfaces/calculate-symbol.enum.go @@ -1,6 +1,8 @@ package interfaces -import "github.com/rpsoftech/bullion-server/src/validator" +import ( + "github.com/rpsoftech/bullion-server/src/validator" +) type BaseSymbolEnum string @@ -10,19 +12,16 @@ const ( ) var ( - baseSymbolEnumMap = map[string]BaseSymbolEnum{ - "GOLD": BASE_SYMBOL_GOLD, - "SILVER": BASE_SYMBOL_SILVER, + baseSymbolEnumMap = EnumValidatorBase{ + Data: map[string]interface{}{ + "GOLD": BASE_SYMBOL_GOLD, + "SILVER": BASE_SYMBOL_SILVER, + }, } ) func init() { - validator.RegisterEnumValidatorFunc("BaseSymbolEnum", ValidateBaseSymbolEnum) -} - -func ValidateBaseSymbolEnum(value string) bool { - _, ok := baseSymbolEnumMap[value] - return ok + validator.RegisterEnumValidatorFunc("BaseSymbolEnum", baseSymbolEnumMap.Validate) } func (s BaseSymbolEnum) String() string { diff --git a/src/interfaces/general-user-req-auth-status.enum.go b/src/interfaces/general-user-req-auth-status.enum.go index 9852833..6822137 100644 --- a/src/interfaces/general-user-req-auth-status.enum.go +++ b/src/interfaces/general-user-req-auth-status.enum.go @@ -11,22 +11,18 @@ const ( ) var ( - generalUserAuthStatusMap = map[string]GeneralUserAuthStatus{ - "Authorized": GENERAL_USER_AUTH_STATUS_AUTHORIZED, - "Requested": GENERAL_USER_AUTH_STATUS_REQUESTED, - "Rejected": GENERAL_USER_AUTH_STATUS_REJECTED, + generalUserAuthStatusMap = EnumValidatorBase{ + Data: map[string]interface{}{ + "Authorized": GENERAL_USER_AUTH_STATUS_AUTHORIZED, + "Requested": GENERAL_USER_AUTH_STATUS_REQUESTED, + "Rejected": GENERAL_USER_AUTH_STATUS_REJECTED, + }, } ) func init() { - validator.RegisterEnumValidatorFunc("GeneralUserAuthStatus", validateEnumGeneralUserAuthStatus) + validator.RegisterEnumValidatorFunc("GeneralUserAuthStatus", generalUserAuthStatusMap.Validate) } - -func validateEnumGeneralUserAuthStatus(value string) bool { - _, ok := generalUserAuthStatusMap[value] - return ok -} - func (s GeneralUserAuthStatus) String() string { switch s { case GENERAL_USER_AUTH_STATUS_AUTHORIZED: diff --git a/src/interfaces/order-entity.interface.go b/src/interfaces/order-entity.interface.go new file mode 100644 index 0000000..7c83543 --- /dev/null +++ b/src/interfaces/order-entity.interface.go @@ -0,0 +1,29 @@ +package interfaces + +type ( + OrderEntity struct { + *BaseEntity `bson:"inline"` + *OrderBase `bson:"inline"` + *LimitWatcherRequired `bson:"inline"` + *FromAdmin `bson:"inline,omitempty"` + } + + LimitWatcherRequired struct { + Price float64 `json:"price" bson:"price" validate:"required"` + ProductId string `json:"productId" bson:"productId" validate:"required,uuid"` + GroupId string `json:"groupId" bson:"groupId" validate:"required,uuid"` + ProductGroupMapId string `json:"productGroupMapId" bson:"productGroupMapId" validate:"required,uuid"` + } + + FromAdmin struct { + PlacedBy string `bson:"placedBy,omitempty" json:"placedBy,omitempty" validate:"uuid"` + AutoRate bool `bson:"autoRate,omitempty" json:"autoRate,omitempty" validate:"boolean"` + } + + OrderBase struct { + UserId string `bson:"userId" json:"userId" validate:"required,uuid"` + OrderType OrderType `bson:"orderType" json:"orderType" validate:"required,enum=OrderStatus"` + OrderStatus OrderStatus `bson:"orderStatus" json:"orderStatus" validate:"required,enum=OrderStatus"` + BuySell BuySell `bson:"buySell" json:"buySell" validate:"required,enum=BuySell"` + } +) diff --git a/src/interfaces/order.enum.go b/src/interfaces/order.enum.go new file mode 100644 index 0000000..c6cb389 --- /dev/null +++ b/src/interfaces/order.enum.go @@ -0,0 +1,139 @@ +package interfaces + +import "github.com/rpsoftech/bullion-server/src/validator" + +type ( + OrderStatus string + OrderType string + BuySell string +) + +const ( + Buy BuySell = "BUY" + Sell BuySell = "SELL" + + Market OrderType = "Market" + Limit OrderType = "Limit" + + OrderPlaced OrderStatus = "OrderPlaced" + LimitPlaced OrderStatus = "LimitPlaced" + LimitPassed OrderStatus = "LimitPassed" + LimitExpired OrderStatus = "LimitExpired" + LimitCanceled OrderStatus = "LimitCanceled" + LimitDeletedByAdmin OrderStatus = "LimitDeletedByAdmin" + OrderDelivered OrderStatus = "OrderDelivered" + OrderPartialDelivered OrderStatus = "OrderPartialDelivered" +) + +var ( + OrderStatusEnumValidator = EnumValidatorBase{ + Data: map[string]interface{}{ + "OrderPlaced": OrderPlaced, + "LimitPlaced": LimitPlaced, + "LimitPassed": LimitPassed, + "LimitExpired": LimitExpired, + "LimitCanceled": LimitCanceled, + "LimitDeletedByAdmin": LimitDeletedByAdmin, + "OrderDelivered": OrderDelivered, + "OrderPartialDelivered": OrderPartialDelivered, + }, + } + + OrderTypeEnumValidator = EnumValidatorBase{ + Data: map[string]interface{}{ + "Market": Market, + "Limit": Limit, + }, + } + + BuySellEnumValidator = EnumValidatorBase{ + Data: map[string]interface{}{ + "BUY": Buy, + "SELL": Sell, + }, + } +) + +func init() { + validator.RegisterEnumValidatorFunc("OrderStatus", OrderStatusEnumValidator.Validate) + validator.RegisterEnumValidatorFunc("OrderType", OrderTypeEnumValidator.Validate) + validator.RegisterEnumValidatorFunc("BuySell", BuySellEnumValidator.Validate) +} +func (s OrderStatus) String() string { + switch s { + case OrderPlaced: + return "OrderPlaced" + case LimitPlaced: + return "LimitPlaced" + case LimitPassed: + return "LimitPassed" + case LimitExpired: + return "LimitExpired" + case LimitCanceled: + return "LimitCanceled" + case LimitDeletedByAdmin: + return "LimitDeletedByAdmin" + case OrderDelivered: + return "OrderDelivered" + case OrderPartialDelivered: + return "OrderPartialDelivered" + } + return "unknown" +} + +func (s OrderStatus) IsValid() bool { + switch s { + case + OrderPlaced, + LimitPlaced, + LimitPassed, + LimitExpired, + LimitCanceled, + LimitDeletedByAdmin, + OrderDelivered, + OrderPartialDelivered: + return true + } + + return false +} + +func (s OrderType) String() string { + switch s { + case Market: + return "Market" + case Limit: + return "Limit" + } + return "unknown" +} + +func (s OrderType) IsValid() bool { + switch s { + case + Market, + Limit: + return true + } + return false +} + +func (s BuySell) String() string { + switch s { + case Buy: + return "BUY" + case Sell: + return "SELL" + } + return "unknown" +} + +func (s BuySell) IsValid() bool { + switch s { + case + Buy, + Sell: + return true + } + return false +} diff --git a/src/interfaces/user-roles.enum.go b/src/interfaces/user-roles.enum.go index d0c3408..92e08e7 100644 --- a/src/interfaces/user-roles.enum.go +++ b/src/interfaces/user-roles.enum.go @@ -14,23 +14,24 @@ const ( ) var ( - userRolesMap = map[string]UserRoles{ - "RATE_ADMIN": ROLE_RATE_ADMIN, - "SUPER_ADMIN": ROLE_SUPER_ADMIN, - "ADMIN": ROLE_ADMIN, - "GENERAL_USER": ROLE_GENERAL_USER, - "TRADE_USER": ROLE_TRADE_USER, - "GOD": ROLE_GOD, + userRolesMap = EnumValidatorBase{ + Data: map[string]interface{}{ + "RATE_ADMIN": ROLE_RATE_ADMIN, + "SUPER_ADMIN": ROLE_SUPER_ADMIN, + "ADMIN": ROLE_ADMIN, + "GENERAL_USER": ROLE_GENERAL_USER, + "TRADE_USER": ROLE_TRADE_USER, + "GOD": ROLE_GOD, + }, } ) func init() { - validator.RegisterEnumValidatorFunc("UserRoles", ValidateEnumUserRole) + validator.RegisterEnumValidatorFunc("UserRoles", userRolesMap.Validate) } func ValidateEnumUserRole(value string) bool { - _, ok := userRolesMap[value] - return ok + return userRolesMap.Validate(value) } func (s UserRoles) String() string { From 4c87b80bd14af6d33cc1e6cf405285343c8a571c Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Sat, 16 Mar 2024 00:48:50 +0530 Subject: [PATCH 02/23] Order Entity Completed --- src/interfaces/base-entity.go | 8 +- src/interfaces/error-code.enum.go | 2 + src/interfaces/order-entity.interface.go | 114 +++++++++++++++++++++-- 3 files changed, 112 insertions(+), 12 deletions(-) diff --git a/src/interfaces/base-entity.go b/src/interfaces/base-entity.go index 587f415..37da61e 100644 --- a/src/interfaces/base-entity.go +++ b/src/interfaces/base-entity.go @@ -32,17 +32,17 @@ type BaseEntity struct { // return json.Marshal(base) // } -func (b *BaseEntity) AddTimeStamps() (r *BaseEntity) { +func (b *BaseEntity) AddTimeStamps() *BaseEntity { b.CreatedAtExported = b.CreatedAt b.ModifiedAtExported = b.ModifiedAt return b } -func (b *BaseEntity) RestoreTimeStamp() (r *BaseEntity) { +func (b *BaseEntity) RestoreTimeStamp() *BaseEntity { b.CreatedAt = b.CreatedAtExported b.ModifiedAt = b.ModifiedAtExported return b } -func (b *BaseEntity) createNewId() (r *BaseEntity) { +func (b *BaseEntity) createNewId() *BaseEntity { id := uuid.New().String() b.ID = id b.CreatedAt = time.Now() @@ -50,7 +50,7 @@ func (b *BaseEntity) createNewId() (r *BaseEntity) { return b } -func (b *BaseEntity) Updated() (r *BaseEntity) { +func (b *BaseEntity) Updated() *BaseEntity { b.ModifiedAt = time.Now() return b } diff --git a/src/interfaces/error-code.enum.go b/src/interfaces/error-code.enum.go index af33e89..e3c7e63 100644 --- a/src/interfaces/error-code.enum.go +++ b/src/interfaces/error-code.enum.go @@ -33,4 +33,6 @@ const ( ERROR_OTP_REQ_NOT_FOUND = 228 ERROR_TOO_MANY_ATTEMPTS = 229 ERROR_WHILE_FETCHING_MESSAGE_TEMPLATE = 230 + ERROR_INVALID_ORDER_STATUS_FOR_DELIVERY = 231 + ERROR_INVALID_WEIGHT_FOR_DELIVERY = 232 ) diff --git a/src/interfaces/order-entity.interface.go b/src/interfaces/order-entity.interface.go index 7c83543..288b529 100644 --- a/src/interfaces/order-entity.interface.go +++ b/src/interfaces/order-entity.interface.go @@ -1,18 +1,34 @@ package interfaces +import ( + "net/http" + "slices" + "time" +) + type ( OrderEntity struct { *BaseEntity `bson:"inline"` *OrderBase `bson:"inline"` *LimitWatcherRequired `bson:"inline"` - *FromAdmin `bson:"inline,omitempty"` + *AfterSuccessOrder `bson:"inline,omitempty"` + Identity *Identity `bson:"inline"` + FromAdmin *FromAdmin `bson:"inline,omitempty"` + DeliveryData *[]DeliveryData `bson:"inline,omitempty"` + } + OrderBase struct { + OrderType OrderType `bson:"orderType" json:"orderType" validate:"required,enum=OrderStatus"` + OrderStatus OrderStatus `bson:"orderStatus" json:"orderStatus" validate:"required,enum=OrderStatus"` + BuySell BuySell `bson:"buySell" json:"buySell" validate:"required,enum=BuySell"` + ProductName string `bson:"productName" json:"productName" validate:"required,min=3,max=100"` } - LimitWatcherRequired struct { - Price float64 `json:"price" bson:"price" validate:"required"` ProductId string `json:"productId" bson:"productId" validate:"required,uuid"` GroupId string `json:"groupId" bson:"groupId" validate:"required,uuid"` ProductGroupMapId string `json:"productGroupMapId" bson:"productGroupMapId" validate:"required,uuid"` + Volume float64 `json:"volume" bson:"volume" validate:"required"` + Weight int `json:"weight" bson:"weight" validate:"required"` + Price float64 `json:"price" bson:"price" validate:"required"` } FromAdmin struct { @@ -20,10 +36,92 @@ type ( AutoRate bool `bson:"autoRate,omitempty" json:"autoRate,omitempty" validate:"boolean"` } - OrderBase struct { - UserId string `bson:"userId" json:"userId" validate:"required,uuid"` - OrderType OrderType `bson:"orderType" json:"orderType" validate:"required,enum=OrderStatus"` - OrderStatus OrderStatus `bson:"orderStatus" json:"orderStatus" validate:"required,enum=OrderStatus"` - BuySell BuySell `bson:"buySell" json:"buySell" validate:"required,enum=BuySell"` + AfterSuccessOrder struct { + CalcSnapShot *CalcSnapshotStruct `json:"calcSnapShot" bson:"calcSnapShot" validate:"required"` + CalcSnapShotId string `json:"calcSnapShotId" bson:"calcSnapShotId" validate:"required,uuid"` + PgmSnapShot *GroupPremiumBase `json:"pgmSnapShot" bson:"pgmSnapShot" validate:"required"` + McxPrice float64 `json:"mcxPrice" bson:"mcxPrice" validate:"required"` + ExecutedOn time.Time `json:"executedOn" bson:"executedOn" validate:"required"` + McxOrderJSON interface{} `json:"mcxOrder,omitempty" bson:"mcxOrder,omitempty"` + } + + Identity struct { + UserId string `bson:"userId" json:"userId" validate:"required,uuid"` + MachineId string `bson:"machineId,omitempty" json:"machineId,omitempty" validate:"required"` + MachineName string `bson:"machineName,omitempty" json:"machineName,omitempty" validate:"required,min=3,max=100"` + IpAddress string `bson:"ipAddress" json:"ipAddress"` + } + + DeliveryData struct { + Weight int `bson:"weight" json:"weight" validate:"required"` + PendingWeight int `bson:"pendingWeight" json:"pendingWeight" validate:"required"` + DeliveredOn time.Time `bson:"deliveredOn" json:"deliveredOn" validate:"required"` } ) + +var AvailableForDelivery = []OrderStatus{OrderPlaced, LimitPassed, OrderPartialDelivered} + +func (e *OrderEntity) DeliverWeight(weight int) (*OrderEntity, error) { + if !slices.Contains(AvailableForDelivery, e.OrderStatus) { + return nil, &RequestError{ + StatusCode: http.StatusBadRequest, + Code: ERROR_INVALID_ORDER_STATUS_FOR_DELIVERY, + Message: "Cannot deliver weight. Order status is not available for delivery", + Name: "OrderStatusNotAvailableForDelivery", + } + } + pendingWeight := e.Weight + if e.DeliveryData != nil { + for _, dataD := range *e.DeliveryData { + pendingWeight = pendingWeight - dataD.Weight + } + } else { + e.DeliveryData = &[]DeliveryData{} + } + + if weight > pendingWeight { + return nil, &RequestError{ + StatusCode: http.StatusBadRequest, + Code: ERROR_INVALID_WEIGHT_FOR_DELIVERY, + Message: "Cannot deliver weight. Weight is not available for delivery", + Name: "InvalidWeightForDelivery", + } + } + + *e.DeliveryData = append(*e.DeliveryData, DeliveryData{ + Weight: weight, + PendingWeight: pendingWeight - weight, + DeliveredOn: time.Now(), + }) + pendingWeight = pendingWeight - weight + e.OrderStatus = OrderPartialDelivered + + if pendingWeight == 0 { + e.OrderStatus = OrderDelivered + } + + return e, nil +} + +func (e *OrderEntity) LimitPassedOrOrderPlaced(mcxPrice float64, calcSnapShot *CalcSnapshotStruct, calcSnapShotId string, pgmSnapShot *GroupPremiumBase, mcxOrderJSON interface{}) *OrderEntity { + e.AfterSuccessOrder = &AfterSuccessOrder{ + CalcSnapShot: calcSnapShot, + CalcSnapShotId: calcSnapShotId, + PgmSnapShot: pgmSnapShot, + McxPrice: mcxPrice, + ExecutedOn: time.Now(), + McxOrderJSON: mcxOrderJSON, + } + return e +} + +func CreateNewOrderEntity(base *OrderBase, limitWatch *LimitWatcherRequired, identity *Identity) *OrderEntity { + b := &OrderEntity{ + BaseEntity: &BaseEntity{}, + OrderBase: base, + LimitWatcherRequired: limitWatch, + Identity: identity, + } + b.createNewId() + return b +} From 413fafd7d297058b4b6d25dc1cd002a9edc18e9e Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Sat, 16 Mar 2024 01:06:26 +0530 Subject: [PATCH 03/23] Order Events Added --- src/events/order.events.go | 53 +++++++++++++++++++ src/interfaces/bullion-site-info.interface.go | 2 +- src/interfaces/error-code.enum.go | 1 + src/interfaces/general-user-req.entity.go | 2 +- src/interfaces/general-users.entity.go | 2 +- src/interfaces/order-entity.interface.go | 1 + src/interfaces/product-entity.interface.go | 2 +- src/interfaces/trade-user.entity.go | 38 +++++++++++-- 8 files changed, 92 insertions(+), 9 deletions(-) create mode 100644 src/events/order.events.go diff --git a/src/events/order.events.go b/src/events/order.events.go new file mode 100644 index 0000000..e5f1828 --- /dev/null +++ b/src/events/order.events.go @@ -0,0 +1,53 @@ +package events + +import ( + "github.com/rpsoftech/bullion-server/src/interfaces" +) + +type OrderEvent struct { + *BaseEvent `bson:"inline"` +} + +func (base *OrderEvent) Add() *OrderEvent { + base.ParentNames = []string{base.EventName, "OrderEvent"} + base.BaseEvent.CreateBaseEvent() + return base +} + +func orderStatusUpdatedEvent(entity *interfaces.OrderEntity, adminId string, eventName string) *BaseEvent { + event := &OrderEvent{ + BaseEvent: &BaseEvent{ + BullionId: entity.BullionId, + KeyId: entity.ID, + AdminId: adminId, + Payload: entity, + EventName: eventName, + }, + } + event.Add() + return event.BaseEvent +} + +func OrderPlacedEvent(entity *interfaces.OrderEntity, adminId string) *BaseEvent { + return orderStatusUpdatedEvent(entity, adminId, "OrderPlacedEvent") +} + +func LimitPlacedEvent(entity *interfaces.OrderEntity, adminId string) *BaseEvent { + return orderStatusUpdatedEvent(entity, adminId, "LimitPlacedEvent") +} + +func LimitDeletedEvent(entity *interfaces.OrderEntity, adminId string) *BaseEvent { + return orderStatusUpdatedEvent(entity, adminId, "LimitDeletedEvent") +} + +func LimitPassedEvent(entity *interfaces.OrderEntity, adminId string) *BaseEvent { + return orderStatusUpdatedEvent(entity, adminId, "LimitPassedEvent") +} + +func LimitCanceledEvent(entity *interfaces.OrderEntity, adminId string) *BaseEvent { + return orderStatusUpdatedEvent(entity, adminId, "LimitCanceledEvent") +} + +func OrderDeliveredEvent(entity *interfaces.OrderEntity, adminId string) *BaseEvent { + return orderStatusUpdatedEvent(entity, adminId, "OrderDeliveredEvent") +} diff --git a/src/interfaces/bullion-site-info.interface.go b/src/interfaces/bullion-site-info.interface.go index 421604e..a3e601b 100644 --- a/src/interfaces/bullion-site-info.interface.go +++ b/src/interfaces/bullion-site-info.interface.go @@ -22,7 +22,7 @@ type BullionSiteInfoEntity struct { GeneralUserInfo *bullionGeneralUserConfig `bson:"generalUserInfo" json:"-" validate:"required"` } -func (b *BullionSiteInfoEntity) AddGeneralUserInfo(AutoApprove bool, AutoLogin bool) (r *BullionSiteInfoEntity) { +func (b *BullionSiteInfoEntity) AddGeneralUserInfo(AutoApprove bool, AutoLogin bool) *BullionSiteInfoEntity { b.GeneralUserInfo = &bullionGeneralUserConfig{ AutoApprove: AutoApprove, AutoLogin: AutoLogin, diff --git a/src/interfaces/error-code.enum.go b/src/interfaces/error-code.enum.go index e3c7e63..11ce1bb 100644 --- a/src/interfaces/error-code.enum.go +++ b/src/interfaces/error-code.enum.go @@ -35,4 +35,5 @@ const ( ERROR_WHILE_FETCHING_MESSAGE_TEMPLATE = 230 ERROR_INVALID_ORDER_STATUS_FOR_DELIVERY = 231 ERROR_INVALID_WEIGHT_FOR_DELIVERY = 232 + ERROR_INSUFFICIENT_MARGIN = 233 ) diff --git a/src/interfaces/general-user-req.entity.go b/src/interfaces/general-user-req.entity.go index 553b964..bbe1e1c 100644 --- a/src/interfaces/general-user-req.entity.go +++ b/src/interfaces/general-user-req.entity.go @@ -7,7 +7,7 @@ type GeneralUserReqEntity struct { Status GeneralUserAuthStatus `bson:"status" json:"status" validate:"required,enum=GeneralUserAuthStatus"` } -func CreateNewGeneralUserReq(generalUserId string, bullionId string, status GeneralUserAuthStatus) (r *GeneralUserReqEntity) { +func CreateNewGeneralUserReq(generalUserId string, bullionId string, status GeneralUserAuthStatus) *GeneralUserReqEntity { b := &GeneralUserReqEntity{ GeneralUserId: generalUserId, BullionId: bullionId, diff --git a/src/interfaces/general-users.entity.go b/src/interfaces/general-users.entity.go index b2af7db..7fc12f2 100644 --- a/src/interfaces/general-users.entity.go +++ b/src/interfaces/general-users.entity.go @@ -18,7 +18,7 @@ type GeneralUserEntity struct { GeneralUser `bson:"inline"` } -func CreateNewGeneralUser(user GeneralUser) (r *GeneralUserEntity) { +func CreateNewGeneralUser(user GeneralUser) *GeneralUserEntity { b := &GeneralUserEntity{ UserRolesInterface: UserRolesInterface{ Role: ROLE_GENERAL_USER, diff --git a/src/interfaces/order-entity.interface.go b/src/interfaces/order-entity.interface.go index 288b529..7bb355a 100644 --- a/src/interfaces/order-entity.interface.go +++ b/src/interfaces/order-entity.interface.go @@ -17,6 +17,7 @@ type ( DeliveryData *[]DeliveryData `bson:"inline,omitempty"` } OrderBase struct { + BullionId string `bson:"bullionId" json:"bullionId" validate:"required,uuid"` OrderType OrderType `bson:"orderType" json:"orderType" validate:"required,enum=OrderStatus"` OrderStatus OrderStatus `bson:"orderStatus" json:"orderStatus" validate:"required,enum=OrderStatus"` BuySell BuySell `bson:"buySell" json:"buySell" validate:"required,enum=BuySell"` diff --git a/src/interfaces/product-entity.interface.go b/src/interfaces/product-entity.interface.go index fef405d..6401687 100644 --- a/src/interfaces/product-entity.interface.go +++ b/src/interfaces/product-entity.interface.go @@ -46,7 +46,7 @@ type ( } ) -func CreateNewProduct(productBase *ProductBaseStruct, calcSnapShot *CalcSnapshotStruct, sequence int) (r *ProductEntity) { +func CreateNewProduct(productBase *ProductBaseStruct, calcSnapShot *CalcSnapshotStruct, sequence int) *ProductEntity { b := &ProductEntity{ ProductBaseStruct: productBase, CalcSnapshot: calcSnapShot, diff --git a/src/interfaces/trade-user.entity.go b/src/interfaces/trade-user.entity.go index b0120a2..75109e7 100644 --- a/src/interfaces/trade-user.entity.go +++ b/src/interfaces/trade-user.entity.go @@ -1,5 +1,7 @@ package interfaces +import "net/http" + type ( TradeUserBase struct { BullionId string `bson:"bullionId" json:"bullionId" validate:"required,uuid"` @@ -18,8 +20,8 @@ type ( UNumber string `bson:"uNumber" json:"uNumber" validate:"required"` } UserMarginsDataStruct struct { - Gold int32 `bson:"gold" json:"gold" validate:"min=0"` - Silver int32 `bson:"silver" json:"silver" validate:"min=0"` + Gold int `bson:"gold" json:"gold" validate:"min=0"` + Silver int `bson:"silver" json:"silver" validate:"min=0"` } TradeUserMargins struct { @@ -41,17 +43,43 @@ type ( } ) -func (user *TradeUserEntity) CreateNew() (r *TradeUserEntity) { +func (user *TradeUserEntity) CreateNew() *TradeUserEntity { user.createNewId() return user } -func (user *TradeUserEntity) UpdateUser() (r *TradeUserEntity) { +func (user *TradeUserEntity) UpdateUser() *TradeUserEntity { user.passwordEntity = CreatePasswordEntity(user.RawPassword) user.Updated() return user } -func (user *TradeUserEntity) DeletePassword() (r *TradeUserEntity) { +func (user *TradeUserEntity) DeletePassword() *TradeUserEntity { user.RawPassword = "" return user } + +func (user *TradeUserEntity) UpdateMarginAfterOrder(weight int, symbol SymbolsEnum) (*TradeUserEntity, error) { + availableMargin := 0 + if symbol == SYMBOL_GOLD { + availableMargin = user.AllotedMargins.Gold - user.UsedMargins.Gold + } else if symbol == SYMBOL_SILVER { + availableMargin = user.AllotedMargins.Silver - user.UsedMargins.Silver + } + + if availableMargin < 0 || availableMargin-weight < 0 { + return nil, &RequestError{ + StatusCode: http.StatusBadRequest, + Code: ERROR_INSUFFICIENT_MARGIN, + Message: "Insufficient Margin", + Name: "INSUFFICIENT_MARGIN", + Extra: map[string]interface{}{"margins": user.TradeUserMargins, "weight": weight}, + } + } + + if symbol == SYMBOL_GOLD { + user.UsedMargins.Gold = user.UsedMargins.Gold + weight + } else if symbol == SYMBOL_SILVER { + user.UsedMargins.Silver = user.UsedMargins.Silver + weight + } + return user, nil +} From 28d4184067560aea4bafbe25701fe8cb1670389b Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Sat, 16 Mar 2024 01:14:19 +0530 Subject: [PATCH 04/23] Updated Scripts --- .github/workflows/builder.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/builder.yml b/.github/workflows/builder.yml index c262919..618aa43 100644 --- a/.github/workflows/builder.yml +++ b/.github/workflows/builder.yml @@ -12,7 +12,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: '1.21.1' + go-version: '1.21.6' - name: Build run: go build -v ./... From 98c62567c35a626903032b98c2ce3b0859ac2253 Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Sat, 16 Mar 2024 02:40:09 +0530 Subject: [PATCH 05/23] Order Repo WIP --- .vscode/settings.json | 1 + src/apis/apis.go | 2 + src/apis/order/admin-order/index.go | 9 ++ src/apis/order/index.go | 14 +++ src/apis/order/user/index.go | 8 ++ src/interfaces/order-entity.interface.go | 2 +- src/mongodb/repos/order.repo.go | 130 +++++++++++++++++++++++ src/mongodb/repos/trade-user.repo.go | 3 - src/services/order-general.service.go | 3 + src/services/trade-user-group.service.go | 3 - 10 files changed, 168 insertions(+), 7 deletions(-) create mode 100644 src/apis/order/admin-order/index.go create mode 100644 src/apis/order/index.go create mode 100644 src/apis/order/user/index.go create mode 100644 src/mongodb/repos/order.repo.go create mode 100644 src/services/order-general.service.go diff --git a/.vscode/settings.json b/.vscode/settings.json index bdad887..999bef1 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,5 +1,6 @@ { "cSpell.words": [ + "adminorder", "Akshat", "bankdetails", "bson", diff --git a/src/apis/apis.go b/src/apis/apis.go index d57dda2..20040c6 100644 --- a/src/apis/apis.go +++ b/src/apis/apis.go @@ -4,9 +4,11 @@ import ( "github.com/gofiber/fiber/v2" "github.com/rpsoftech/bullion-server/src/apis/auth" "github.com/rpsoftech/bullion-server/src/apis/data" + "github.com/rpsoftech/bullion-server/src/apis/order" ) func AddApis(app fiber.Router) { auth.AddAuthPackages(app.Group("/auth")) data.AddDataPackage(app.Group("/data")) + order.AddOrderPackage(app.Group("/order")) } diff --git a/src/apis/order/admin-order/index.go b/src/apis/order/admin-order/index.go new file mode 100644 index 0000000..aa2308d --- /dev/null +++ b/src/apis/order/admin-order/index.go @@ -0,0 +1,9 @@ +package adminorder + +import ( + "github.com/gofiber/fiber/v2" +) + +func AddAdminOrderRouter(router fiber.Router) { + +} diff --git a/src/apis/order/index.go b/src/apis/order/index.go new file mode 100644 index 0000000..52fb67c --- /dev/null +++ b/src/apis/order/index.go @@ -0,0 +1,14 @@ +package order + +import ( + "github.com/gofiber/fiber/v2" + adminorder "github.com/rpsoftech/bullion-server/src/apis/order/admin-order" + "github.com/rpsoftech/bullion-server/src/apis/order/user" + "github.com/rpsoftech/bullion-server/src/middleware" +) + +func AddOrderPackage(router fiber.Router) { + router.Use(middleware.AllowOnlyValidTokenMiddleWare) + adminorder.AddAdminOrderRouter(router.Group("/admin", middleware.AllowOnlyBigAdmins.Validate)) + user.AddUserOrderApis(router.Group("/user", middleware.AllowAllAdminsAndTradeUsers.Validate)) +} diff --git a/src/apis/order/user/index.go b/src/apis/order/user/index.go new file mode 100644 index 0000000..89591eb --- /dev/null +++ b/src/apis/order/user/index.go @@ -0,0 +1,8 @@ +package user + +import "github.com/gofiber/fiber/v2" + +func AddUserOrderApis(router fiber.Router) { + + // router.Use(middleware.AllowAllAdminsAndTradeUsers.Validate) +} diff --git a/src/interfaces/order-entity.interface.go b/src/interfaces/order-entity.interface.go index 7bb355a..c91a781 100644 --- a/src/interfaces/order-entity.interface.go +++ b/src/interfaces/order-entity.interface.go @@ -12,7 +12,7 @@ type ( *OrderBase `bson:"inline"` *LimitWatcherRequired `bson:"inline"` *AfterSuccessOrder `bson:"inline,omitempty"` - Identity *Identity `bson:"inline"` + *Identity `bson:"inline"` FromAdmin *FromAdmin `bson:"inline,omitempty"` DeliveryData *[]DeliveryData `bson:"inline,omitempty"` } diff --git a/src/mongodb/repos/order.repo.go b/src/mongodb/repos/order.repo.go new file mode 100644 index 0000000..6d0f81d --- /dev/null +++ b/src/mongodb/repos/order.repo.go @@ -0,0 +1,130 @@ +package repos + +import ( + "errors" + "fmt" + "net/http" + + "github.com/rpsoftech/bullion-server/src/env" + "github.com/rpsoftech/bullion-server/src/interfaces" + "github.com/rpsoftech/bullion-server/src/mongodb" + "github.com/rpsoftech/bullion-server/src/utility" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo" + "go.mongodb.org/mongo-driver/mongo/options" +) + +type ( + OrderRepoStruct struct { + collection *mongo.Collection + } +) + +const orderCollectionName = "Order" + +var OrderRepo *OrderRepoStruct + +func init() { + if env.Env.APP_ENV == env.APP_ENV_DEVELOPE { + return + } + coll := mongodb.MongoDatabase.Collection(orderCollectionName) + OrderRepo = &OrderRepoStruct{ + collection: coll, + } + addUniqueIndexesToCollection([]string{"id"}, OrderRepo.collection) + addIndexesToCollection([]string{"userId", "productGroupMapId", "groupId", "productId", "orderStatus", "createdAt"}, OrderRepo.collection) +} + +func (repo *OrderRepoStruct) Save(entity *interfaces.OrderEntity) (*interfaces.OrderEntity, error) { + if err := utility.ValidateStructAndReturnReqError(entity, &interfaces.RequestError{ + StatusCode: http.StatusBadRequest, + Code: interfaces.ERROR_INVALID_ENTITY, + Message: "", + Name: "ERROR_INVALID_ENTITY", + }); err != nil { + return entity, err + } + entity.Updated() + err := repo.collection.FindOneAndUpdate(mongodb.MongoCtx, bson.D{{ + Key: "_id", Value: entity.ID, + }}, bson.D{{Key: "$set", Value: entity}}, findOneAndUpdateOptions).Err() + if err != nil { + if !errors.Is(err, mongo.ErrNoDocuments) { + err = &interfaces.RequestError{ + StatusCode: 500, + Code: interfaces.ERROR_INTERNAL_SERVER, + Message: fmt.Sprintf("Internal Server Error: %s", err.Error()), + Name: "INTERNAL_ERROR", + } + } else { + err = nil + } + } + return entity, err +} + +func (repo *OrderRepoStruct) findByFilter(filter *mongoDbFilter) (*[]interfaces.OrderEntity, error) { + var result []interfaces.OrderEntity + opt := options.Find() + if filter.sort != nil { + opt.SetSort(filter.sort) + } + if filter.limit > 0 { + opt.SetLimit(filter.limit) + } + if filter.skip > 0 { + opt.SetSkip(filter.skip) + } + cursor, err := repo.collection.Find(mongodb.MongoCtx, filter.conditions, opt) + if err == nil { + err = cursor.All(mongodb.MongoCtx, &result) + } + if err != nil { + if errors.Is(err, mongo.ErrNoDocuments) { + // This error means your query did not match any documents. + err = &interfaces.RequestError{ + StatusCode: http.StatusBadRequest, + Code: interfaces.ERROR_ENTITY_NOT_FOUND, + Message: fmt.Sprintf("Feeds Entities filtered By %v not found", filter), + Name: "ENTITY_NOT_FOUND", + } + } else { + err = &interfaces.RequestError{ + StatusCode: 500, + Code: interfaces.ERROR_INTERNAL_SERVER, + Message: fmt.Sprintf("Internal Server Error: %s", err.Error()), + Name: "INTERNAL_ERROR", + } + } + } + return &result, err +} + +func (repo *OrderRepoStruct) FindOne(id string) (*interfaces.OrderEntity, error) { + var result interfaces.OrderEntity + + err := repo.collection.FindOne(mongodb.MongoCtx, bson.D{{ + Key: "id", Value: id, + }}).Decode(&result) + + if err != nil { + if errors.Is(err, mongo.ErrNoDocuments) { + // This error means your query did not match any documents. + err = &interfaces.RequestError{ + StatusCode: http.StatusBadRequest, + Code: interfaces.ERROR_ENTITY_NOT_FOUND, + Message: fmt.Sprintf("Feeds Entity identified by id %s not found", id), + Name: "ENTITY_NOT_FOUND", + } + } else { + err = &interfaces.RequestError{ + StatusCode: 500, + Code: interfaces.ERROR_INTERNAL_SERVER, + Message: fmt.Sprintf("Internal Server Error: %s", err.Error()), + Name: "INTERNAL_ERROR", + } + } + } + return &result, err +} diff --git a/src/mongodb/repos/trade-user.repo.go b/src/mongodb/repos/trade-user.repo.go index aa312f3..b1f4147 100644 --- a/src/mongodb/repos/trade-user.repo.go +++ b/src/mongodb/repos/trade-user.repo.go @@ -8,7 +8,6 @@ import ( "github.com/rpsoftech/bullion-server/src/env" "github.com/rpsoftech/bullion-server/src/interfaces" "github.com/rpsoftech/bullion-server/src/mongodb" - "github.com/rpsoftech/bullion-server/src/redis" "github.com/rpsoftech/bullion-server/src/utility" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" @@ -18,7 +17,6 @@ import ( type ( TradeUserRepoStruct struct { collection *mongo.Collection - redis *redis.RedisClientStruct } ) @@ -33,7 +31,6 @@ func init() { coll := mongodb.MongoDatabase.Collection(tradeUserCollectionName) TradeUserRepo = &TradeUserRepoStruct{ collection: coll, - redis: redis.InitRedisAndRedisClient(), } addUniqueIndexesToCollection([]string{"id"}, TradeUserRepo.collection) addIndexesToCollection([]string{"bullionId", "isActive"}, TradeUserRepo.collection) diff --git a/src/services/order-general.service.go b/src/services/order-general.service.go new file mode 100644 index 0000000..092c941 --- /dev/null +++ b/src/services/order-general.service.go @@ -0,0 +1,3 @@ +package services + +func init() {} diff --git a/src/services/trade-user-group.service.go b/src/services/trade-user-group.service.go index 37f8d03..4bb2e69 100644 --- a/src/services/trade-user-group.service.go +++ b/src/services/trade-user-group.service.go @@ -6,11 +6,9 @@ import ( "github.com/rpsoftech/bullion-server/src/events" "github.com/rpsoftech/bullion-server/src/interfaces" "github.com/rpsoftech/bullion-server/src/mongodb/repos" - "github.com/rpsoftech/bullion-server/src/redis" ) type tradeUserGroupServiceStruct struct { - redisRepo *redis.RedisClientStruct eventBus *eventBusService firebaseDb *firebaseDatabaseService bullionService *bullionDetailsService @@ -31,7 +29,6 @@ func init() { func getTradeUserGroupService() *tradeUserGroupServiceStruct { if TradeUserGroupService == nil { TradeUserGroupService = &tradeUserGroupServiceStruct{ - redisRepo: redis.InitRedisAndRedisClient(), eventBus: getEventBusService(), firebaseDb: getFirebaseRealTimeDatabase(), bullionService: getBullionService(), From d04d31d68c9b287fd9277bee4e2e1bcd76c4c368 Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Sat, 16 Mar 2024 10:19:37 +0530 Subject: [PATCH 06/23] Order Repo Completed --- src/interfaces/order-entity.interface.go | 4 +- src/mongodb/repos/order.repo.go | 73 ++++++++++++++++++++++++ 2 files changed, 75 insertions(+), 2 deletions(-) diff --git a/src/interfaces/order-entity.interface.go b/src/interfaces/order-entity.interface.go index c91a781..a32ec9b 100644 --- a/src/interfaces/order-entity.interface.go +++ b/src/interfaces/order-entity.interface.go @@ -60,10 +60,10 @@ type ( } ) -var AvailableForDelivery = []OrderStatus{OrderPlaced, LimitPassed, OrderPartialDelivered} +var AvailableForDelivery = &[]OrderStatus{OrderPlaced, LimitPassed, OrderPartialDelivered} func (e *OrderEntity) DeliverWeight(weight int) (*OrderEntity, error) { - if !slices.Contains(AvailableForDelivery, e.OrderStatus) { + if !slices.Contains(*AvailableForDelivery, e.OrderStatus) { return nil, &RequestError{ StatusCode: http.StatusBadRequest, Code: ERROR_INVALID_ORDER_STATUS_FOR_DELIVERY, diff --git a/src/mongodb/repos/order.repo.go b/src/mongodb/repos/order.repo.go index 6d0f81d..1d22776 100644 --- a/src/mongodb/repos/order.repo.go +++ b/src/mongodb/repos/order.repo.go @@ -4,6 +4,7 @@ import ( "errors" "fmt" "net/http" + "time" "github.com/rpsoftech/bullion-server/src/env" "github.com/rpsoftech/bullion-server/src/interfaces" @@ -64,6 +65,37 @@ func (repo *OrderRepoStruct) Save(entity *interfaces.OrderEntity) (*interfaces.O return entity, err } +func (repo *OrderRepoStruct) BulkUpdate(entities *[]interfaces.OrderEntity) (*[]interfaces.OrderEntity, error) { + models := make([]mongo.WriteModel, len(*entities)) + for i, entity := range *entities { + if err := utility.ValidateStructAndReturnReqError(entity, &interfaces.RequestError{ + StatusCode: http.StatusBadRequest, + Code: interfaces.ERROR_INVALID_ENTITY, + Message: "", + Name: "ERROR_INVALID_ENTITY", + }); err != nil { + return nil, err + } + entity.Updated() + models[i] = mongo.NewUpdateOneModel().SetFilter(bson.D{{Key: "_id", Value: entity.ID}}).SetUpdate( + bson.D{{Key: "$set", Value: entity}}).SetUpsert(true) + } + _, err := repo.collection.BulkWrite(mongodb.MongoCtx, models) + if err != nil { + if !errors.Is(err, mongo.ErrNoDocuments) { + err = &interfaces.RequestError{ + StatusCode: 500, + Code: interfaces.ERROR_INTERNAL_SERVER, + Message: fmt.Sprintf("Internal Server Error: %s", err.Error()), + Name: "INTERNAL_ERROR", + } + } else { + err = nil + } + } + return entities, err +} + func (repo *OrderRepoStruct) findByFilter(filter *mongoDbFilter) (*[]interfaces.OrderEntity, error) { var result []interfaces.OrderEntity opt := options.Find() @@ -128,3 +160,44 @@ func (repo *OrderRepoStruct) FindOne(id string) (*interfaces.OrderEntity, error) } return &result, err } + +func (repo *OrderRepoStruct) DeleteOrderHistoryById(id string) error { + _, err := repo.collection.DeleteOne(mongodb.MongoCtx, bson.D{{ + Key: "_id", Value: id, + }}) + return err +} + +func (repo *OrderRepoStruct) GetOrdersByBullionIdWithDateRangeAndOrderStatus(bullionId string, startDate time.Time, endDate time.Time, orderStatusArray *[]interfaces.OrderStatus) (*[]interfaces.OrderEntity, error) { + return repo.findByFilter(&mongoDbFilter{ + sort: &bson.D{{Key: "createdAt", Value: -1}}, + conditions: &bson.D{ + {Key: "bullionId", Value: bullionId}, + {Key: "createdAt", Value: bson.D{{Key: "$gte", Value: startDate}, {Key: "$lte", Value: endDate}}}, + {Key: "orderStatus", Value: bson.D{{Key: "$in", Value: *orderStatusArray}}}, + }, + }) +} + +func (repo *OrderRepoStruct) GetUsersOrderPaginated(userId string, page int64, limit int64) (*[]interfaces.OrderEntity, error) { + return repo.findByFilter(&mongoDbFilter{ + sort: &bson.D{{Key: "createdAt", Value: -1}}, + conditions: &bson.D{ + {Key: "userId", Value: userId}, + }, + limit: limit, + skip: page * limit, + }) +} + +func (repo *OrderRepoStruct) GetUsersOrderPaginatedWithOrderStatusArray(userId string, orderStatusArray *[]interfaces.OrderStatus, page int64, limit int64) (*[]interfaces.OrderEntity, error) { + return repo.findByFilter(&mongoDbFilter{ + sort: &bson.D{{Key: "createdAt", Value: -1}}, + conditions: &bson.D{ + {Key: "userId", Value: userId}, + {Key: "orderStatus", Value: bson.D{{Key: "$in", Value: *orderStatusArray}}}, + }, + limit: limit, + skip: page * limit, + }) +} From 5dd334ad5ae4b8e3684e157bffa429e111824656 Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Sun, 17 Mar 2024 02:18:37 +0530 Subject: [PATCH 07/23] Trade User Caching Data Completed --- go.mod | 18 +++++++++--------- go.sum | 16 ++++++++++++++++ src/mongodb/repos/trade-user.repo.go | 20 +++++++++++++++++++- src/redis/index.go | 5 ++++- src/services/order-general.service.go | 27 ++++++++++++++++++++++++++- 5 files changed, 74 insertions(+), 12 deletions(-) diff --git a/go.mod b/go.mod index 94d87b6..5213013 100644 --- a/go.mod +++ b/go.mod @@ -1,6 +1,6 @@ module github.com/rpsoftech/bullion-server -go 1.21.6 +go 1.22.1 require ( cloud.google.com/go/firestore v1.15.0 @@ -15,15 +15,15 @@ require ( github.com/redis/go-redis/v9 v9.5.1 go.mongodb.org/mongo-driver v1.14.0 golang.org/x/crypto v0.21.0 - google.golang.org/api v0.169.0 + google.golang.org/api v0.170.0 ) require ( cloud.google.com/go v0.112.1 // indirect - cloud.google.com/go/compute v1.25.0 // indirect + cloud.google.com/go/compute v1.25.1 // indirect cloud.google.com/go/compute/metadata v0.2.3 // indirect - cloud.google.com/go/iam v1.1.6 // indirect - cloud.google.com/go/longrunning v0.5.5 // indirect + cloud.google.com/go/iam v1.1.7 // indirect + cloud.google.com/go/longrunning v0.5.6 // indirect cloud.google.com/go/storage v1.39.1 // indirect github.com/MicahParks/keyfunc v1.9.0 // indirect github.com/andybalholm/brotli v1.1.0 // indirect @@ -41,7 +41,7 @@ require ( github.com/golang/snappy v0.0.4 // indirect github.com/google/s2a-go v0.1.7 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect - github.com/googleapis/gax-go/v2 v2.12.2 // indirect + github.com/googleapis/gax-go/v2 v2.12.3 // indirect github.com/klauspost/compress v1.17.7 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect @@ -70,9 +70,9 @@ require ( golang.org/x/time v0.5.0 // indirect google.golang.org/appengine v1.6.8 // indirect google.golang.org/appengine/v2 v2.0.5 // indirect - google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240311173647-c811ad7063a7 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7 // indirect + google.golang.org/genproto v0.0.0-20240314234333-6e1732d8331c // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240314234333-6e1732d8331c // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect google.golang.org/grpc v1.62.1 // indirect google.golang.org/protobuf v1.33.0 // indirect ) diff --git a/go.sum b/go.sum index c0e572a..af94b31 100644 --- a/go.sum +++ b/go.sum @@ -3,14 +3,20 @@ cloud.google.com/go v0.112.1 h1:uJSeirPke5UNZHIb4SxfZklVSiWWVqW4oXlETwZziwM= cloud.google.com/go v0.112.1/go.mod h1:+Vbu+Y1UU+I1rjmzeMOb/8RfkKJK2Gyxi1X6jJCZLo4= cloud.google.com/go/compute v1.25.0 h1:H1/4SqSUhjPFE7L5ddzHOfY2bCAvjwNRZPNl6Ni5oYU= cloud.google.com/go/compute v1.25.0/go.mod h1:GR7F0ZPZH8EhChlMo9FkLd7eUTwEymjqQagxzilIxIE= +cloud.google.com/go/compute v1.25.1 h1:ZRpHJedLtTpKgr3RV1Fx23NuaAEN1Zfx9hw1u4aJdjU= +cloud.google.com/go/compute v1.25.1/go.mod h1:oopOIR53ly6viBYxaDhBfJwzUAxf1zE//uf3IB011ls= cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= cloud.google.com/go/firestore v1.15.0 h1:/k8ppuWOtNuDHt2tsRV42yI21uaGnKDEQnRFeBpbFF8= cloud.google.com/go/firestore v1.15.0/go.mod h1:GWOxFXcv8GZUtYpWHw/w6IuYNux/BtmeVTMmjrm4yhk= cloud.google.com/go/iam v1.1.6 h1:bEa06k05IO4f4uJonbB5iAgKTPpABy1ayxaIZV/GHVc= cloud.google.com/go/iam v1.1.6/go.mod h1:O0zxdPeGBoFdWW3HWmBxJsk0pfvNM/p/qa82rWOGTwI= +cloud.google.com/go/iam v1.1.7 h1:z4VHOhwKLF/+UYXAJDFwGtNF0b6gjsW1Pk9Ml0U/IoM= +cloud.google.com/go/iam v1.1.7/go.mod h1:J4PMPg8TtyurAUvSmPj8FF3EDgY1SPRZxcUGrn7WXGA= cloud.google.com/go/longrunning v0.5.5 h1:GOE6pZFdSrTb4KAiKnXsJBtlE6mEyaW44oKyMILWnOg= cloud.google.com/go/longrunning v0.5.5/go.mod h1:WV2LAxD8/rg5Z1cNW6FJ/ZpX4E4VnDnoTk0yawPBB7s= +cloud.google.com/go/longrunning v0.5.6 h1:xAe8+0YaWoCKr9t1+aWe+OeQgN/iJK1fEgZSXmjuEaE= +cloud.google.com/go/longrunning v0.5.6/go.mod h1:vUaDrWYOMKRuhiv6JBnn49YxCPz2Ayn9GqyjaBT8/mA= cloud.google.com/go/storage v1.39.1 h1:MvraqHKhogCOTXTlct/9C3K3+Uy2jBmFYb3/Sp6dVtY= cloud.google.com/go/storage v1.39.1/go.mod h1:xK6xZmxZmo+fyP7+DEF6FhNc24/JAe95OLyOHCXFH1o= firebase.google.com/go/v4 v4.13.0 h1:meFz9nvDNh/FDyrEykoAzSfComcQbmnQSjoHrePRqeI= @@ -104,6 +110,8 @@ github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfF github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0= github.com/googleapis/gax-go/v2 v2.12.2 h1:mhN09QQW1jEWeMF74zGR81R30z4VJzjZsfkUhuHF+DA= github.com/googleapis/gax-go/v2 v2.12.2/go.mod h1:61M8vcyyXR2kqKFxKrfA22jaA8JGF7Dc8App1U3H6jc= +github.com/googleapis/gax-go/v2 v2.12.3 h1:5/zPPDvw8Q1SuXjrqrZslrqT7dL/uJT2CQii/cLCKqA= +github.com/googleapis/gax-go/v2 v2.12.3/go.mod h1:AKloxT6GtNbaLm8QTNSidHUVsHYcBHwWRvkNFJUQcS4= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg= @@ -234,6 +242,8 @@ golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSm golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= google.golang.org/api v0.169.0 h1:QwWPy71FgMWqJN/l6jVlFHUa29a7dcUy02I8o799nPY= google.golang.org/api v0.169.0/go.mod h1:gpNOiMA2tZ4mf5R9Iwf4rK/Dcz0fbdIgWYWVoxmsyLg= +google.golang.org/api v0.170.0 h1:zMaruDePM88zxZBG+NG8+reALO2rfLhe/JShitLyT48= +google.golang.org/api v0.170.0/go.mod h1:/xql9M2btF85xac/VAm4PsLMTLVGUOpq4BE9R8jyNy8= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= @@ -245,10 +255,16 @@ google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98 google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7 h1:ImUcDPHjTrAqNhlOkSocDLfG9rrNHH7w7uoKWPaWZ8s= google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7/go.mod h1:/3XmxOjePkvmKrHuBy4zNFw7IzxJXtAgdpXi8Ll990U= +google.golang.org/genproto v0.0.0-20240314234333-6e1732d8331c h1:1AVpelW1Ld8u6QbfPlwh00uAsR3xrnfn6FIJsCags3k= +google.golang.org/genproto v0.0.0-20240314234333-6e1732d8331c/go.mod h1:/3XmxOjePkvmKrHuBy4zNFw7IzxJXtAgdpXi8Ll990U= google.golang.org/genproto/googleapis/api v0.0.0-20240311173647-c811ad7063a7 h1:oqta3O3AnlWbmIE3bFnWbu4bRxZjfbWCp0cKSuZh01E= google.golang.org/genproto/googleapis/api v0.0.0-20240311173647-c811ad7063a7/go.mod h1:VQW3tUculP/D4B+xVCo+VgSq8As6wA9ZjHl//pmk+6s= +google.golang.org/genproto/googleapis/api v0.0.0-20240314234333-6e1732d8331c h1:kaI7oewGK5YnVwj+Y+EJBO/YN1ht8iTL9XkFHtVZLsc= +google.golang.org/genproto/googleapis/api v0.0.0-20240314234333-6e1732d8331c/go.mod h1:VQW3tUculP/D4B+xVCo+VgSq8As6wA9ZjHl//pmk+6s= google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7 h1:8EeVk1VKMD+GD/neyEHGmz7pFblqPjHoi+PGQIlLx2s= google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c h1:lfpJ/2rWPa/kJgxyyXM8PrNnfCzcmxJ265mADgwmvLI= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= diff --git a/src/mongodb/repos/trade-user.repo.go b/src/mongodb/repos/trade-user.repo.go index b1f4147..00f4122 100644 --- a/src/mongodb/repos/trade-user.repo.go +++ b/src/mongodb/repos/trade-user.repo.go @@ -1,13 +1,16 @@ package repos import ( + "encoding/json" "errors" "fmt" "net/http" + "time" "github.com/rpsoftech/bullion-server/src/env" "github.com/rpsoftech/bullion-server/src/interfaces" "github.com/rpsoftech/bullion-server/src/mongodb" + "github.com/rpsoftech/bullion-server/src/redis" "github.com/rpsoftech/bullion-server/src/utility" "go.mongodb.org/mongo-driver/bson" "go.mongodb.org/mongo-driver/mongo" @@ -17,6 +20,7 @@ import ( type ( TradeUserRepoStruct struct { collection *mongo.Collection + redis *redis.RedisClientStruct } ) @@ -31,6 +35,7 @@ func init() { coll := mongodb.MongoDatabase.Collection(tradeUserCollectionName) TradeUserRepo = &TradeUserRepoStruct{ collection: coll, + redis: redis.InitRedisAndRedisClient(), } addUniqueIndexesToCollection([]string{"id"}, TradeUserRepo.collection) addIndexesToCollection([]string{"bullionId", "isActive"}, TradeUserRepo.collection) @@ -65,6 +70,7 @@ func (repo *TradeUserRepoStruct) Save(entity *interfaces.TradeUserEntity) (*inte err = nil } } + go repo.cacheDataToRedis(entity) return entity, err } @@ -129,7 +135,12 @@ func (repo *TradeUserRepoStruct) findByFilter(filter *mongoDbFilter) (*[]interfa func (repo *TradeUserRepoStruct) FindOne(id string) (*interfaces.TradeUserEntity, error) { var result interfaces.TradeUserEntity - + if redisData := repo.redis.GetStringData(fmt.Sprintf("tradeUser/%s", id)); redisData != "" { + entity := new(interfaces.TradeUserEntity) + if err := json.Unmarshal([]byte(redisData), entity); err == nil { + return entity, err + } + } err := repo.collection.FindOne(mongodb.MongoCtx, bson.D{{ Key: "id", Value: id, }}).Decode(&result) @@ -152,9 +163,16 @@ func (repo *TradeUserRepoStruct) FindOne(id string) (*interfaces.TradeUserEntity } } } + go repo.cacheDataToRedis(&result) return &result, err } +func (repo *TradeUserRepoStruct) cacheDataToRedis(entity *interfaces.TradeUserEntity) { + if entityStringBytes, err := json.Marshal(entity); err == nil { + entityString := string(entityStringBytes) + repo.redis.SetStringDataWithExpiry(fmt.Sprintf("tradeUser/%s", entity.ID), entityString, time.Duration(24)*time.Hour) + } +} func (repo *TradeUserRepoStruct) findOneByCondition(bullionId string, condition *bson.E) (*interfaces.TradeUserEntity, error) { var result interfaces.TradeUserEntity diff --git a/src/redis/index.go b/src/redis/index.go index 58d40dc..2273870 100644 --- a/src/redis/index.go +++ b/src/redis/index.go @@ -63,5 +63,8 @@ func (r *RedisClientStruct) RemoveKey(key ...string) { r.redisClient.Del(RedisCTX, key...) } func (r *RedisClientStruct) SetStringData(key string, value string, expiresIn int) { - r.redisClient.Set(RedisCTX, key, value, time.Duration(expiresIn)*time.Second) + r.SetStringDataWithExpiry(key, value, time.Duration(expiresIn)*time.Second) +} +func (r *RedisClientStruct) SetStringDataWithExpiry(key string, value string, expiresIn time.Duration) { + r.redisClient.Set(RedisCTX, key, value, expiresIn) } diff --git a/src/services/order-general.service.go b/src/services/order-general.service.go index 092c941..e8c3568 100644 --- a/src/services/order-general.service.go +++ b/src/services/order-general.service.go @@ -1,3 +1,28 @@ package services -func init() {} +import "github.com/rpsoftech/bullion-server/src/mongodb/repos" + +type orderGeneralService struct { + eventBus *eventBusService + firebaseDb *firebaseDatabaseService + bullionService *bullionDetailsService + orderRepo *repos.OrderRepoStruct +} + +var OrderGeneralService *orderGeneralService + +func init() { + getOrderGeneralService() +} +func getOrderGeneralService() *orderGeneralService { + if OrderGeneralService == nil { + OrderGeneralService = &orderGeneralService{ + eventBus: getEventBusService(), + firebaseDb: getFirebaseRealTimeDatabase(), + bullionService: getBullionService(), + orderRepo: repos.OrderRepo, + } + println("Order General Service Initialized") + } + return OrderGeneralService +} From c55c9b7b9a7cf2a025831cacd941db5aee976c50 Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Sun, 17 Mar 2024 12:45:23 +0530 Subject: [PATCH 08/23] WIP --- src/interfaces/error-code.enum.go | 1 + src/interfaces/trade-user-group.entity.go | 11 +++++ src/services/order-general.service.go | 59 +++++++++++++++++++---- 3 files changed, 62 insertions(+), 9 deletions(-) diff --git a/src/interfaces/error-code.enum.go b/src/interfaces/error-code.enum.go index 11ce1bb..24c11c9 100644 --- a/src/interfaces/error-code.enum.go +++ b/src/interfaces/error-code.enum.go @@ -36,4 +36,5 @@ const ( ERROR_INVALID_ORDER_STATUS_FOR_DELIVERY = 231 ERROR_INVALID_WEIGHT_FOR_DELIVERY = 232 ERROR_INSUFFICIENT_MARGIN = 233 + ERROR_INVALID_VOLUME = 234 ) diff --git a/src/interfaces/trade-user-group.entity.go b/src/interfaces/trade-user-group.entity.go index 98459eb..d685a85 100644 --- a/src/interfaces/trade-user-group.entity.go +++ b/src/interfaces/trade-user-group.entity.go @@ -52,6 +52,17 @@ func (r *TradeUserGroupMapEntity) CreateNew() *TradeUserGroupMapEntity { return r } +func (r *TradeUserGroupMapEntity) ValidateVolume(weight int) bool { + if weight < r.GroupVolumeBase.OneClick { + return false + } else if weight > r.GroupVolumeBase.Total { + return false + } else if weight == r.GroupVolumeBase.OneClick || weight == r.GroupVolumeBase.Total { + return true + } + return (weight-r.GroupVolumeBase.OneClick)%r.GroupVolumeBase.Step == 0 +} + func (r *TradeUserGroupMapBase) UpdateDetails(base *TradeUserGroupMapBase) *TradeUserGroupMapBase { r.IsActive = base.IsActive r.CanTrade = base.CanTrade diff --git a/src/services/order-general.service.go b/src/services/order-general.service.go index e8c3568..e213bb9 100644 --- a/src/services/order-general.service.go +++ b/src/services/order-general.service.go @@ -1,12 +1,17 @@ package services -import "github.com/rpsoftech/bullion-server/src/mongodb/repos" +import ( + "github.com/rpsoftech/bullion-server/src/interfaces" + "github.com/rpsoftech/bullion-server/src/mongodb/repos" +) type orderGeneralService struct { - eventBus *eventBusService - firebaseDb *firebaseDatabaseService - bullionService *bullionDetailsService - orderRepo *repos.OrderRepoStruct + eventBus *eventBusService + firebaseDb *firebaseDatabaseService + bullionService *bullionDetailsService + groupMapService *tradeUserGroupServiceStruct + orderRepo *repos.OrderRepoStruct + productGroupMapRepo *repos.ProductGroupMapRepoStruct } var OrderGeneralService *orderGeneralService @@ -17,12 +22,48 @@ func init() { func getOrderGeneralService() *orderGeneralService { if OrderGeneralService == nil { OrderGeneralService = &orderGeneralService{ - eventBus: getEventBusService(), - firebaseDb: getFirebaseRealTimeDatabase(), - bullionService: getBullionService(), - orderRepo: repos.OrderRepo, + eventBus: getEventBusService(), + firebaseDb: getFirebaseRealTimeDatabase(), + bullionService: getBullionService(), + groupMapService: getTradeUserGroupService(), + orderRepo: repos.OrderRepo, + productGroupMapRepo: repos.ProductGroupMapRepo, } println("Order General Service Initialized") } return OrderGeneralService } + +func (service *orderGeneralService) ValidateVolumeForGroupMapId(groupMapId string, weight int) (bool, error) { + groupMap, err := service.productGroupMapRepo.FindOne(groupMapId) + if err != nil { + return false, err + } + if !groupMap.ValidateVolume(weight) { + return false, &interfaces.RequestError{ + StatusCode: 400, + Code: interfaces.ERROR_INVALID_VOLUME, + Message: "Invalid Volume", + Name: "INVALID_REQUEST", + } + } + return true, nil +} + +func (service *orderGeneralService) ValidationOfGroupMapIdAndOrder(groupMapId string, userId string, weight int) (bool, error) { + groupMap, err := service.productGroupMapRepo.FindOne(groupMapId) + + if err != nil { + return false, err + } + + if !groupMap.ValidateVolume(weight) { + return false, &interfaces.RequestError{ + StatusCode: 400, + Code: interfaces.ERROR_INVALID_VOLUME, + Message: "Invalid Volume", + Name: "INVALID_REQUEST", + } + } + return true, nil +} From 0dcb7eb63cdd637e34cd6d3a37ab41a014537a00 Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Mon, 18 Mar 2024 02:38:33 +0530 Subject: [PATCH 09/23] Order Base Validator Added --- src/interfaces/error-code.enum.go | 3 ++ src/services/order-general.service.go | 67 +++++++++++++++++++++------ 2 files changed, 57 insertions(+), 13 deletions(-) diff --git a/src/interfaces/error-code.enum.go b/src/interfaces/error-code.enum.go index 24c11c9..095af08 100644 --- a/src/interfaces/error-code.enum.go +++ b/src/interfaces/error-code.enum.go @@ -37,4 +37,7 @@ const ( ERROR_INVALID_WEIGHT_FOR_DELIVERY = 232 ERROR_INSUFFICIENT_MARGIN = 233 ERROR_INVALID_VOLUME = 234 + ERROR_TRADING_IS_DISABLED = 235 + ERROR_TRADING_IS_DISABLED_FOR_GROUP = 236 + ERROR_TRADING_IS_DISABLED_FOR_PRODUCT = 237 ) diff --git a/src/services/order-general.service.go b/src/services/order-general.service.go index e213bb9..50e2240 100644 --- a/src/services/order-general.service.go +++ b/src/services/order-general.service.go @@ -1,6 +1,8 @@ package services import ( + "net/http" + "github.com/rpsoftech/bullion-server/src/interfaces" "github.com/rpsoftech/bullion-server/src/mongodb/repos" ) @@ -9,6 +11,7 @@ type orderGeneralService struct { eventBus *eventBusService firebaseDb *firebaseDatabaseService bullionService *bullionDetailsService + flagService *FlagServiceStruct groupMapService *tradeUserGroupServiceStruct orderRepo *repos.OrderRepoStruct productGroupMapRepo *repos.ProductGroupMapRepoStruct @@ -26,6 +29,7 @@ func getOrderGeneralService() *orderGeneralService { firebaseDb: getFirebaseRealTimeDatabase(), bullionService: getBullionService(), groupMapService: getTradeUserGroupService(), + flagService: getFlagService(), orderRepo: repos.OrderRepo, productGroupMapRepo: repos.ProductGroupMapRepo, } @@ -34,29 +38,66 @@ func getOrderGeneralService() *orderGeneralService { return OrderGeneralService } -func (service *orderGeneralService) ValidateVolumeForGroupMapId(groupMapId string, weight int) (bool, error) { - groupMap, err := service.productGroupMapRepo.FindOne(groupMapId) - if err != nil { +func (service *orderGeneralService) ValidateUserAndGroupMapWithWeight(user *interfaces.TradeUserEntity, groupMap *interfaces.TradeUserGroupMapEntity, group *interfaces.TradeUserGroupEntity, weight int) (bool, error) { + if !user.IsActive { + return false, &interfaces.RequestError{ + StatusCode: http.StatusUnauthorized, + Code: interfaces.ERROR_PERMISSION_NOT_ALLOWED, + Message: "Account Is Not Active Please Contact Admin", + Name: "ERROR_PERMISSION_NOT_ALLOWED", + } + } + + if flags, err := service.flagService.GetFlags(user.BullionId); err != nil { return false, err + } else if !flags.CanTrade { + return false, &interfaces.RequestError{ + StatusCode: 400, + Code: interfaces.ERROR_TRADING_IS_DISABLED, + Message: "Trading is disabled. Contact User", + Name: "BULLION_NOT_ACTIVE", + } } - if !groupMap.ValidateVolume(weight) { + if !group.IsActive { + return false, &interfaces.RequestError{ + StatusCode: http.StatusUnauthorized, + Code: interfaces.ERROR_PERMISSION_NOT_ALLOWED, + Message: "Group Is Not Active Please Contact Admin", + Name: "ERROR_PERMISSION_NOT_ALLOWED", + } + } + + if !group.CanTrade { return false, &interfaces.RequestError{ StatusCode: 400, - Code: interfaces.ERROR_INVALID_VOLUME, - Message: "Invalid Volume", - Name: "INVALID_REQUEST", + Code: interfaces.ERROR_TRADING_IS_DISABLED_FOR_GROUP, + Message: "Trading is disabled for your group. Contact User", + Name: "GROUP_NOT_ACTIVE", } } - return true, nil -} -func (service *orderGeneralService) ValidationOfGroupMapIdAndOrder(groupMapId string, userId string, weight int) (bool, error) { - groupMap, err := service.productGroupMapRepo.FindOne(groupMapId) + if !groupMap.IsActive { + return false, &interfaces.RequestError{ + StatusCode: http.StatusUnauthorized, + Code: interfaces.ERROR_PERMISSION_NOT_ALLOWED, + Message: "Group Map Is Not Active Please Contact Admin", + Name: "ERROR_PERMISSION_NOT_ALLOWED", + } + } - if err != nil { - return false, err + if !groupMap.CanTrade { + return false, &interfaces.RequestError{ + StatusCode: 400, + Code: interfaces.ERROR_TRADING_IS_DISABLED_FOR_PRODUCT, + Message: "Trading is disabled for your group map. Contact Admin", + Name: "GROUP_NOT_ACTIVE", + } } + return service.validateVolumeForGroupMap(groupMap, weight) +} + +func (service *orderGeneralService) validateVolumeForGroupMap(groupMap *interfaces.TradeUserGroupMapEntity, weight int) (bool, error) { if !groupMap.ValidateVolume(weight) { return false, &interfaces.RequestError{ StatusCode: 400, From 96551b3fd63cc474ec53ba651f59fa7317caafbc Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Tue, 19 Mar 2024 01:29:27 +0530 Subject: [PATCH 10/23] Docker Added --- .dockerignore | 32 +++++++++++ Dockerfile | 78 +++++++++++++++++++++++++++ README.Docker.md | 22 ++++++++ compose.yaml | 77 ++++++++++++++++++++++++++ src/env/index.go | 11 +++- src/env/keys.go | 3 +- src/redis/index.go | 3 +- src/services/order-general.service.go | 4 ++ src/utility/firebase/firebase-app.go | 1 + 9 files changed, 227 insertions(+), 4 deletions(-) create mode 100644 .dockerignore create mode 100644 Dockerfile create mode 100644 README.Docker.md create mode 100644 compose.yaml diff --git a/.dockerignore b/.dockerignore new file mode 100644 index 0000000..e5c60ab --- /dev/null +++ b/.dockerignore @@ -0,0 +1,32 @@ +# Include any files or directories that you don't want to be copied to your +# container here (e.g., local build artifacts, temporary files, etc.). +# +# For more help, visit the .dockerignore file reference guide at +# https://docs.docker.com/go/build-context-dockerignore/ + +**/.DS_Store +**/.classpath +**/.dockerignore +**/.env +**/.git +**/.gitignore +**/.project +**/.settings +**/.toolstarget +**/.vs +**/.vscode +**/*.*proj.user +**/*.dbmdl +**/*.jfm +**/bin +**/charts +**/docker-compose* +**/compose* +**/Dockerfile* +**/node_modules +**/npm-debug.log +**/obj +**/secrets.dev.yaml +**/values.dev.yaml +LICENSE +README.md diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..aaaf910 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,78 @@ +# syntax=docker/dockerfile:1 + +# Comments are provided throughout this file to help you get started. +# If you need more help, visit the Dockerfile reference guide at +# https://docs.docker.com/go/dockerfile-reference/ + +# Want to help us make this template better? Share your feedback here: https://forms.gle/ybq9Krt8jtBL3iCk7 + +################################################################################ +# Create a stage for building the application. +ARG GO_VERSION=1.22.1 +FROM --platform=$BUILDPLATFORM golang:${GO_VERSION} AS build +WORKDIR /src + +# Download dependencies as a separate step to take advantage of Docker's caching. +# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds. +# Leverage bind mounts to go.sum and go.mod to avoid having to copy them into +# the container. +RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=bind,source=go.sum,target=go.sum \ + --mount=type=bind,source=go.mod,target=go.mod \ + go mod download -x + +# This is the architecture you’re building for, which is passed in by the builder. +# Placing it here allows the previous steps to be cached across architectures. +ARG TARGETARCH + +# Build the application. +# Leverage a cache mount to /go/pkg/mod/ to speed up subsequent builds. +# Leverage a bind mount to the current directory to avoid having to copy the +# source code into the container. +RUN --mount=type=cache,target=/go/pkg/mod/ \ + --mount=type=bind,target=. \ + CGO_ENABLED=0 GOARCH=$TARGETARCH go build -o /bin/server . + +################################################################################ +# Create a new stage for running the application that contains the minimal +# runtime dependencies for the application. This often uses a different base +# image from the build stage where the necessary files are copied from the build +# stage. +# +# The example below uses the alpine image as the foundation for running the app. +# By specifying the "latest" tag, it will also use whatever happens to be the +# most recent version of that image when you build your Dockerfile. If +# reproducability is important, consider using a versioned tag +# (e.g., alpine:3.17.2) or SHA (e.g., alpine@sha256:c41ab5c992deb4fe7e5da09f67a8804a46bd0592bfdf0b1847dde0e0889d2bff). +FROM alpine:latest AS final + +# Install any runtime dependencies that are needed to run your application. +# Leverage a cache mount to /var/cache/apk/ to speed up subsequent builds. +RUN --mount=type=cache,target=/var/cache/apk \ + apk --update add \ + ca-certificates \ + tzdata \ + && \ + update-ca-certificates + +# Create a non-privileged user that the app will run under. +# See https://docs.docker.com/go/dockerfile-user-best-practices/ +ARG UID=10001 +RUN adduser \ + --disabled-password \ + --gecos "" \ + --home "/nonexistent" \ + --shell "/sbin/nologin" \ + --no-create-home \ + --uid "${UID}" \ + appuser +USER appuser + +# Copy the executable from the "build" stage. +COPY --from=build /bin/server /bin/ + +# Expose the port that the application listens on. +EXPOSE 5000 + +# What the container should run when it is started. +ENTRYPOINT [ "/bin/server" ] diff --git a/README.Docker.md b/README.Docker.md new file mode 100644 index 0000000..7e31be9 --- /dev/null +++ b/README.Docker.md @@ -0,0 +1,22 @@ +### Building and running your application + +When you're ready, start your application by running: +`docker compose up --build`. + +Your application will be available at http://localhost:5000. + +### Deploying your application to the cloud + +First, build your image, e.g.: `docker build -t myapp .`. +If your cloud uses a different CPU architecture than your development +machine (e.g., you are on a Mac M1 and your cloud provider is amd64), +you'll want to build the image for that platform, e.g.: +`docker build --platform=linux/amd64 -t myapp .`. + +Then, push it to your registry, e.g. `docker push myregistry.com/myapp`. + +Consult Docker's [getting started](https://docs.docker.com/go/get-started-sharing/) +docs for more detail on building and pushing. + +### References +* [Docker's Go guide](https://docs.docker.com/language/golang/) \ No newline at end of file diff --git a/compose.yaml b/compose.yaml new file mode 100644 index 0000000..b860951 --- /dev/null +++ b/compose.yaml @@ -0,0 +1,77 @@ +# Comments are provided throughout this file to help you get started. +# If you need more help, visit the Docker Compose reference guide at +# https://docs.docker.com/go/compose-spec-reference/ + +# Here the instructions define your application as a service called "server". +# This service is built from the Dockerfile in the current directory. +# You can add other services your application may depend on here, such as a +# database or a cache. For examples, see the Awesome Compose repository: +# https://github.com/docker/awesome-compose + +services: + server: + build: + context: . + target: final + env_file: + - path: ./.env + required: true # default + - path: ./override.env + required: false # optional + environment: + - APP_ENV=${APP_ENV} + - PORT=${PORT} + - DB_URL=${DB_URL} + - DB_NAME=${DB_NAME} + - REDIS_DB_HOST=redis + - REDIS_DB_PORT=${REDIS_DB_PORT} + - REDIS_DB_PASSWORD=${REDIS_DB_PASSWORD} + - REDIS_DB_DATABASE=${REDIS_DB_DATABASE} + - ACCESS_TOKEN_KEY=${ACCESS_TOKEN_KEY} + - REFRESH_TOKEN_KEY=${REFRESH_TOKEN_KEY} + - FIREBASE_JSON_STRING=${FIREBASE_JSON_STRING} + - FIREBASE_DATABASE_URL=${FIREBASE_DATABASE_URL} + ports: + - 5000:5000 + + redis: + image: redis:alpine + command: + - '--port ${REDIS_DB_PORT}' + - '--requirepass ${REDIS_DB_PASSWORD}' + ports: + - '${REDIS_DB_PORT}:${REDIS_DB_PORT}' + +# The commented out section below is an example of how to define a PostgreSQL +# database that your application can use. `depends_on` tells Docker Compose to +# start the database before your application. The `db-data` volume persists the +# database data between container restarts. The `db-password` secret is used +# to set the database password. You must create `db/password.txt` and add +# a password of your choosing to it before running `docker compose up`. +# depends_on: +# db: +# condition: service_healthy +# db: +# image: postgres +# restart: always +# user: postgres +# secrets: +# - db-password +# volumes: +# - db-data:/var/lib/postgresql/data +# environment: +# - POSTGRES_DB=example +# - POSTGRES_PASSWORD_FILE=/run/secrets/db-password +# expose: +# - 5432 +# healthcheck: +# test: [ "CMD", "pg_isready" ] +# interval: 10s +# timeout: 5s +# retries: 5 +# volumes: +# db-data: +# secrets: +# db-password: +# file: db/password.txt + diff --git a/src/env/index.go b/src/env/index.go index c5557aa..5ed90f2 100644 --- a/src/env/index.go +++ b/src/env/index.go @@ -13,7 +13,8 @@ type EnvInterface struct { PORT int `json:"PORT" validate:"required,port"` DB_URL string `json:"DB_URL" validate:"required,url"` DB_NAME string `json:"DB_NAME_KEY" validate:"required,min=3"` - REDIS_DB_URL string `json:"REDIS_DB_URL" validate:"required"` + REDIS_DB_HOST string `json:"REDIS_DB_HOST" validate:"required"` + REDIS_DB_PORT int `json:"REDIS_DB_PORT" validate:"required,port"` REDIS_DB_PASSWORD string `json:"REDIS_DB_PASSWORD" validate:"required"` REDIS_DB_DATABASE int `json:"REDIS_DB_DATABASE" validate:"min=0,max=100"` ACCESS_TOKEN_KEY string `json:"ACCESS_TOKEN_KEY" validate:"required,min=100"` @@ -36,12 +37,18 @@ func init() { // ... handle error panic(err) } + redis_DB_PORT, err := strconv.Atoi(os.Getenv(redis_DB_PORT_KEY)) + if err != nil { + // ... handle error + panic(err) + } Env = &EnvInterface{ APP_ENV: appEnv, PORT: PORT, DB_NAME: os.Getenv(db_NAME_KEY), DB_URL: os.Getenv(db_URL_KEY), - REDIS_DB_URL: os.Getenv(redis_DB_URL_KEY), + REDIS_DB_PORT: redis_DB_PORT, + REDIS_DB_HOST: os.Getenv(redis_DB_HOST_KEY), REDIS_DB_PASSWORD: os.Getenv(redis_DB_PASSWORD_KEY), REDIS_DB_DATABASE: redis_DB_DATABASE, ACCESS_TOKEN_KEY: os.Getenv(access_TOKEN_KEY), diff --git a/src/env/keys.go b/src/env/keys.go index 4455976..09115ed 100644 --- a/src/env/keys.go +++ b/src/env/keys.go @@ -8,7 +8,8 @@ const access_TOKEN_KEY = "ACCESS_TOKEN_KEY" const refresh_TOKEN_KEY = "REFRESH_TOKEN_KEY" const firebase_JSON_STRING_KEY = "FIREBASE_JSON_STRING" const firebase_DATABASE_URL_KEY = "FIREBASE_DATABASE_URL" -const redis_DB_URL_KEY = "REDIS_DB_URL" +const redis_DB_HOST_KEY = "REDIS_DB_HOST" +const redis_DB_PORT_KEY = "REDIS_DB_PORT" const redis_DB_PASSWORD_KEY = "REDIS_DB_PASSWORD" const redis_DB_DATABASE_KEY = "REDIS_DB_DATABASE" diff --git a/src/redis/index.go b/src/redis/index.go index 2273870..5734656 100644 --- a/src/redis/index.go +++ b/src/redis/index.go @@ -2,6 +2,7 @@ package redis import ( "context" + "fmt" "time" "github.com/redis/go-redis/v9" @@ -28,7 +29,7 @@ func InitRedisAndRedisClient() *RedisClientStruct { return RedisClient } client := redis.NewClient(&redis.Options{ - Addr: env.Env.REDIS_DB_URL, + Addr: fmt.Sprintf("%v:%d", env.Env.REDIS_DB_HOST, env.Env.REDIS_DB_PORT), Password: env.Env.REDIS_DB_PASSWORD, // no password set DB: env.Env.REDIS_DB_DATABASE, // use default DB }) diff --git a/src/services/order-general.service.go b/src/services/order-general.service.go index 50e2240..d83ac84 100644 --- a/src/services/order-general.service.go +++ b/src/services/order-general.service.go @@ -39,6 +39,8 @@ func getOrderGeneralService() *orderGeneralService { } func (service *orderGeneralService) ValidateUserAndGroupMapWithWeight(user *interfaces.TradeUserEntity, groupMap *interfaces.TradeUserGroupMapEntity, group *interfaces.TradeUserGroupEntity, weight int) (bool, error) { + + // Check for User Activation if !user.IsActive { return false, &interfaces.RequestError{ StatusCode: http.StatusUnauthorized, @@ -51,6 +53,7 @@ func (service *orderGeneralService) ValidateUserAndGroupMapWithWeight(user *inte if flags, err := service.flagService.GetFlags(user.BullionId); err != nil { return false, err } else if !flags.CanTrade { + // Check If Trading Is Disabled return false, &interfaces.RequestError{ StatusCode: 400, Code: interfaces.ERROR_TRADING_IS_DISABLED, @@ -58,6 +61,7 @@ func (service *orderGeneralService) ValidateUserAndGroupMapWithWeight(user *inte Name: "BULLION_NOT_ACTIVE", } } + // Check for Group Activation if !group.IsActive { return false, &interfaces.RequestError{ StatusCode: http.StatusUnauthorized, diff --git a/src/utility/firebase/firebase-app.go b/src/utility/firebase/firebase-app.go index 5036b51..345f6d1 100644 --- a/src/utility/firebase/firebase-app.go +++ b/src/utility/firebase/firebase-app.go @@ -33,6 +33,7 @@ func init() { log.Fatalf("error initializing app: %v\n", err) } firebaseApp = app + log.Print("Firebase App initialized") firebaseDb, err := firebaseApp.DatabaseWithURL(FirebaseCtx, env.Env.FIREBASE_DATABASE_URL) if err != nil { log.Fatalf("error initializing Firebase Database: %v\n", err) From 923a76efed539d33bfbf9f0a37f2563a9c5bc875 Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Thu, 21 Mar 2024 06:54:34 +0530 Subject: [PATCH 11/23] Place Order WIP --- compose.yaml | 2 +- src/interfaces/error-code.enum.go | 1 + src/services/order-general.service.go | 109 ++++++++++++++++++++++---- src/services/trade-user.service.go | 28 +++++-- src/utility/jwt/jwt.go | 4 +- 5 files changed, 116 insertions(+), 28 deletions(-) diff --git a/compose.yaml b/compose.yaml index b860951..424e5dc 100644 --- a/compose.yaml +++ b/compose.yaml @@ -32,7 +32,7 @@ services: - FIREBASE_JSON_STRING=${FIREBASE_JSON_STRING} - FIREBASE_DATABASE_URL=${FIREBASE_DATABASE_URL} ports: - - 5000:5000 + - 5000:${PORT} redis: image: redis:alpine diff --git a/src/interfaces/error-code.enum.go b/src/interfaces/error-code.enum.go index 095af08..260b995 100644 --- a/src/interfaces/error-code.enum.go +++ b/src/interfaces/error-code.enum.go @@ -40,4 +40,5 @@ const ( ERROR_TRADING_IS_DISABLED = 235 ERROR_TRADING_IS_DISABLED_FOR_GROUP = 236 ERROR_TRADING_IS_DISABLED_FOR_PRODUCT = 237 + ERROR_GROUP_MAP_NOT_FOUND = 238 ) diff --git a/src/services/order-general.service.go b/src/services/order-general.service.go index d83ac84..6cf46bb 100644 --- a/src/services/order-general.service.go +++ b/src/services/order-general.service.go @@ -8,13 +8,14 @@ import ( ) type orderGeneralService struct { - eventBus *eventBusService - firebaseDb *firebaseDatabaseService - bullionService *bullionDetailsService - flagService *FlagServiceStruct - groupMapService *tradeUserGroupServiceStruct - orderRepo *repos.OrderRepoStruct - productGroupMapRepo *repos.ProductGroupMapRepoStruct + eventBus *eventBusService + firebaseDb *firebaseDatabaseService + bullionService *bullionDetailsService + flagService *FlagServiceStruct + groupService *tradeUserGroupServiceStruct + orderRepo *repos.OrderRepoStruct + userService *tradeUserServiceStruct + productService *productService } var OrderGeneralService *orderGeneralService @@ -25,20 +26,21 @@ func init() { func getOrderGeneralService() *orderGeneralService { if OrderGeneralService == nil { OrderGeneralService = &orderGeneralService{ - eventBus: getEventBusService(), - firebaseDb: getFirebaseRealTimeDatabase(), - bullionService: getBullionService(), - groupMapService: getTradeUserGroupService(), - flagService: getFlagService(), - orderRepo: repos.OrderRepo, - productGroupMapRepo: repos.ProductGroupMapRepo, + eventBus: getEventBusService(), + firebaseDb: getFirebaseRealTimeDatabase(), + bullionService: getBullionService(), + groupService: getTradeUserGroupService(), + flagService: getFlagService(), + userService: getTradeUserService(), + productService: getProductService(), + orderRepo: repos.OrderRepo, } println("Order General Service Initialized") } return OrderGeneralService } -func (service *orderGeneralService) ValidateUserAndGroupMapWithWeight(user *interfaces.TradeUserEntity, groupMap *interfaces.TradeUserGroupMapEntity, group *interfaces.TradeUserGroupEntity, weight int) (bool, error) { +func (service *orderGeneralService) ValidateUserAndGroupMapWithWeight(user *interfaces.TradeUserEntity, group *interfaces.TradeUserGroupEntity, groupMap *interfaces.TradeUserGroupMapEntity, weight int) (bool, error) { // Check for User Activation if !user.IsActive { @@ -70,7 +72,7 @@ func (service *orderGeneralService) ValidateUserAndGroupMapWithWeight(user *inte Name: "ERROR_PERMISSION_NOT_ALLOWED", } } - + // Check for Group User Can Trade if !group.CanTrade { return false, &interfaces.RequestError{ StatusCode: 400, @@ -80,6 +82,7 @@ func (service *orderGeneralService) ValidateUserAndGroupMapWithWeight(user *inte } } + // Check for Group Map Activation if !groupMap.IsActive { return false, &interfaces.RequestError{ StatusCode: http.StatusUnauthorized, @@ -89,6 +92,7 @@ func (service *orderGeneralService) ValidateUserAndGroupMapWithWeight(user *inte } } + // Check for Group Map Can Trade if !groupMap.CanTrade { return false, &interfaces.RequestError{ StatusCode: 400, @@ -107,8 +111,79 @@ func (service *orderGeneralService) validateVolumeForGroupMap(groupMap *interfac StatusCode: 400, Code: interfaces.ERROR_INVALID_VOLUME, Message: "Invalid Volume", - Name: "INVALID_REQUEST", + Name: "INVALID_VOLUME", } } return true, nil } + +func (service *orderGeneralService) findOrderDetailsAndValidate(userId string, groupId string, groupMapId string, weight int) (*interfaces.TradeUserEntity, *interfaces.TradeUserGroupEntity, *interfaces.TradeUserGroupMapEntity, error) { + // Get User + user, err := service.userService.GetTradeUserById(userId) + if err != nil { + return nil, nil, nil, err + } + + if user.GroupId != groupId { + return nil, nil, nil, &interfaces.RequestError{ + StatusCode: 400, + Code: interfaces.ERROR_PERMISSION_NOT_ALLOWED, + Message: "MissMatch Group Id", + Name: "MISS_MATCH_GROUP_ID", + } + } + // Get Group + group, err := service.groupService.GetGroupByGroupId(groupId, user.BullionId) + if err != nil { + return nil, nil, nil, err + } + + // Get Group Map + groupMaps, err := service.groupService.GetGroupMapByGroupId(groupId, user.BullionId) + if err != nil { + return nil, nil, nil, err + } + var groupMap *interfaces.TradeUserGroupMapEntity + + for _, v := range *groupMaps { + if v.ID == groupMapId { + groupMap = &v + break + } + } + if groupMap == nil { + return nil, nil, nil, &interfaces.RequestError{ + StatusCode: 400, + Code: interfaces.ERROR_GROUP_MAP_NOT_FOUND, + Message: "Group Map Not Found", + Name: "GROUP_MAP_NOT_FOUND", + } + + } + service.ValidateUserAndGroupMapWithWeight(user, group, groupMap, weight) + return user, group, groupMap, nil +} +func (service *orderGeneralService) PlaceOrder(orderType interfaces.OrderStatus, userId string, groupId string, groupMapId string, weight int, price float64, placedBy string) (*interfaces.OrderEntity, error) { + + user, group, groupMap, err := service.findOrderDetailsAndValidate(userId, groupId, groupMapId, weight) + if err != nil { + return nil, err + } + // product + product, err := service.productService.GetProductsById(group.BullionId, groupMap.ProductId) + if err != nil { + return nil, err + } + + // TODO Validate Pricing + + _, err = user.UpdateMarginAfterOrder(weight, product.SourceSymbol) + if err != nil { + return nil, err + } + + // TODO Check Hedging And Place Order + return nil, nil + // return service.orderRepo.PlaceOrder(orderType, user, group, groupMap, price, placedBy) + // return service.orderRepo.PlaceOrder(orderType, user, group, groupMap, price, placedBy) +} diff --git a/src/services/trade-user.service.go b/src/services/trade-user.service.go index e2a96b9..7833f97 100644 --- a/src/services/trade-user.service.go +++ b/src/services/trade-user.service.go @@ -27,15 +27,23 @@ type tradeUserServiceStruct struct { var TradeUserService *tradeUserServiceStruct func init() { - TradeUserService = &tradeUserServiceStruct{ - tradeUserRepo: repos.TradeUserRepo, - accessTokenService: AccessTokenService, - eventBus: getEventBusService(), - firebaseDb: getFirebaseRealTimeDatabase(), - sendMsgService: getSendMsgService(), - bullionService: getBullionService(), - realtimeDatabase: getFirebaseRealTimeDatabase(), + getTradeUserService() +} + +func getTradeUserService() *tradeUserServiceStruct { + if TradeUserService == nil { + TradeUserService = &tradeUserServiceStruct{ + tradeUserRepo: repos.TradeUserRepo, + accessTokenService: AccessTokenService, + eventBus: getEventBusService(), + firebaseDb: getFirebaseRealTimeDatabase(), + sendMsgService: getSendMsgService(), + bullionService: getBullionService(), + realtimeDatabase: getFirebaseRealTimeDatabase(), + } + println("Trade User Service Initialized") } + return TradeUserService } func (service *tradeUserServiceStruct) VerifyAndSendOtpForNewUser(tradeUser *interfaces.TradeUserBase, bullionId string) (*string, error) { @@ -270,6 +278,10 @@ func (service *tradeUserServiceStruct) LoginWithNumberAndPassword(number string, return service.generateTokensForTradeUserWithPasswordMatching(tradeUser, password) } +func (service *tradeUserServiceStruct) GetTradeUserById(id string) (*interfaces.TradeUserEntity, error) { + return service.tradeUserRepo.FindOne(id) +} + func (service *tradeUserServiceStruct) UpdateTradeUser(entity *interfaces.TradeUserEntity, adminId string) error { user, err := service.tradeUserRepo.FindOne(entity.ID) if err != nil { diff --git a/src/utility/jwt/jwt.go b/src/utility/jwt/jwt.go index f3a22e6..d43ef96 100644 --- a/src/utility/jwt/jwt.go +++ b/src/utility/jwt/jwt.go @@ -90,7 +90,7 @@ func (t *TokenService) VerifyToken(token string) (*GeneralUserAccessRefreshToken } claim, ok := claimRaw.Claims.(*GeneralUserAccessRefreshToken) - if !ok && err == nil { + if !ok { err = &interfaces.RequestError{ StatusCode: 401, Code: interfaces.ERROR_INVALID_TOKEN, @@ -155,7 +155,7 @@ func (t *TokenService) VerifyTokenGeneralPurpose(token string) (*GeneralPurposeT } claim, ok := claimRaw.Claims.(*GeneralPurposeTokenGeneration) - if !ok && err == nil { + if !ok { err = &interfaces.RequestError{ StatusCode: 401, Code: interfaces.ERROR_INVALID_TOKEN, From 82bef791caa272b4fca104543a41e58c155e1da6 Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Thu, 21 Mar 2024 08:15:36 +0530 Subject: [PATCH 12/23] Last Rate Reader Added From Redis --- src/interfaces/base-symbol.enum.go | 6 +-- src/interfaces/general-type.go | 3 ++ src/interfaces/price-key.enum.go | 83 ++++++++++++++++++++++++++++++ src/redis/index.go | 3 ++ src/services/live-rate.service.go | 50 ++++++++++++++++++ 5 files changed, 142 insertions(+), 3 deletions(-) create mode 100644 src/interfaces/general-type.go create mode 100644 src/interfaces/price-key.enum.go create mode 100644 src/services/live-rate.service.go diff --git a/src/interfaces/base-symbol.enum.go b/src/interfaces/base-symbol.enum.go index 4763d0d..1a63f4f 100644 --- a/src/interfaces/base-symbol.enum.go +++ b/src/interfaces/base-symbol.enum.go @@ -20,12 +20,12 @@ var ( symbolEnumMap = EnumValidatorBase{ Data: map[string]interface{}{ "GOLD": SYMBOL_GOLD, - "SILVER": SYMBOL_SILVER, "GOLD_MCX": SYMBOL_GOLD_MCX, - "SILVER_MCX": SYMBOL_SILVER_MCX, + "GOLD_SPOT": SYMBOL_GOLD_SPOT, "GOLD_NEXT": SYMBOL_GOLD_NEXT, + "SILVER": SYMBOL_SILVER, + "SILVER_MCX": SYMBOL_SILVER_MCX, "SILVER_NEXT": SYMBOL_SILVER_NEXT, - "GOLD_SPOT": SYMBOL_GOLD_SPOT, "SILVER_SPOT": SYMBOL_SILVER_SPOT, "INR": SYMBOL_INR, }, diff --git a/src/interfaces/general-type.go b/src/interfaces/general-type.go new file mode 100644 index 0000000..f72e678 --- /dev/null +++ b/src/interfaces/general-type.go @@ -0,0 +1,3 @@ +package interfaces + +type LiveRateData map[SymbolsEnum]map[PriceKeyEnum]float64 diff --git a/src/interfaces/price-key.enum.go b/src/interfaces/price-key.enum.go new file mode 100644 index 0000000..b8ada4d --- /dev/null +++ b/src/interfaces/price-key.enum.go @@ -0,0 +1,83 @@ +package interfaces + +import "github.com/rpsoftech/bullion-server/src/validator" + +type PriceKeyEnum string + +const ( + PRICE_KEY_BID_HIGH PriceKeyEnum = "bid-high" + PRICE_KEY_BID_LOW PriceKeyEnum = "bid-low" + PRICE_KEY_ASK_HIGH PriceKeyEnum = "ask-high" + PRICE_KEY_ASK_LOW PriceKeyEnum = "ask-low" + PRICE_KEY_LAST_HIGH PriceKeyEnum = "last-high" + PRICE_KEY_LAST_LOW PriceKeyEnum = "last-low" + PRICE_BID PriceKeyEnum = "bid" + PRICE_ASK PriceKeyEnum = "ask" + PRICE_OPEN PriceKeyEnum = "open" + PRICE_CLOSE PriceKeyEnum = "close" +) + +var ( + priceKeyEnumMap = EnumValidatorBase{ + Data: map[string]interface{}{ + "bid-high": PRICE_KEY_BID_HIGH, + "bid-low": PRICE_KEY_BID_LOW, + "ask-high": PRICE_KEY_ASK_HIGH, + "ask-low": PRICE_KEY_ASK_LOW, + "last-high": PRICE_KEY_LAST_HIGH, + "last-low": PRICE_KEY_LAST_LOW, + "bid": PRICE_BID, + "ask": PRICE_ASK, + "open": PRICE_OPEN, + "close": PRICE_CLOSE, + }, + } +) + +func init() { + validator.RegisterEnumValidatorFunc("PriceKeyEnum", priceKeyEnumMap.Validate) +} + +func (s PriceKeyEnum) String() string { + switch s { + case PRICE_KEY_BID_HIGH: + return "bid-high" + case PRICE_KEY_BID_LOW: + return "bid-low" + case PRICE_KEY_ASK_HIGH: + return "ask-high" + case PRICE_KEY_ASK_LOW: + return "ask-low" + case PRICE_KEY_LAST_HIGH: + return "last-high" + case PRICE_KEY_LAST_LOW: + return "last-low" + case PRICE_BID: + return "bid" + case PRICE_ASK: + return "ask" + case PRICE_OPEN: + return "open" + case PRICE_CLOSE: + return "close" + } + return "unknown" +} + +func (s PriceKeyEnum) IsValid() bool { + switch s { + case + PRICE_KEY_BID_HIGH, + PRICE_KEY_BID_LOW, + PRICE_KEY_ASK_HIGH, + PRICE_KEY_ASK_LOW, + PRICE_KEY_LAST_HIGH, + PRICE_KEY_LAST_LOW, + PRICE_BID, + PRICE_ASK, + PRICE_OPEN, + PRICE_CLOSE: + return true + } + return false +} diff --git a/src/redis/index.go b/src/redis/index.go index 5734656..1a67db2 100644 --- a/src/redis/index.go +++ b/src/redis/index.go @@ -59,6 +59,9 @@ func (r *RedisClientStruct) PublishEvent(event *events.BaseEvent) { func (r *RedisClientStruct) GetStringData(key string) string { return r.redisClient.Get(RedisCTX, key).Val() } +func (r *RedisClientStruct) GetByteData(key string) ([]byte, error) { + return r.redisClient.Get(RedisCTX, key).Bytes() +} func (r *RedisClientStruct) RemoveKey(key ...string) { r.redisClient.Del(RedisCTX, key...) diff --git a/src/services/live-rate.service.go b/src/services/live-rate.service.go new file mode 100644 index 0000000..25bf47f --- /dev/null +++ b/src/services/live-rate.service.go @@ -0,0 +1,50 @@ +package services + +import ( + "encoding/json" + "time" + + "github.com/rpsoftech/bullion-server/src/interfaces" + "github.com/rpsoftech/bullion-server/src/redis" +) + +type LiveRateService struct { + redisRepo *redis.RedisClientStruct + LastRateMap interfaces.LiveRateData +} + +var LiveRateServiceInstance *LiveRateService + +func init() { + service := getLiveRateService() + service.lastRateReaderFromRedis() +} + +func getLiveRateService() *LiveRateService { + if LiveRateServiceInstance == nil { + LiveRateServiceInstance = &LiveRateService{ + redisRepo: redis.InitRedisAndRedisClient(), + LastRateMap: make(map[interfaces.SymbolsEnum]map[interfaces.PriceKeyEnum]float64), + } + println("Live Rate Service Initialized") + } + return LiveRateServiceInstance +} + +func (s *LiveRateService) GetLastRate() *interfaces.LiveRateData { + return &s.LastRateMap +} + +func (s *LiveRateService) lastRateReaderFromRedis() { + println("Reading Last Rate From Redis Started") + go func() { + for { + data, err := s.redisRepo.GetByteData("LastRate") + // s.LastRateMap = res + if err != nil && len(data) > 0 { + json.Unmarshal(data, &s.LastRateMap) + } + time.Sleep(5 * time.Second) + } + }() +} From ec0695246b2d691b49c689547aff0c34b326328b Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Mon, 25 Mar 2024 21:37:41 +0530 Subject: [PATCH 13/23] Spot Price Calculation Added And CRUD Added --- main.go | 2 +- src/apis/data/index.go | 1 + .../data/product/add-update-bank-calc.api.go | 35 ++++++ src/apis/data/product/get-bank-calc.api.go | 31 ++++++ src/apis/data/product/get-live.rate.api.go | 10 ++ src/apis/data/product/index.go | 6 + src/events/bank-rate-calc.event.go | 29 +++++ src/interfaces/bank-rate.calc.entity.go | 35 ++++++ src/interfaces/base-symbol.enum.go | 21 ++++ src/interfaces/order-entity.interface.go | 1 + src/mongodb/repos/bank-rate-calc.repo.go | 103 ++++++++++++++++++ src/mongodb/repos/trade-user.repo.go | 13 +-- src/redis/index.go | 11 +- src/services/bank-rate-cacl.service.go | 57 ++++++++++ src/services/general-user.service.go | 5 +- src/services/live-rate.service.go | 62 ++++++++--- src/services/trade-user.service.go | 13 ++- 17 files changed, 405 insertions(+), 30 deletions(-) create mode 100644 src/apis/data/product/add-update-bank-calc.api.go create mode 100644 src/apis/data/product/get-bank-calc.api.go create mode 100644 src/apis/data/product/get-live.rate.api.go create mode 100644 src/events/bank-rate-calc.event.go create mode 100644 src/interfaces/bank-rate.calc.entity.go create mode 100644 src/mongodb/repos/bank-rate-calc.repo.go create mode 100644 src/services/bank-rate-cacl.service.go diff --git a/main.go b/main.go index d669fd7..ca9dd80 100644 --- a/main.go +++ b/main.go @@ -41,7 +41,7 @@ func main() { return c.Status(mappedError.StatusCode).JSON(mappedError) }, }) - + // TODO Add middleware to recover from panics https://docs.gofiber.io/api/middleware/recover app.Use(logger.New()) app.Use(middleware.TokenDecrypter) diff --git a/src/apis/data/index.go b/src/apis/data/index.go index c29e8c9..ebd2efe 100644 --- a/src/apis/data/index.go +++ b/src/apis/data/index.go @@ -14,6 +14,7 @@ import ( func AddDataPackage(router fiber.Router) { router.Use(middleware.AllowOnlyValidTokenMiddleWare) router.Use(middleware.AllowAllUsers.Validate) + product.AddRateApi(router.Group("/rates")) { productGroup := router.Group("/product") product.AddProduct(productGroup) diff --git a/src/apis/data/product/add-update-bank-calc.api.go b/src/apis/data/product/add-update-bank-calc.api.go new file mode 100644 index 0000000..f1539c8 --- /dev/null +++ b/src/apis/data/product/add-update-bank-calc.api.go @@ -0,0 +1,35 @@ +package product + +import ( + "github.com/gofiber/fiber/v2" + "github.com/rpsoftech/bullion-server/src/interfaces" + "github.com/rpsoftech/bullion-server/src/services" + "github.com/rpsoftech/bullion-server/src/utility" +) + +type apiAddUpdateBankCalcBody struct { + GOLD_SPOT *interfaces.BankRateCalcBase `bson:"goldSpot" json:"goldSpot" validate:"required"` + SILVER_SPOT *interfaces.BankRateCalcBase `bson:"silverSpot" json:"silverSpot" validate:"required"` +} + +func apiAddUpdateBankCalc(c *fiber.Ctx) error { + body := new(apiAddUpdateBankCalcBody) + c.BodyParser(body) + if err := utility.ValidateReqInput(body); err != nil { + return err + } + userId, err := interfaces.ExtractTokenUserIdFromCtx(c) + if err != nil { + return err + } + bullionId, err := interfaces.ExtractBullionIdFromCtx(c) + if err != nil { + return err + } + entity, err := services.BankRateCalcService.SaveBankRateCalc(body.GOLD_SPOT, body.SILVER_SPOT, bullionId, userId) + if err != nil { + return err + } else { + return c.JSON(entity) + } +} diff --git a/src/apis/data/product/get-bank-calc.api.go b/src/apis/data/product/get-bank-calc.api.go new file mode 100644 index 0000000..94d6e01 --- /dev/null +++ b/src/apis/data/product/get-bank-calc.api.go @@ -0,0 +1,31 @@ +package product + +import ( + "net/http" + + "github.com/gofiber/fiber/v2" + "github.com/rpsoftech/bullion-server/src/interfaces" + "github.com/rpsoftech/bullion-server/src/services" +) + +func apiGetBankCalc(c *fiber.Ctx) error { + + id := c.Query("bullionId") + if id == "" { + return &interfaces.RequestError{ + StatusCode: http.StatusBadRequest, + Code: interfaces.ERROR_INVALID_INPUT, + Message: "Please Pass Valid Bullion Id", + Name: "INVALID_INPUT", + } + } + if err := interfaces.ValidateBullionIdMatchingInToken(c, id); err != nil { + return err + } + entity, err := services.BankRateCalcService.GetBankRateCalcByBullionId(id) + if err != nil { + return err + } else { + return c.JSON(entity) + } +} diff --git a/src/apis/data/product/get-live.rate.api.go b/src/apis/data/product/get-live.rate.api.go new file mode 100644 index 0000000..33e5480 --- /dev/null +++ b/src/apis/data/product/get-live.rate.api.go @@ -0,0 +1,10 @@ +package product + +import ( + "github.com/gofiber/fiber/v2" + "github.com/rpsoftech/bullion-server/src/services" +) + +func apiGetLiveRate(c *fiber.Ctx) error { + return c.JSON(services.LiveRateService.LastRateMap) +} diff --git a/src/apis/data/product/index.go b/src/apis/data/product/index.go index 651f306..d4f6491 100644 --- a/src/apis/data/product/index.go +++ b/src/apis/data/product/index.go @@ -8,9 +8,15 @@ import ( func AddProduct(router fiber.Router) { router.Get("/getAll", apiGetProducts) router.Get("/getProduct", apiGetProducts) + router.Get("/getBankCalc", apiGetBankCalc) adminGroup := router.Use(middleware.AllowAllAdmins.Validate) adminGroup.Put("/add", apiAddNewProduct) adminGroup.Patch("/update", apiUpdateProducts) adminGroup.Patch("/updateCalcSnapShot", apiUpdateProductCalcSnapshot) adminGroup.Patch("/updateSequence", apiUpdateProductSequence) + adminGroup.Patch("/updateBankCalc", apiAddUpdateBankCalc) +} + +func AddRateApi(router fiber.Router) { + router.Get("/", apiGetLiveRate) } diff --git a/src/events/bank-rate-calc.event.go b/src/events/bank-rate-calc.event.go new file mode 100644 index 0000000..f138924 --- /dev/null +++ b/src/events/bank-rate-calc.event.go @@ -0,0 +1,29 @@ +package events + +import ( + "github.com/rpsoftech/bullion-server/src/interfaces" +) + +type bankRateCalcEvent struct { + *BaseEvent `bson:"inline"` +} + +func (base *bankRateCalcEvent) Add() *bankRateCalcEvent { + base.ParentNames = []string{base.EventName, "BankRateCalcEvent"} + base.BaseEvent.CreateBaseEvent() + return base +} + +func BankRateCalcUpdatedEvent(entity *interfaces.BankRateCalcEntity, adminId string) *BaseEvent { + event := &bankRateCalcEvent{ + BaseEvent: &BaseEvent{ + BullionId: entity.BullionId, + KeyId: entity.ID, + AdminId: adminId, + Payload: entity, + EventName: "BankRateCalcUpdatedEvent", + }, + } + event.Add() + return event.BaseEvent +} diff --git a/src/interfaces/bank-rate.calc.entity.go b/src/interfaces/bank-rate.calc.entity.go new file mode 100644 index 0000000..5cf66c7 --- /dev/null +++ b/src/interfaces/bank-rate.calc.entity.go @@ -0,0 +1,35 @@ +package interfaces + +type ( + BankRateCalcEntity struct { + *BaseEntity `bson:"inline"` + BullionId string `bson:"bullionId" json:"bullionId" validate:"required,uuid"` + GOLD_SPOT *BankRateCalcBase `bson:"goldSpot" json:"goldSpot" validate:"required"` + SILVER_SPOT *BankRateCalcBase `bson:"silverSpot" json:"silverSpot" validate:"required"` + } + + BankRateCalcBase struct { + Premium float64 `bson:"premium" json:"premium" validate:"min=-1000,max=1000"` + Conv float64 `bson:"conv" json:"conv" validate:"required,min=0.1,max=1000"` + Duty int `bson:"duty" json:"duty" validate:"min=0"` + Margin int `bson:"margin" json:"margin" validate:"min=0"` + Gst int `bson:"gst" json:"gst" validate:"min=0,max=100"` + DivBy int `bson:"divBy" json:"divBy" validate:"min=1,max=100"` + MultiBy int `bson:"multiBy" json:"multiBy" validate:"min=1,max=100"` + } +) + +func (b *BankRateCalcBase) CalculatePrice(symbolPrice, inrPrice float64) float64 { + premium, conv, margin, duty, gst, divBy, multiBy := b.Premium, b.Conv, float64(b.Margin), float64(b.Duty), float64(b.Gst), float64(b.DivBy), float64(b.MultiBy) + finalPrice := (symbolPrice + premium) * conv * inrPrice + finalPrice += margin + duty + finalPrice *= 1 + gst/100 + finalPrice /= divBy + return finalPrice * multiBy +} + +func (b *BankRateCalcEntity) CreateNewBankRateCalc() *BankRateCalcEntity { + b.BaseEntity = &BaseEntity{} + b.createNewId() + return b +} diff --git a/src/interfaces/base-symbol.enum.go b/src/interfaces/base-symbol.enum.go index 1a63f4f..66526e8 100644 --- a/src/interfaces/base-symbol.enum.go +++ b/src/interfaces/base-symbol.enum.go @@ -16,6 +16,18 @@ const ( SYMBOL_INR SymbolsEnum = "INR" ) +var SymbolsEnumArray = []SymbolsEnum{ + SYMBOL_GOLD, + SYMBOL_SILVER, + SYMBOL_GOLD_MCX, + SYMBOL_SILVER_MCX, + SYMBOL_GOLD_NEXT, + SYMBOL_SILVER_NEXT, + SYMBOL_GOLD_SPOT, + SYMBOL_SILVER_SPOT, + SYMBOL_INR, +} + var ( symbolEnumMap = EnumValidatorBase{ Data: map[string]interface{}{ @@ -35,6 +47,15 @@ var ( func init() { validator.RegisterEnumValidatorFunc("SymbolsEnum", symbolEnumMap.Validate) } + +func SymbolsEnumFromString(d string) SymbolsEnum { + enumValue := symbolEnumMap.Data[d] + if enumValue != nil { + return enumValue.(SymbolsEnum) + } + return "" +} + func (s SymbolsEnum) String() string { switch s { case SYMBOL_GOLD: diff --git a/src/interfaces/order-entity.interface.go b/src/interfaces/order-entity.interface.go index a32ec9b..82d99c6 100644 --- a/src/interfaces/order-entity.interface.go +++ b/src/interfaces/order-entity.interface.go @@ -41,6 +41,7 @@ type ( CalcSnapShot *CalcSnapshotStruct `json:"calcSnapShot" bson:"calcSnapShot" validate:"required"` CalcSnapShotId string `json:"calcSnapShotId" bson:"calcSnapShotId" validate:"required,uuid"` PgmSnapShot *GroupPremiumBase `json:"pgmSnapShot" bson:"pgmSnapShot" validate:"required"` + BankRateCalc *BankRateCalcBase `json:"bankRateCalc" bson:"bankRateCalc"` McxPrice float64 `json:"mcxPrice" bson:"mcxPrice" validate:"required"` ExecutedOn time.Time `json:"executedOn" bson:"executedOn" validate:"required"` McxOrderJSON interface{} `json:"mcxOrder,omitempty" bson:"mcxOrder,omitempty"` diff --git a/src/mongodb/repos/bank-rate-calc.repo.go b/src/mongodb/repos/bank-rate-calc.repo.go new file mode 100644 index 0000000..fd53733 --- /dev/null +++ b/src/mongodb/repos/bank-rate-calc.repo.go @@ -0,0 +1,103 @@ +package repos + +import ( + "encoding/json" + "errors" + "fmt" + "net/http" + "time" + + "github.com/rpsoftech/bullion-server/src/env" + "github.com/rpsoftech/bullion-server/src/interfaces" + "github.com/rpsoftech/bullion-server/src/mongodb" + "github.com/rpsoftech/bullion-server/src/redis" + "go.mongodb.org/mongo-driver/bson" + "go.mongodb.org/mongo-driver/mongo" +) + +type BankRateCalcRepoStruct struct { + collection *mongo.Collection + redis *redis.RedisClientStruct + // historyCollection *mongo.Collection +} + +const bankRateCalcRepoCollectionName = "BankRateCalc" +const bankRateRedisCollection = "bankRate" + +// const bankRateCalcHistoryRepoCollectionName = "BankRateCalcHistory" + +var BankRateCalcRepo *BankRateCalcRepoStruct + +func init() { + if env.Env.APP_ENV == env.APP_ENV_DEVELOPE { + return + } + coll := mongodb.MongoDatabase.Collection(bankRateCalcRepoCollectionName) + BankRateCalcRepo = &BankRateCalcRepoStruct{ + collection: coll, + redis: redis.InitRedisAndRedisClient(), + } + addUniqueIndexesToCollection([]string{"id", "bullionId"}, BankRateCalcRepo.collection) +} + +func (repo *BankRateCalcRepoStruct) cacheDataToRedis(entity *interfaces.BankRateCalcEntity) { + if entityStringBytes, err := json.Marshal(entity); err == nil { + entityString := string(entityStringBytes) + repo.redis.SetStringDataWithExpiry(fmt.Sprintf("%s/%s", bankRateRedisCollection, entity.BullionId), entityString, time.Duration(24)*time.Hour) + } +} + +func (repo *BankRateCalcRepoStruct) Save(entity *interfaces.BankRateCalcEntity) (*interfaces.BankRateCalcEntity, error) { + var result interfaces.BankRateCalcEntity + err := repo.collection.FindOneAndUpdate(mongodb.MongoCtx, bson.D{{ + Key: "_id", Value: entity.ID, + }}, bson.D{{Key: "$set", Value: entity}}, findOneAndUpdateOptions).Decode(&result) + entity.Updated() + if err != nil { + if !errors.Is(err, mongo.ErrNoDocuments) { + err = &interfaces.RequestError{ + StatusCode: 500, + Code: interfaces.ERROR_INTERNAL_SERVER, + Message: fmt.Sprintf("Internal Server Error: %s", err.Error()), + Name: "INTERNAL_ERROR", + } + } else { + err = nil + } + } + go repo.cacheDataToRedis(entity) + return &result, err +} + +func (repo *BankRateCalcRepoStruct) FindOneByBullionId(id string) (*interfaces.BankRateCalcEntity, error) { + result := new(interfaces.BankRateCalcEntity) + if redisData := repo.redis.GetStringData(fmt.Sprintf("%s/%s", bankRateRedisCollection, id)); redisData != "" { + if err := json.Unmarshal([]byte(redisData), result); err == nil { + return result, err + } + } + err := repo.collection.FindOne(mongodb.MongoCtx, bson.D{{ + Key: "bullionId", Value: id, + }}).Decode(result) + + if err != nil { + if errors.Is(err, mongo.ErrNoDocuments) { + // This error means your query did not match any documents. + err = &interfaces.RequestError{ + StatusCode: http.StatusBadRequest, + Code: interfaces.ERROR_ENTITY_NOT_FOUND, + Message: fmt.Sprintf("Bullion Entity identified by id %s not found", id), + Name: "ENTITY_NOT_FOUND", + } + } else { + err = &interfaces.RequestError{ + StatusCode: 500, + Code: interfaces.ERROR_INTERNAL_SERVER, + Message: fmt.Sprintf("Internal Server Error: %s", err.Error()), + Name: "INTERNAL_ERROR", + } + } + } + go repo.cacheDataToRedis(result) + return result, err +} diff --git a/src/mongodb/repos/trade-user.repo.go b/src/mongodb/repos/trade-user.repo.go index 00f4122..82f4b81 100644 --- a/src/mongodb/repos/trade-user.repo.go +++ b/src/mongodb/repos/trade-user.repo.go @@ -134,16 +134,15 @@ func (repo *TradeUserRepoStruct) findByFilter(filter *mongoDbFilter) (*[]interfa } func (repo *TradeUserRepoStruct) FindOne(id string) (*interfaces.TradeUserEntity, error) { - var result interfaces.TradeUserEntity + result := new(interfaces.TradeUserEntity) if redisData := repo.redis.GetStringData(fmt.Sprintf("tradeUser/%s", id)); redisData != "" { - entity := new(interfaces.TradeUserEntity) - if err := json.Unmarshal([]byte(redisData), entity); err == nil { - return entity, err + if err := json.Unmarshal([]byte(redisData), result); err == nil { + return result, err } } err := repo.collection.FindOne(mongodb.MongoCtx, bson.D{{ Key: "id", Value: id, - }}).Decode(&result) + }}).Decode(result) if err != nil { if errors.Is(err, mongo.ErrNoDocuments) { @@ -163,8 +162,8 @@ func (repo *TradeUserRepoStruct) FindOne(id string) (*interfaces.TradeUserEntity } } } - go repo.cacheDataToRedis(&result) - return &result, err + go repo.cacheDataToRedis(result) + return result, err } func (repo *TradeUserRepoStruct) cacheDataToRedis(entity *interfaces.TradeUserEntity) { diff --git a/src/redis/index.go b/src/redis/index.go index 1a67db2..a4d037a 100644 --- a/src/redis/index.go +++ b/src/redis/index.go @@ -22,6 +22,7 @@ func init() { if env.Env.APP_ENV == env.APP_ENV_DEVELOPE { return } + // RedisClient.redisClient.Subscribe() } func InitRedisAndRedisClient() *RedisClientStruct { @@ -53,15 +54,19 @@ func DeferFunction() { } } +func (r *RedisClientStruct) SubscribeToChannels(channels ...string) *redis.PubSub { + return r.redisClient.Subscribe(RedisCTX, channels...) +} + func (r *RedisClientStruct) PublishEvent(event *events.BaseEvent) { r.redisClient.Publish(RedisCTX, event.GetEventName(), event.GetPayloadString()) } +func (r *RedisClientStruct) GetHashValue(key string) map[string]string { + return r.redisClient.HGetAll(RedisCTX, key).Val() +} func (r *RedisClientStruct) GetStringData(key string) string { return r.redisClient.Get(RedisCTX, key).Val() } -func (r *RedisClientStruct) GetByteData(key string) ([]byte, error) { - return r.redisClient.Get(RedisCTX, key).Bytes() -} func (r *RedisClientStruct) RemoveKey(key ...string) { r.redisClient.Del(RedisCTX, key...) diff --git a/src/services/bank-rate-cacl.service.go b/src/services/bank-rate-cacl.service.go new file mode 100644 index 0000000..b47f3a4 --- /dev/null +++ b/src/services/bank-rate-cacl.service.go @@ -0,0 +1,57 @@ +package services + +import ( + "github.com/rpsoftech/bullion-server/src/events" + "github.com/rpsoftech/bullion-server/src/interfaces" + "github.com/rpsoftech/bullion-server/src/mongodb/repos" +) + +type bankRateService struct { + bankRateRepo *repos.BankRateCalcRepoStruct + eventBus *eventBusService + firebaseDatabaseService *firebaseDatabaseService +} + +var BankRateCalcService *bankRateService + +func init() { + getBankRateService() +} + +func getBankRateService() *bankRateService { + if BankRateCalcService == nil { + BankRateCalcService = &bankRateService{ + eventBus: getEventBusService(), + bankRateRepo: repos.BankRateCalcRepo, + firebaseDatabaseService: getFirebaseRealTimeDatabase(), + } + println("Bank Rate Service Initialized") + } + return BankRateCalcService +} + +func (service *bankRateService) GetBankRateCalcByBullionId(bullionId string) (*interfaces.BankRateCalcEntity, error) { + return service.bankRateRepo.FindOneByBullionId(bullionId) +} + +func (service *bankRateService) SaveBankRateCalc(gold *interfaces.BankRateCalcBase, silver *interfaces.BankRateCalcBase, bullionId string, adminId string) (*interfaces.BankRateCalcEntity, error) { + entity, err := service.GetBankRateCalcByBullionId(bullionId) + if err != nil { + entity = &interfaces.BankRateCalcEntity{ + BullionId: bullionId, + GOLD_SPOT: gold, + SILVER_SPOT: silver, + } + entity.CreateNewBankRateCalc() + } else { + entity.GOLD_SPOT = gold + entity.SILVER_SPOT = silver + } + _, err = service.bankRateRepo.Save(entity) + if err != nil { + return nil, err + } + service.eventBus.Publish(events.BankRateCalcUpdatedEvent(entity, adminId)) + service.firebaseDatabaseService.SetPublicData(bullionId, []string{"bankRateCalc"}, entity) + return entity, nil +} diff --git a/src/services/general-user.service.go b/src/services/general-user.service.go index fc71bed..fe5986e 100644 --- a/src/services/general-user.service.go +++ b/src/services/general-user.service.go @@ -69,7 +69,10 @@ func (service *generalUserService) RegisterNew(bullionId string, user interface{ return nil, err } - service.GeneralUserRepo.Save(entity) + _, err = service.GeneralUserRepo.Save(entity) + if err != nil { + return nil, err + } _, err = service.sendApprovalRequest(entity, Bullion) if err != nil { diff --git a/src/services/live-rate.service.go b/src/services/live-rate.service.go index 25bf47f..8d52498 100644 --- a/src/services/live-rate.service.go +++ b/src/services/live-rate.service.go @@ -8,43 +8,75 @@ import ( "github.com/rpsoftech/bullion-server/src/redis" ) -type LiveRateService struct { +type liveRateServiceStruct struct { redisRepo *redis.RedisClientStruct LastRateMap interfaces.LiveRateData } -var LiveRateServiceInstance *LiveRateService +var LiveRateService *liveRateServiceStruct func init() { service := getLiveRateService() service.lastRateReaderFromRedis() + service.subscribeToRedisForRate() } -func getLiveRateService() *LiveRateService { - if LiveRateServiceInstance == nil { - LiveRateServiceInstance = &LiveRateService{ +func getLiveRateService() *liveRateServiceStruct { + if LiveRateService == nil { + LiveRateService = &liveRateServiceStruct{ redisRepo: redis.InitRedisAndRedisClient(), - LastRateMap: make(map[interfaces.SymbolsEnum]map[interfaces.PriceKeyEnum]float64), + LastRateMap: make(interfaces.LiveRateData), + } + for _, k := range interfaces.SymbolsEnumArray { + LiveRateService.LastRateMap[k] = make(map[interfaces.PriceKeyEnum]float64) } println("Live Rate Service Initialized") } - return LiveRateServiceInstance + return LiveRateService } -func (s *LiveRateService) GetLastRate() *interfaces.LiveRateData { +func (s *liveRateServiceStruct) GetLastRate() *interfaces.LiveRateData { return &s.LastRateMap } -func (s *LiveRateService) lastRateReaderFromRedis() { - println("Reading Last Rate From Redis Started") +func (s *liveRateServiceStruct) lastRateReaderFromRedis() { go func() { for { - data, err := s.redisRepo.GetByteData("LastRate") - // s.LastRateMap = res - if err != nil && len(data) > 0 { - json.Unmarshal(data, &s.LastRateMap) + data := s.redisRepo.GetHashValue("LastRate") + for keyString, value := range data { + key := interfaces.SymbolsEnumFromString(keyString) + if key != "" { + symbolMap := s.LastRateMap[key] + json.Unmarshal([]byte(value), &symbolMap) + } + } + time.Sleep(15 * time.Second) + } + }() +} + +// SubscribeToRedisForRate subscribes to the minirate Redis channel and +// updates the live rate service with the latest data from Redis. +func (s *liveRateServiceStruct) subscribeToRedisForRate() { + psc := redis.RedisClient.SubscribeToChannels("minirate") + + go func() { + // Listen to messages from the Redis channel + for msg := range psc.Channel() { + // Unmarshal the JSON data from the Redis message payload + data := new(interfaces.LiveRateData) + if err := json.Unmarshal([]byte(msg.Payload), data); err == nil { + // Loop through each symbol in the data + for symbol, rates := range *data { + // If the symbol does not already exist in the live rate map + // Add the symbol and its rates to the live rate map + if _, ok := s.LastRateMap[symbol]; ok { + for priceKey, v1 := range rates { + s.LastRateMap[symbol][priceKey] = v1 + } + } + } } - time.Sleep(5 * time.Second) } }() } diff --git a/src/services/trade-user.service.go b/src/services/trade-user.service.go index 7833f97..316a1dd 100644 --- a/src/services/trade-user.service.go +++ b/src/services/trade-user.service.go @@ -217,7 +217,9 @@ func (service *tradeUserServiceStruct) RegisterNewTradeUser(base *interfaces.Tra if err := utility.ValidateReqInput(entity); err != nil { return nil, err } - service.tradeUserRepo.Save(entity) + if _, err := service.tradeUserRepo.Save(entity); err != nil { + return nil, err + } service.firebaseDb.setPrivateData("tradeUsersNumbers", []string{entity.BullionId}, newUserNumber) go service.afterSuccessFullRegistration(entity.ID) return entity, nil @@ -298,7 +300,9 @@ func (service *tradeUserServiceStruct) UpdateTradeUser(entity *interfaces.TradeU user.TradeUserBase = entity.TradeUserBase user.TradeUserAdvanced.IsActive = entity.TradeUserAdvanced.IsActive user.TradeUserMargins = entity.TradeUserMargins - service.tradeUserRepo.Save(user) + if _, err := service.tradeUserRepo.Save(entity); err != nil { + return err + } service.eventBus.Publish(events.CreateTradeUserUpdated(entity.BullionId, user, adminId)) return nil } @@ -341,7 +345,10 @@ func (service *tradeUserServiceStruct) TradeUserChangeStatus(id string, bullionI return err } entity.IsActive = isActive - service.tradeUserRepo.Save(entity) + + if _, err := service.tradeUserRepo.Save(entity); err != nil { + return err + } if isActive { service.eventBus.Publish(events.CreateTradeUserActivatedEvent(entity.BullionId, entity, adminId)) } else { From c3701c54efd8f6241886679ef6cd78380b6e5dc4 Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Tue, 26 Mar 2024 01:45:49 +0530 Subject: [PATCH 14/23] Basic Testing Added --- src/interfaces/product-entity.interface.go | 5 +++ .../product-entity.interface_test.go | 39 +++++++++++++++++++ 2 files changed, 44 insertions(+) create mode 100644 src/interfaces/product-entity.interface_test.go diff --git a/src/interfaces/product-entity.interface.go b/src/interfaces/product-entity.interface.go index 6401687..931c0c9 100644 --- a/src/interfaces/product-entity.interface.go +++ b/src/interfaces/product-entity.interface.go @@ -56,3 +56,8 @@ func CreateNewProduct(productBase *ProductBaseStruct, calcSnapShot *CalcSnapshot b.createNewId() return b } + +func Calculate(symbol float64, snapshot *CshPremiumBuySellSnapshot) float64 { + price := symbol + float64(snapshot.Premium) + return price * (1 + float64(snapshot.Tax)/100) +} diff --git a/src/interfaces/product-entity.interface_test.go b/src/interfaces/product-entity.interface_test.go new file mode 100644 index 0000000..661f2dc --- /dev/null +++ b/src/interfaces/product-entity.interface_test.go @@ -0,0 +1,39 @@ +package interfaces + +import ( + "testing" +) + +func TestCalculate(t *testing.T) { + snapshot := &CshPremiumBuySellSnapshot{ + Premium: 10, + Tax: 5, + } + + t.Run("Positive values calculation", func(t *testing.T) { + symbol := 100.0 + expected := 115.5 + result := Calculate(symbol, snapshot) + if result != expected { + t.Errorf("Expected %f, but got %f", expected, result) + } + }) + + t.Run("Negative values calculation", func(t *testing.T) { + symbol := -50.0 + expected := -42.0 + result := Calculate(symbol, snapshot) + if result != expected { + t.Errorf("Expected %f, but got %f", expected, result) + } + }) + + t.Run("Zero values calculation", func(t *testing.T) { + symbol := 0.0 + expected := 10.5 + result := Calculate(symbol, snapshot) + if result != expected { + t.Errorf("Expected %f, but got %f", expected, result) + } + }) +} From 7dc00942bf1283105547a4cd84397fa3cf5e787a Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Wed, 27 Mar 2024 08:18:23 +0530 Subject: [PATCH 15/23] Some of the info is updated For Bullion Site Details --- src/apis/auth/get-bullion-details.go | 2 +- src/interfaces/bullion-site-info.interface.go | 40 +++++++++++++++---- src/services/bullion-details.service.go | 4 +- 3 files changed, 36 insertions(+), 10 deletions(-) diff --git a/src/apis/auth/get-bullion-details.go b/src/apis/auth/get-bullion-details.go index 60daafe..d3b1e23 100644 --- a/src/apis/auth/get-bullion-details.go +++ b/src/apis/auth/get-bullion-details.go @@ -23,7 +23,7 @@ func apiGetBullionDetailsByShortName(c *fiber.Ctx) error { if entity, err := services.BullionDetailsService.GetBullionDetailsByShortName(shortName); err != nil { return err } else { - return c.JSON(entity) + return c.JSON(entity.BullionPublicInfo) } } diff --git a/src/interfaces/bullion-site-info.interface.go b/src/interfaces/bullion-site-info.interface.go index a3e601b..7117c00 100644 --- a/src/interfaces/bullion-site-info.interface.go +++ b/src/interfaces/bullion-site-info.interface.go @@ -10,16 +10,25 @@ type bullionConfigs struct { DefaultGroupIdForTradeUser string `bson:"defaultGroupIdForTradeUser" json:"defaultGroupIdForTradeUser" validate:"required,uuid"` } +type limitConfigs struct { + FreezeTop int `bson:"freezeTop" json:"freezeTop" validate:"required"` + FreezeBottom int `bson:"freezeBottom" json:"freezeBottom" validate:"required"` +} + type BullionSiteBasicInfo struct { Name string `bson:"name" json:"name" validate:"required"` ShortName string `bson:"shortName" json:"shortName" validate:"required"` Domain string `bson:"domain" json:"domain" validate:"required"` } -type BullionSiteInfoEntity struct { +type BullionPublicInfo struct { *BaseEntity `bson:"inline"` *BullionSiteBasicInfo `bson:"inline"` - BullionConfigs *bullionConfigs `bson:"bullionConfigs" json:"-" validate:"required"` - GeneralUserInfo *bullionGeneralUserConfig `bson:"generalUserInfo" json:"-" validate:"required"` +} +type BullionSiteInfoEntity struct { + *BullionPublicInfo `bson:"inline"` + LimitConfigs *limitConfigs `bson:"limitConfigs" json:"-" validate:"required"` + BullionConfigs *bullionConfigs `bson:"bullionConfigs" json:"-" validate:"required"` + GeneralUserInfo *bullionGeneralUserConfig `bson:"generalUserInfo" json:"generalUserInfo" validate:"required"` } func (b *BullionSiteInfoEntity) AddGeneralUserInfo(AutoApprove bool, AutoLogin bool) *BullionSiteInfoEntity { @@ -32,11 +41,26 @@ func (b *BullionSiteInfoEntity) AddGeneralUserInfo(AutoApprove bool, AutoLogin b func CreateNewBullionSiteInfo(name string, shortName string, domain string) *BullionSiteInfoEntity { b := BullionSiteInfoEntity{ - BaseEntity: &BaseEntity{}, - BullionSiteBasicInfo: &BullionSiteBasicInfo{ - Name: name, - ShortName: shortName, - Domain: domain, + BullionPublicInfo: &BullionPublicInfo{ + BaseEntity: &BaseEntity{}, + BullionSiteBasicInfo: &BullionSiteBasicInfo{ + Name: name, + ShortName: shortName, + Domain: domain, + }, + }, + BullionConfigs: &bullionConfigs{ + OTPLength: 5, + HaveCustomWhatsappAgent: true, + DefaultGroupIdForTradeUser: "", + }, + LimitConfigs: &limitConfigs{ + FreezeTop: 20, + FreezeBottom: 100, + }, + GeneralUserInfo: &bullionGeneralUserConfig{ + AutoApprove: false, + AutoLogin: true, }, } b.createNewId() diff --git a/src/services/bullion-details.service.go b/src/services/bullion-details.service.go index c1be9b8..6114865 100644 --- a/src/services/bullion-details.service.go +++ b/src/services/bullion-details.service.go @@ -37,7 +37,8 @@ func (service *bullionDetailsService) GetBullionDetailsByShortName(shortName str if err != nil { return nil, err } - service.bullionSiteInfoMapById[shortName] = bullion + service.bullionSiteInfoMapById[bullion.ID] = bullion + service.bullionSiteInfoMapByShortName[shortName] = bullion return bullion, nil } func (service *bullionDetailsService) GetBullionDetailsByBullionId(id string) (*interfaces.BullionSiteInfoEntity, error) { @@ -49,6 +50,7 @@ func (service *bullionDetailsService) GetBullionDetailsByBullionId(id string) (* return nil, err } service.bullionSiteInfoMapById[id] = bullion + service.bullionSiteInfoMapByShortName[bullion.ShortName] = bullion return bullion, nil } From 88852618ac96fc77ebd44a11fb82eea1e4e06331 Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Mon, 22 Apr 2024 01:53:42 +0530 Subject: [PATCH 16/23] Deps Updated --- go.mod | 54 ++++++++++++------------ go.sum | 130 +++++++++++++++++++++++++-------------------------------- 2 files changed, 83 insertions(+), 101 deletions(-) diff --git a/go.mod b/go.mod index 5213013..85645fc 100644 --- a/go.mod +++ b/go.mod @@ -4,30 +4,31 @@ go 1.22.1 require ( cloud.google.com/go/firestore v1.15.0 - firebase.google.com/go/v4 v4.13.0 - github.com/go-faker/faker/v4 v4.3.0 + firebase.google.com/go/v4 v4.14.0 + github.com/go-faker/faker/v4 v4.4.1 github.com/go-playground/validator/v10 v10.19.0 - github.com/gofiber/fiber/v2 v2.52.2 + github.com/gofiber/fiber/v2 v2.52.4 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/google/uuid v1.6.0 github.com/joho/godotenv v1.5.1 github.com/mitchellh/mapstructure v1.5.0 github.com/redis/go-redis/v9 v9.5.1 - go.mongodb.org/mongo-driver v1.14.0 - golang.org/x/crypto v0.21.0 - google.golang.org/api v0.170.0 + go.mongodb.org/mongo-driver v1.15.0 + golang.org/x/crypto v0.22.0 + google.golang.org/api v0.175.0 ) require ( - cloud.google.com/go v0.112.1 // indirect - cloud.google.com/go/compute v1.25.1 // indirect - cloud.google.com/go/compute/metadata v0.2.3 // indirect + cloud.google.com/go v0.112.2 // indirect + cloud.google.com/go/auth v0.2.2 // indirect + cloud.google.com/go/auth/oauth2adapt v0.2.1 // indirect + cloud.google.com/go/compute/metadata v0.3.0 // indirect cloud.google.com/go/iam v1.1.7 // indirect cloud.google.com/go/longrunning v0.5.6 // indirect - cloud.google.com/go/storage v1.39.1 // indirect + cloud.google.com/go/storage v1.40.0 // indirect github.com/MicahParks/keyfunc v1.9.0 // indirect github.com/andybalholm/brotli v1.1.0 // indirect - github.com/cespare/xxhash/v2 v2.2.0 // indirect + github.com/cespare/xxhash/v2 v2.3.0 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect github.com/felixge/httpsnoop v1.0.4 // indirect github.com/gabriel-vasile/mimetype v1.4.3 // indirect @@ -42,7 +43,7 @@ require ( github.com/google/s2a-go v0.1.7 // indirect github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect github.com/googleapis/gax-go/v2 v2.12.3 // indirect - github.com/klauspost/compress v1.17.7 // indirect + github.com/klauspost/compress v1.17.8 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect @@ -57,22 +58,21 @@ require ( github.com/xdg-go/stringprep v1.0.4 // indirect github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a // indirect go.opencensus.io v0.24.0 // indirect - go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 // indirect - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 // indirect - go.opentelemetry.io/otel v1.24.0 // indirect - go.opentelemetry.io/otel/metric v1.24.0 // indirect - go.opentelemetry.io/otel/trace v1.24.0 // indirect - golang.org/x/net v0.22.0 // indirect - golang.org/x/oauth2 v0.18.0 // indirect - golang.org/x/sync v0.6.0 // indirect - golang.org/x/sys v0.18.0 // indirect + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.50.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.50.0 // indirect + go.opentelemetry.io/otel v1.25.0 // indirect + go.opentelemetry.io/otel/metric v1.25.0 // indirect + go.opentelemetry.io/otel/trace v1.25.0 // indirect + golang.org/x/net v0.24.0 // indirect + golang.org/x/oauth2 v0.19.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 golang.org/x/time v0.5.0 // indirect - google.golang.org/appengine v1.6.8 // indirect - google.golang.org/appengine/v2 v2.0.5 // indirect - google.golang.org/genproto v0.0.0-20240314234333-6e1732d8331c // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240314234333-6e1732d8331c // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c // indirect - google.golang.org/grpc v1.62.1 // indirect + google.golang.org/appengine/v2 v2.0.6 // indirect + google.golang.org/genproto v0.0.0-20240415180920-8c6c420018be // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect + google.golang.org/grpc v1.63.2 // indirect google.golang.org/protobuf v1.33.0 // indirect ) diff --git a/go.sum b/go.sum index af94b31..5819529 100644 --- a/go.sum +++ b/go.sum @@ -1,26 +1,22 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.112.1 h1:uJSeirPke5UNZHIb4SxfZklVSiWWVqW4oXlETwZziwM= -cloud.google.com/go v0.112.1/go.mod h1:+Vbu+Y1UU+I1rjmzeMOb/8RfkKJK2Gyxi1X6jJCZLo4= -cloud.google.com/go/compute v1.25.0 h1:H1/4SqSUhjPFE7L5ddzHOfY2bCAvjwNRZPNl6Ni5oYU= -cloud.google.com/go/compute v1.25.0/go.mod h1:GR7F0ZPZH8EhChlMo9FkLd7eUTwEymjqQagxzilIxIE= -cloud.google.com/go/compute v1.25.1 h1:ZRpHJedLtTpKgr3RV1Fx23NuaAEN1Zfx9hw1u4aJdjU= -cloud.google.com/go/compute v1.25.1/go.mod h1:oopOIR53ly6viBYxaDhBfJwzUAxf1zE//uf3IB011ls= -cloud.google.com/go/compute/metadata v0.2.3 h1:mg4jlk7mCAj6xXp9UJ4fjI9VUI5rubuGBW5aJ7UnBMY= -cloud.google.com/go/compute/metadata v0.2.3/go.mod h1:VAV5nSsACxMJvgaAuX6Pk2AawlZn8kiOGuCv6gTkwuA= +cloud.google.com/go v0.112.2 h1:ZaGT6LiG7dBzi6zNOvVZwacaXlmf3lRqnC4DQzqyRQw= +cloud.google.com/go v0.112.2/go.mod h1:iEqjp//KquGIJV/m+Pk3xecgKNhV+ry+vVTsy4TbDms= +cloud.google.com/go/auth v0.2.2 h1:gmxNJs4YZYcw6YvKRtVBaF2fyUE6UrWPyzU8jHvYfmI= +cloud.google.com/go/auth v0.2.2/go.mod h1:2bDNJWtWziDT3Pu1URxHHbkHE/BbOCuyUiKIGcNvafo= +cloud.google.com/go/auth/oauth2adapt v0.2.1 h1:VSPmMmUlT8CkIZ2PzD9AlLN+R3+D1clXMWHHa6vG/Ag= +cloud.google.com/go/auth/oauth2adapt v0.2.1/go.mod h1:tOdK/k+D2e4GEwfBRA48dKNQiDsqIXxLh7VU319eV0g= +cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc= +cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k= cloud.google.com/go/firestore v1.15.0 h1:/k8ppuWOtNuDHt2tsRV42yI21uaGnKDEQnRFeBpbFF8= cloud.google.com/go/firestore v1.15.0/go.mod h1:GWOxFXcv8GZUtYpWHw/w6IuYNux/BtmeVTMmjrm4yhk= -cloud.google.com/go/iam v1.1.6 h1:bEa06k05IO4f4uJonbB5iAgKTPpABy1ayxaIZV/GHVc= -cloud.google.com/go/iam v1.1.6/go.mod h1:O0zxdPeGBoFdWW3HWmBxJsk0pfvNM/p/qa82rWOGTwI= cloud.google.com/go/iam v1.1.7 h1:z4VHOhwKLF/+UYXAJDFwGtNF0b6gjsW1Pk9Ml0U/IoM= cloud.google.com/go/iam v1.1.7/go.mod h1:J4PMPg8TtyurAUvSmPj8FF3EDgY1SPRZxcUGrn7WXGA= -cloud.google.com/go/longrunning v0.5.5 h1:GOE6pZFdSrTb4KAiKnXsJBtlE6mEyaW44oKyMILWnOg= -cloud.google.com/go/longrunning v0.5.5/go.mod h1:WV2LAxD8/rg5Z1cNW6FJ/ZpX4E4VnDnoTk0yawPBB7s= cloud.google.com/go/longrunning v0.5.6 h1:xAe8+0YaWoCKr9t1+aWe+OeQgN/iJK1fEgZSXmjuEaE= cloud.google.com/go/longrunning v0.5.6/go.mod h1:vUaDrWYOMKRuhiv6JBnn49YxCPz2Ayn9GqyjaBT8/mA= -cloud.google.com/go/storage v1.39.1 h1:MvraqHKhogCOTXTlct/9C3K3+Uy2jBmFYb3/Sp6dVtY= -cloud.google.com/go/storage v1.39.1/go.mod h1:xK6xZmxZmo+fyP7+DEF6FhNc24/JAe95OLyOHCXFH1o= -firebase.google.com/go/v4 v4.13.0 h1:meFz9nvDNh/FDyrEykoAzSfComcQbmnQSjoHrePRqeI= -firebase.google.com/go/v4 v4.13.0/go.mod h1:e1/gaR6EnbQfsmTnAMx1hnz+ninJIrrr/RAh59Tpfn8= +cloud.google.com/go/storage v1.40.0 h1:VEpDQV5CJxFmJ6ueWNsKxcr1QAYOXEgxDa+sBbJahPw= +cloud.google.com/go/storage v1.40.0/go.mod h1:Rrj7/hKlG87BLqDJYtwR0fbPld8uJPbQ2ucUMY7Ir0g= +firebase.google.com/go/v4 v4.14.0 h1:Tc9jWzMUApUFUA5UUx/HcBeZ+LPjlhG2vNRfWJrcMwU= +firebase.google.com/go/v4 v4.14.0/go.mod h1:pLATyL6xH2o9AMe7rqHdmmOUE/Ph7wcwepIs+uiEKPg= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= github.com/MicahParks/keyfunc v1.9.0 h1:lhKd5xrFHLNOWrDc4Tyb/Q1AJ4LCzQ48GVJyVIID3+o= github.com/MicahParks/keyfunc v1.9.0/go.mod h1:IdnCilugA0O/99dW+/MkvlyrsX8+L8+x95xuVNtM5jw= @@ -31,8 +27,8 @@ github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdb github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= -github.com/cespare/xxhash/v2 v2.2.0 h1:DC2CZ1Ep5Y4k3ZQ899DldepgrayRUGE6BBZ/cd9Cj44= -github.com/cespare/xxhash/v2 v2.2.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= +github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= +github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= @@ -48,8 +44,8 @@ github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2 github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= -github.com/go-faker/faker/v4 v4.3.0 h1:UXOW7kn/Mwd0u6MR30JjUKVzguT20EB/hBOddAAO+DY= -github.com/go-faker/faker/v4 v4.3.0/go.mod h1:F/bBy8GH9NxOxMInug5Gx4WYeG6fHJZ8Ol/dhcpRub4= +github.com/go-faker/faker/v4 v4.4.1 h1:LY1jDgjVkBZWIhATCt+gkl0x9i/7wC61gZx73GTFb+Q= +github.com/go-faker/faker/v4 v4.4.1/go.mod h1:HRLrjis+tYsbFtIHufEPTAIzcZiRu0rS9EYl2Ccwme4= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= @@ -63,8 +59,8 @@ github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJn github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4= github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= -github.com/gofiber/fiber/v2 v2.52.2 h1:b0rYH6b06Df+4NyrbdptQL8ifuxw/Tf2DgfkZkDaxEo= -github.com/gofiber/fiber/v2 v2.52.2/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ= +github.com/gofiber/fiber/v2 v2.52.4 h1:P+T+4iK7VaqUsq2PALYEfBBo6bJZ4q3FP8cZ84EggTM= +github.com/gofiber/fiber/v2 v2.52.4/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ= github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= @@ -85,7 +81,6 @@ github.com/golang/protobuf v1.4.0/go.mod h1:jodUvKwWbYaEsadDk5Fwe5c77LiNKVO9IDvq github.com/golang/protobuf v1.4.1/go.mod h1:U8fpvMrcmy5pZrNK1lt4xCsGvpyWQ/VVv6QDs8UjoX8= github.com/golang/protobuf v1.4.3/go.mod h1:oDoupMAO8OvCJWAcko0GGGIgR6R6ocIYbsSw735rRwI= github.com/golang/protobuf v1.5.0/go.mod h1:FsONVRAS9T7sI+LIUmWTfcYkHO4aIWwzhcaSAoJOfIk= -github.com/golang/protobuf v1.5.2/go.mod h1:XVQd3VNwM+JqD3oG2Ue2ip4fOMUkwXdXDdiuN0vRsmY= github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek= github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps= github.com/golang/snappy v0.0.4 h1:yAGX7huGHXlcLOEtBnF4w7FQwA26wojNCwOYAEhLjQM= @@ -108,14 +103,12 @@ github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfFxPRy3Bf7vr3h0cechB90XaQs= github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0= -github.com/googleapis/gax-go/v2 v2.12.2 h1:mhN09QQW1jEWeMF74zGR81R30z4VJzjZsfkUhuHF+DA= -github.com/googleapis/gax-go/v2 v2.12.2/go.mod h1:61M8vcyyXR2kqKFxKrfA22jaA8JGF7Dc8App1U3H6jc= github.com/googleapis/gax-go/v2 v2.12.3 h1:5/zPPDvw8Q1SuXjrqrZslrqT7dL/uJT2CQii/cLCKqA= github.com/googleapis/gax-go/v2 v2.12.3/go.mod h1:AKloxT6GtNbaLm8QTNSidHUVsHYcBHwWRvkNFJUQcS4= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= -github.com/klauspost/compress v1.17.7 h1:ehO88t2UGzQK66LMdE8tibEd1ErmzZjNEqWkjLAKQQg= -github.com/klauspost/compress v1.17.7/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= +github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -143,8 +136,8 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= -github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= +github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= +github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= github.com/valyala/fasthttp v1.52.0 h1:wqBQpxH71XW0e2g+Og4dzQM8pk34aFYlA1Ga8db7gU0= @@ -160,28 +153,28 @@ github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gi github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk= github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.mongodb.org/mongo-driver v1.14.0 h1:P98w8egYRjYe3XDjxhYJagTokP/H6HzlsnojRgZRd80= -go.mongodb.org/mongo-driver v1.14.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= +go.mongodb.org/mongo-driver v1.15.0 h1:rJCKC8eEliewXjZGf0ddURtl7tTVy1TK3bfl0gkUSLc= +go.mongodb.org/mongo-driver v1.15.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0 h1:4Pp6oUg3+e/6M4C0A/3kJ2VYa++dsWVTtGgLVj5xtHg= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.49.0/go.mod h1:Mjt1i1INqiaoZOMGR1RIUJN+i3ChKoFRqzrRQhlkbs0= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0 h1:jq9TW8u3so/bN+JPT166wjOI6/vQPF6Xe7nMNIltagk= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.49.0/go.mod h1:p8pYQP+m5XfbZm9fxtSKAbM6oIllS7s2AfxrChvc7iw= -go.opentelemetry.io/otel v1.24.0 h1:0LAOdjNmQeSTzGBzduGe/rU4tZhMwL5rWgtp9Ku5Jfo= -go.opentelemetry.io/otel v1.24.0/go.mod h1:W7b9Ozg4nkF5tWI5zsXkaKKDjdVjpD4oAt9Qi/MArHo= -go.opentelemetry.io/otel/metric v1.24.0 h1:6EhoGWWK28x1fbpA4tYTOWBkPefTDQnb8WSGXlc88kI= -go.opentelemetry.io/otel/metric v1.24.0/go.mod h1:VYhLe1rFfxuTXLgj4CBiyz+9WYBA8pNGJgDcSFRKBco= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.50.0 h1:zvpPXY7RfYAGSdYQLjp6zxdJNSYD/+FFoCTQN9IPxBs= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.50.0/go.mod h1:BMn8NB1vsxTljvuorms2hyOs8IBuuBEq0pl7ltOfy30= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.50.0 h1:cEPbyTSEHlQR89XVlyo78gqluF8Y3oMeBkXGWzQsfXY= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.50.0/go.mod h1:DKdbWcT4GH1D0Y3Sqt/PFXt2naRKDWtU+eE6oLdFNA8= +go.opentelemetry.io/otel v1.25.0 h1:gldB5FfhRl7OJQbUHt/8s0a7cE8fbsPAtdpRaApKy4k= +go.opentelemetry.io/otel v1.25.0/go.mod h1:Wa2ds5NOXEMkCmUou1WA7ZBfLTHWIsp034OVD7AO+Vg= +go.opentelemetry.io/otel/metric v1.25.0 h1:LUKbS7ArpFL/I2jJHdJcqMGxkRdxpPHE0VU/D4NuEwA= +go.opentelemetry.io/otel/metric v1.25.0/go.mod h1:rkDLUSd2lC5lq2dFNrX9LGAbINP5B7WBkC78RXCpH5s= go.opentelemetry.io/otel/sdk v1.22.0 h1:6coWHw9xw7EfClIC/+O31R8IY3/+EiRFHevmHafB2Gw= go.opentelemetry.io/otel/sdk v1.22.0/go.mod h1:iu7luyVGYovrRpe2fmj3CVKouQNdTOkxtLzPvPz1DOc= -go.opentelemetry.io/otel/trace v1.24.0 h1:CsKnnL4dUAr/0llH9FKuc698G04IrpWV0MQA/Y1YELI= -go.opentelemetry.io/otel/trace v1.24.0/go.mod h1:HPc3Xr/cOApsBI154IU0OI0HJexz+aw5uPdbs3UCjNU= +go.opentelemetry.io/otel/trace v1.25.0 h1:tqukZGLwQYRIFtSQM2u2+yfMVTgGVeqRLPUYx1Dq6RM= +go.opentelemetry.io/otel/trace v1.25.0/go.mod h1:hCCs70XM/ljO+BeQkyFnbK28SBIJ/Emuha+ccrCRT7I= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.21.0 h1:X31++rzVUdKhX5sWmSOFZxx8UW/ldWx55cbf08iNAMA= -golang.org/x/crypto v0.21.0/go.mod h1:0BP7YvVV9gBbVKyeTG0Gyn+gZm94bibOW5BjDEYAOMs= +golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= +golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -196,17 +189,17 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.22.0 h1:9sGLhx7iRIHEiX0oAJ3MRZMUCElJgy7Br1nO+AMN3Tc= -golang.org/x/net v0.22.0/go.mod h1:JKghWKKOSdJwpW2GEx0Ja7fmaKnMsbu+MWVZTokSYmg= +golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= +golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.18.0 h1:09qnuIAgzdx1XplqJvW6CQqMCtGZykZWcXzPMPUusvI= -golang.org/x/oauth2 v0.18.0/go.mod h1:Wf7knwG0MPoWIMMBgFlEaSUDaKskp0dCfrlJRJXbBi8= +golang.org/x/oauth2 v0.19.0 h1:9+E/EZBCbTLNrbN35fHv/a/d/mOBatymz1zbtQrXpIg= +golang.org/x/oauth2 v0.19.0/go.mod h1:vYi7skDa1x015PmRRYZ7+s1cWyPgrPiSYRe4rnsexc8= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.6.0 h1:5BMeUDZ7vkXGfEr1x9B4bRcTH4lpkTkpdh0T/J+qjbQ= -golang.org/x/sync v0.6.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= +golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -217,8 +210,8 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.18.0 h1:DBdB3niSjOA/O0blCZBqDefyWNYveAYMNF1Wum0DYQ4= -golang.org/x/sys v0.18.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= +golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= @@ -240,38 +233,28 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= -google.golang.org/api v0.169.0 h1:QwWPy71FgMWqJN/l6jVlFHUa29a7dcUy02I8o799nPY= -google.golang.org/api v0.169.0/go.mod h1:gpNOiMA2tZ4mf5R9Iwf4rK/Dcz0fbdIgWYWVoxmsyLg= -google.golang.org/api v0.170.0 h1:zMaruDePM88zxZBG+NG8+reALO2rfLhe/JShitLyT48= -google.golang.org/api v0.170.0/go.mod h1:/xql9M2btF85xac/VAm4PsLMTLVGUOpq4BE9R8jyNy8= +google.golang.org/api v0.175.0 h1:9bMDh10V9cBuU8N45Wlc3cKkItfqMRV0Fi8UscLEtbY= +google.golang.org/api v0.175.0/go.mod h1:Rra+ltKu14pps/4xTycZfobMgLpbosoaaL7c+SEMrO8= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= -google.golang.org/appengine v1.6.8 h1:IhEN5q69dyKagZPYMSdIjS2HqprW324FRQZJcGqPAsM= -google.golang.org/appengine v1.6.8/go.mod h1:1jJ3jBArFh5pcgW8gCtRJnepW8FzD1V44FJffLiz/Ds= -google.golang.org/appengine/v2 v2.0.5 h1:4C+F3Cd3L2nWEfSmFEZDPjQvDwL8T0YCeZBysZifP3k= -google.golang.org/appengine/v2 v2.0.5/go.mod h1:WoEXGoXNfa0mLvaH5sV3ZSGXwVmy8yf7Z1JKf3J3wLI= +google.golang.org/appengine/v2 v2.0.6 h1:LvPZLGuchSBslPBp+LAhihBeGSiRh1myRoYK4NtuBIw= +google.golang.org/appengine/v2 v2.0.6/go.mod h1:WoEXGoXNfa0mLvaH5sV3ZSGXwVmy8yf7Z1JKf3J3wLI= google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7 h1:ImUcDPHjTrAqNhlOkSocDLfG9rrNHH7w7uoKWPaWZ8s= -google.golang.org/genproto v0.0.0-20240311173647-c811ad7063a7/go.mod h1:/3XmxOjePkvmKrHuBy4zNFw7IzxJXtAgdpXi8Ll990U= -google.golang.org/genproto v0.0.0-20240314234333-6e1732d8331c h1:1AVpelW1Ld8u6QbfPlwh00uAsR3xrnfn6FIJsCags3k= -google.golang.org/genproto v0.0.0-20240314234333-6e1732d8331c/go.mod h1:/3XmxOjePkvmKrHuBy4zNFw7IzxJXtAgdpXi8Ll990U= -google.golang.org/genproto/googleapis/api v0.0.0-20240311173647-c811ad7063a7 h1:oqta3O3AnlWbmIE3bFnWbu4bRxZjfbWCp0cKSuZh01E= -google.golang.org/genproto/googleapis/api v0.0.0-20240311173647-c811ad7063a7/go.mod h1:VQW3tUculP/D4B+xVCo+VgSq8As6wA9ZjHl//pmk+6s= -google.golang.org/genproto/googleapis/api v0.0.0-20240314234333-6e1732d8331c h1:kaI7oewGK5YnVwj+Y+EJBO/YN1ht8iTL9XkFHtVZLsc= -google.golang.org/genproto/googleapis/api v0.0.0-20240314234333-6e1732d8331c/go.mod h1:VQW3tUculP/D4B+xVCo+VgSq8As6wA9ZjHl//pmk+6s= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7 h1:8EeVk1VKMD+GD/neyEHGmz7pFblqPjHoi+PGQIlLx2s= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240311173647-c811ad7063a7/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c h1:lfpJ/2rWPa/kJgxyyXM8PrNnfCzcmxJ265mADgwmvLI= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240314234333-6e1732d8331c/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= +google.golang.org/genproto v0.0.0-20240415180920-8c6c420018be h1:g4aX8SUFA8V5F4LrSY5EclyGYw1OZN4HS1jTyjB9ZDc= +google.golang.org/genproto v0.0.0-20240415180920-8c6c420018be/go.mod h1:FeSdT5fk+lkxatqJP38MsUicGqHax5cLtmy/6TAuxO4= +google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be h1:Zz7rLWqp0ApfsR/l7+zSHhY3PMiH2xqgxlfYfAfNpoU= +google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be/go.mod h1:dvdCTIoAGbkWbcIKBniID56/7XHTt6WfxXNMxuziJ+w= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be h1:LG9vZxsWGOmUKieR8wPAUR3u3MpnYFQZROPIMaXh7/A= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= -google.golang.org/grpc v1.62.1 h1:B4n+nfKzOICUXMgyrNd19h/I9oH0L1pizfk1d4zSgTk= -google.golang.org/grpc v1.62.1/go.mod h1:IWTG0VlJLCh1SkC58F7np9ka9mx/WNkjl4PGJaiq+QE= +google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= +google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -282,7 +265,6 @@ google.golang.org/protobuf v1.23.0/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2 google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpADcykh3NcUnDUJcl1+ZksZNG86OlYog2l/sGQquU= google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= -google.golang.org/protobuf v1.26.0/go.mod h1:9q0QmTI4eRPtz6boOQmLYwt+qCgq0jsYwAQnmE0givc= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= From f9151c83b08afb4d2379b6877c1020f911d60983 Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Wed, 1 May 2024 23:08:13 +0530 Subject: [PATCH 17/23] Deps Added --- go.mod | 30 +++++++++++++++--------------- go.sum | 57 ++++++++++++++++++++++++++++----------------------------- 2 files changed, 43 insertions(+), 44 deletions(-) diff --git a/go.mod b/go.mod index 85645fc..05781a8 100644 --- a/go.mod +++ b/go.mod @@ -1,12 +1,12 @@ module github.com/rpsoftech/bullion-server -go 1.22.1 +go 1.22.2 require ( cloud.google.com/go/firestore v1.15.0 firebase.google.com/go/v4 v4.14.0 github.com/go-faker/faker/v4 v4.4.1 - github.com/go-playground/validator/v10 v10.19.0 + github.com/go-playground/validator/v10 v10.20.0 github.com/gofiber/fiber/v2 v2.52.4 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/google/uuid v1.6.0 @@ -15,13 +15,13 @@ require ( github.com/redis/go-redis/v9 v9.5.1 go.mongodb.org/mongo-driver v1.15.0 golang.org/x/crypto v0.22.0 - google.golang.org/api v0.175.0 + google.golang.org/api v0.177.0 ) require ( cloud.google.com/go v0.112.2 // indirect - cloud.google.com/go/auth v0.2.2 // indirect - cloud.google.com/go/auth/oauth2adapt v0.2.1 // indirect + cloud.google.com/go/auth v0.3.0 // indirect + cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect cloud.google.com/go/compute/metadata v0.3.0 // indirect cloud.google.com/go/iam v1.1.7 // indirect cloud.google.com/go/longrunning v0.5.6 // indirect @@ -56,13 +56,13 @@ require ( 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 + github.com/youmark/pkcs8 v0.0.0-20240424034433-3c2c7870ae76 // indirect go.opencensus.io v0.24.0 // indirect - go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.50.0 // indirect - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.50.0 // indirect - go.opentelemetry.io/otel v1.25.0 // indirect - go.opentelemetry.io/otel/metric v1.25.0 // indirect - go.opentelemetry.io/otel/trace v1.25.0 // indirect + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 // indirect + go.opentelemetry.io/otel v1.26.0 // indirect + go.opentelemetry.io/otel/metric v1.26.0 // indirect + go.opentelemetry.io/otel/trace v1.26.0 // indirect golang.org/x/net v0.24.0 // indirect golang.org/x/oauth2 v0.19.0 // indirect golang.org/x/sync v0.7.0 // indirect @@ -70,9 +70,9 @@ require ( golang.org/x/text v0.14.0 // indirect golang.org/x/time v0.5.0 // indirect google.golang.org/appengine/v2 v2.0.6 // indirect - google.golang.org/genproto v0.0.0-20240415180920-8c6c420018be // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be // indirect + google.golang.org/genproto v0.0.0-20240429193739-8cf5692501f6 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20240429193739-8cf5692501f6 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 // indirect google.golang.org/grpc v1.63.2 // indirect - google.golang.org/protobuf v1.33.0 // indirect + google.golang.org/protobuf v1.34.0 // indirect ) diff --git a/go.sum b/go.sum index 5819529..8c23764 100644 --- a/go.sum +++ b/go.sum @@ -1,10 +1,10 @@ cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= cloud.google.com/go v0.112.2 h1:ZaGT6LiG7dBzi6zNOvVZwacaXlmf3lRqnC4DQzqyRQw= cloud.google.com/go v0.112.2/go.mod h1:iEqjp//KquGIJV/m+Pk3xecgKNhV+ry+vVTsy4TbDms= -cloud.google.com/go/auth v0.2.2 h1:gmxNJs4YZYcw6YvKRtVBaF2fyUE6UrWPyzU8jHvYfmI= -cloud.google.com/go/auth v0.2.2/go.mod h1:2bDNJWtWziDT3Pu1URxHHbkHE/BbOCuyUiKIGcNvafo= -cloud.google.com/go/auth/oauth2adapt v0.2.1 h1:VSPmMmUlT8CkIZ2PzD9AlLN+R3+D1clXMWHHa6vG/Ag= -cloud.google.com/go/auth/oauth2adapt v0.2.1/go.mod h1:tOdK/k+D2e4GEwfBRA48dKNQiDsqIXxLh7VU319eV0g= +cloud.google.com/go/auth v0.3.0 h1:PRyzEpGfx/Z9e8+lHsbkoUVXD0gnu4MNmm7Gp8TQNIs= +cloud.google.com/go/auth v0.3.0/go.mod h1:lBv6NKTWp8E3LPzmO1TbiiRKc4drLOfHsgmlH9ogv5w= +cloud.google.com/go/auth/oauth2adapt v0.2.2 h1:+TTV8aXpjeChS9M+aTtN/TjdQnzJvmzKFt//oWu7HX4= +cloud.google.com/go/auth/oauth2adapt v0.2.2/go.mod h1:wcYjgpZI9+Yu7LyYBg4pqSiaRkfEK3GQcpb7C/uyF1Q= cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc= cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k= cloud.google.com/go/firestore v1.15.0 h1:/k8ppuWOtNuDHt2tsRV42yI21uaGnKDEQnRFeBpbFF8= @@ -57,8 +57,8 @@ github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/o github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.19.0 h1:ol+5Fu+cSq9JD7SoSqe04GMI92cbn0+wvQ3bZ8b/AU4= -github.com/go-playground/validator/v10 v10.19.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= +github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= github.com/gofiber/fiber/v2 v2.52.4 h1:P+T+4iK7VaqUsq2PALYEfBBo6bJZ4q3FP8cZ84EggTM= github.com/gofiber/fiber/v2 v2.52.4/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ= github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= @@ -150,27 +150,26 @@ github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= -github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a h1:fZHgsYlfvtyqToslyjUt3VOPF4J7aK/3MPcK7xp3PDk= -github.com/youmark/pkcs8 v0.0.0-20201027041543-1326539a0a0a/go.mod h1:ul22v+Nro/R083muKhosV54bj5niojjWZvU8xrevuH4= +github.com/youmark/pkcs8 v0.0.0-20240424034433-3c2c7870ae76 h1:tBiBTKHnIjovYoLX/TPkcf+OjqqKGQrPtGT3Foz+Pgo= +github.com/youmark/pkcs8 v0.0.0-20240424034433-3c2c7870ae76/go.mod h1:SQliXeA7Dhkt//vS29v3zpbEwoa+zb2Cn5xj5uO4K5U= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= go.mongodb.org/mongo-driver v1.15.0 h1:rJCKC8eEliewXjZGf0ddURtl7tTVy1TK3bfl0gkUSLc= go.mongodb.org/mongo-driver v1.15.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.50.0 h1:zvpPXY7RfYAGSdYQLjp6zxdJNSYD/+FFoCTQN9IPxBs= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.50.0/go.mod h1:BMn8NB1vsxTljvuorms2hyOs8IBuuBEq0pl7ltOfy30= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.50.0 h1:cEPbyTSEHlQR89XVlyo78gqluF8Y3oMeBkXGWzQsfXY= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.50.0/go.mod h1:DKdbWcT4GH1D0Y3Sqt/PFXt2naRKDWtU+eE6oLdFNA8= -go.opentelemetry.io/otel v1.25.0 h1:gldB5FfhRl7OJQbUHt/8s0a7cE8fbsPAtdpRaApKy4k= -go.opentelemetry.io/otel v1.25.0/go.mod h1:Wa2ds5NOXEMkCmUou1WA7ZBfLTHWIsp034OVD7AO+Vg= -go.opentelemetry.io/otel/metric v1.25.0 h1:LUKbS7ArpFL/I2jJHdJcqMGxkRdxpPHE0VU/D4NuEwA= -go.opentelemetry.io/otel/metric v1.25.0/go.mod h1:rkDLUSd2lC5lq2dFNrX9LGAbINP5B7WBkC78RXCpH5s= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0 h1:A3SayB3rNyt+1S6qpI9mHPkeHTZbD7XILEqWnYZb2l0= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0/go.mod h1:27iA5uvhuRNmalO+iEUdVn5ZMj2qy10Mm+XRIpRmyuU= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 h1:Xs2Ncz0gNihqu9iosIZ5SkBbWo5T8JhhLJFMQL1qmLI= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0/go.mod h1:vy+2G/6NvVMpwGX/NyLqcC41fxepnuKHk16E6IZUcJc= +go.opentelemetry.io/otel v1.26.0 h1:LQwgL5s/1W7YiiRwxf03QGnWLb2HW4pLiAhaA5cZXBs= +go.opentelemetry.io/otel v1.26.0/go.mod h1:UmLkJHUAidDval2EICqBMbnAd0/m2vmpf/dAM+fvFs4= +go.opentelemetry.io/otel/metric v1.26.0 h1:7S39CLuY5Jgg9CrnA9HHiEjGMF/X2VHvoXGgSllRz30= +go.opentelemetry.io/otel/metric v1.26.0/go.mod h1:SY+rHOI4cEawI9a7N1A4nIg/nTQXe1ccCNWYOJUrpX4= go.opentelemetry.io/otel/sdk v1.22.0 h1:6coWHw9xw7EfClIC/+O31R8IY3/+EiRFHevmHafB2Gw= go.opentelemetry.io/otel/sdk v1.22.0/go.mod h1:iu7luyVGYovrRpe2fmj3CVKouQNdTOkxtLzPvPz1DOc= -go.opentelemetry.io/otel/trace v1.25.0 h1:tqukZGLwQYRIFtSQM2u2+yfMVTgGVeqRLPUYx1Dq6RM= -go.opentelemetry.io/otel/trace v1.25.0/go.mod h1:hCCs70XM/ljO+BeQkyFnbK28SBIJ/Emuha+ccrCRT7I= +go.opentelemetry.io/otel/trace v1.26.0 h1:1ieeAUb4y0TE26jUFrCIXKpTuVK7uJGN9/Z/2LP5sQA= +go.opentelemetry.io/otel/trace v1.26.0/go.mod h1:4iDxvGDQuUkHve82hJJ8UqrwswHYsZuWCBllGV2U2y0= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= -golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= @@ -233,8 +232,8 @@ golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8T golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= -google.golang.org/api v0.175.0 h1:9bMDh10V9cBuU8N45Wlc3cKkItfqMRV0Fi8UscLEtbY= -google.golang.org/api v0.175.0/go.mod h1:Rra+ltKu14pps/4xTycZfobMgLpbosoaaL7c+SEMrO8= +google.golang.org/api v0.177.0 h1:8a0p/BbPa65GlqGWtUKxot4p0TV8OGOfyTjtmkXNXmk= +google.golang.org/api v0.177.0/go.mod h1:srbhue4MLjkjbkux5p3dw/ocYOSZTaIEvf7bCOnFQDw= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine/v2 v2.0.6 h1:LvPZLGuchSBslPBp+LAhihBeGSiRh1myRoYK4NtuBIw= @@ -242,12 +241,12 @@ google.golang.org/appengine/v2 v2.0.6/go.mod h1:WoEXGoXNfa0mLvaH5sV3ZSGXwVmy8yf7 google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20240415180920-8c6c420018be h1:g4aX8SUFA8V5F4LrSY5EclyGYw1OZN4HS1jTyjB9ZDc= -google.golang.org/genproto v0.0.0-20240415180920-8c6c420018be/go.mod h1:FeSdT5fk+lkxatqJP38MsUicGqHax5cLtmy/6TAuxO4= -google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be h1:Zz7rLWqp0ApfsR/l7+zSHhY3PMiH2xqgxlfYfAfNpoU= -google.golang.org/genproto/googleapis/api v0.0.0-20240415180920-8c6c420018be/go.mod h1:dvdCTIoAGbkWbcIKBniID56/7XHTt6WfxXNMxuziJ+w= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be h1:LG9vZxsWGOmUKieR8wPAUR3u3MpnYFQZROPIMaXh7/A= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240415180920-8c6c420018be/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= +google.golang.org/genproto v0.0.0-20240429193739-8cf5692501f6 h1:MTmrc2F5TZKDKXigcZetYkH04YwqtOPEQJwh4PPOgfk= +google.golang.org/genproto v0.0.0-20240429193739-8cf5692501f6/go.mod h1:2ROWwqCIx97Y7CSyp11xB8fori0wzvD6+gbacaf5c8I= +google.golang.org/genproto/googleapis/api v0.0.0-20240429193739-8cf5692501f6 h1:DTJM0R8LECCgFeUwApvcEJHz85HLagW8uRENYxHh1ww= +google.golang.org/genproto/googleapis/api v0.0.0-20240429193739-8cf5692501f6/go.mod h1:10yRODfgim2/T8csjQsMPgZOMvtytXKTDRzH6HRGzRw= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 h1:DujSIu+2tC9Ht0aPNA7jgj23Iq8Ewi5sgkQ++wdvonE= +google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= @@ -266,8 +265,8 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.33.0 h1:uNO2rsAINq/JlFpSdYEKIZ0uKD/R9cpdv0T+yoGwGmI= -google.golang.org/protobuf v1.33.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4= +google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= From b1a153f010cb22759f73a5d3548392d40a5ad710 Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Wed, 1 May 2024 23:09:27 +0530 Subject: [PATCH 18/23] CI Version Changes --- .github/workflows/builder.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/builder.yml b/.github/workflows/builder.yml index 618aa43..965e20e 100644 --- a/.github/workflows/builder.yml +++ b/.github/workflows/builder.yml @@ -12,7 +12,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: '1.21.6' + go-version: '1.22.2' - name: Build run: go build -v ./... From 3b58a138bb5a0fd4dea46d839ecc1c575d7fdcb5 Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Thu, 2 May 2024 01:17:50 +0530 Subject: [PATCH 19/23] SOME MORE PROGRESS --- src/interfaces/base-symbol.enum.go | 76 +++++++++++++++------- src/interfaces/calculate-on-price.enum.go | 42 +++++++++++- src/interfaces/product-entity.interface.go | 3 +- src/interfaces/trade-user.entity.go | 10 +-- src/services/order-general.service.go | 41 +++++++----- 5 files changed, 123 insertions(+), 49 deletions(-) diff --git a/src/interfaces/base-symbol.enum.go b/src/interfaces/base-symbol.enum.go index 66526e8..bc14ebb 100644 --- a/src/interfaces/base-symbol.enum.go +++ b/src/interfaces/base-symbol.enum.go @@ -1,14 +1,20 @@ package interfaces -import "github.com/rpsoftech/bullion-server/src/validator" +import ( + "github.com/rpsoftech/bullion-server/src/validator" +) type SymbolsEnum string +type SourceSymbolEnum string + +const ( + SOURCE_SYMBOL_GOLD SourceSymbolEnum = "GOLD" + SOURCE_SYMBOL_SILVER SourceSymbolEnum = "SILVER" +) const ( SYMBOL_GOLD SymbolsEnum = "GOLD" SYMBOL_SILVER SymbolsEnum = "SILVER" - SYMBOL_GOLD_MCX SymbolsEnum = "GOLD_MCX" - SYMBOL_SILVER_MCX SymbolsEnum = "SILVER_MCX" SYMBOL_GOLD_NEXT SymbolsEnum = "GOLD_NEXT" SYMBOL_SILVER_NEXT SymbolsEnum = "SILVER_NEXT" SYMBOL_GOLD_SPOT SymbolsEnum = "GOLD_SPOT" @@ -16,27 +22,35 @@ const ( SYMBOL_INR SymbolsEnum = "INR" ) -var SymbolsEnumArray = []SymbolsEnum{ - SYMBOL_GOLD, - SYMBOL_SILVER, - SYMBOL_GOLD_MCX, - SYMBOL_SILVER_MCX, - SYMBOL_GOLD_NEXT, - SYMBOL_SILVER_NEXT, - SYMBOL_GOLD_SPOT, - SYMBOL_SILVER_SPOT, - SYMBOL_INR, -} - var ( + SymbolsEnumArray = []SymbolsEnum{ + SYMBOL_GOLD, + SYMBOL_SILVER, + SYMBOL_GOLD_NEXT, + SYMBOL_SILVER_NEXT, + SYMBOL_GOLD_SPOT, + SYMBOL_SILVER_SPOT, + SYMBOL_INR, + } + + SourceSymbolEnumArray = []SourceSymbolEnum{ + SOURCE_SYMBOL_GOLD, + SOURCE_SYMBOL_SILVER, + } + + sourceSymbolEnumMap = EnumValidatorBase{ + Data: map[string]interface{}{ + "GOLD": SOURCE_SYMBOL_GOLD, + "SILVER": SOURCE_SYMBOL_SILVER, + }, + } + symbolEnumMap = EnumValidatorBase{ Data: map[string]interface{}{ "GOLD": SYMBOL_GOLD, - "GOLD_MCX": SYMBOL_GOLD_MCX, "GOLD_SPOT": SYMBOL_GOLD_SPOT, "GOLD_NEXT": SYMBOL_GOLD_NEXT, "SILVER": SYMBOL_SILVER, - "SILVER_MCX": SYMBOL_SILVER_MCX, "SILVER_NEXT": SYMBOL_SILVER_NEXT, "SILVER_SPOT": SYMBOL_SILVER_SPOT, "INR": SYMBOL_INR, @@ -46,6 +60,7 @@ var ( func init() { validator.RegisterEnumValidatorFunc("SymbolsEnum", symbolEnumMap.Validate) + validator.RegisterEnumValidatorFunc("SourceSymbolEnum", sourceSymbolEnumMap.Validate) } func SymbolsEnumFromString(d string) SymbolsEnum { @@ -62,10 +77,6 @@ func (s SymbolsEnum) String() string { return "GOLD" case SYMBOL_SILVER: return "SILVER" - case SYMBOL_GOLD_MCX: - return "GOLD_MCX" - case SYMBOL_SILVER_MCX: - return "SILVER_MCX" case SYMBOL_GOLD_NEXT: return "GOLD_NEXT" case SYMBOL_SILVER_NEXT: @@ -86,8 +97,6 @@ func (s SymbolsEnum) IsValid() bool { case SYMBOL_GOLD, SYMBOL_SILVER, - SYMBOL_GOLD_MCX, - SYMBOL_SILVER_MCX, SYMBOL_GOLD_NEXT, SYMBOL_SILVER_NEXT, SYMBOL_GOLD_SPOT, @@ -98,3 +107,24 @@ func (s SymbolsEnum) IsValid() bool { return false } + +func (s SourceSymbolEnum) String() string { + switch s { + case SOURCE_SYMBOL_GOLD: + return "GOLD" + case SOURCE_SYMBOL_SILVER: + return "SILVER" + } + return "unknown" +} + +func (s SourceSymbolEnum) IsValid() bool { + switch s { + case + SOURCE_SYMBOL_GOLD, + SOURCE_SYMBOL_SILVER: + return true + } + + return false +} diff --git a/src/interfaces/calculate-on-price.enum.go b/src/interfaces/calculate-on-price.enum.go index 40302a7..f50f93b 100644 --- a/src/interfaces/calculate-on-price.enum.go +++ b/src/interfaces/calculate-on-price.enum.go @@ -4,13 +4,25 @@ import "github.com/rpsoftech/bullion-server/src/validator" type CalculateOnPriceType string +type CalculationPriceMethod string + const ( - CALCULATE_ON_BID_ASK CalculateOnPriceType = "BID_ASK" - CALCULATE_ON_BID CalculateOnPriceType = "BID" - CALCULATE_ON_ASK CalculateOnPriceType = "ASK" + CALCULATION_PRICE_TYPE_FIX CalculationPriceMethod = "FIX" + CALCULATION_PRICE_TYPE_BANK CalculationPriceMethod = "BANK" + CALCULATION_PRICE_TYPE_EXEC CalculationPriceMethod = "EXEC" + CALCULATE_ON_BID_ASK CalculateOnPriceType = "BID_ASK" + CALCULATE_ON_BID CalculateOnPriceType = "BID" + CALCULATE_ON_ASK CalculateOnPriceType = "ASK" ) var ( + calculationPriceMethodMap = EnumValidatorBase{ + Data: map[string]interface{}{ + "FIX": CALCULATION_PRICE_TYPE_FIX, + "BANK": CALCULATION_PRICE_TYPE_BANK, + "EXEC": CALCULATION_PRICE_TYPE_EXEC, + }, + } calculateOnPriceTypeMap = EnumValidatorBase{ Data: map[string]interface{}{ "BID_ASK": CALCULATE_ON_BID_ASK, @@ -22,6 +34,7 @@ var ( func init() { validator.RegisterEnumValidatorFunc("CalculateOnPriceType", calculateOnPriceTypeMap.Validate) + validator.RegisterEnumValidatorFunc("CalculationPriceMethod", calculationPriceMethodMap.Validate) } // ValidateEnumCalculateOnPriceType checks if the given value is a valid calculateOnPriceType. @@ -52,3 +65,26 @@ func (s CalculateOnPriceType) IsValid() bool { return false } + +func (s CalculationPriceMethod) String() string { + switch s { + case CALCULATION_PRICE_TYPE_FIX: + return "FIX" + case CALCULATION_PRICE_TYPE_BANK: + return "BANK" + case CALCULATION_PRICE_TYPE_EXEC: + return "EXEC" + } + return "unknown" +} + +func (s CalculationPriceMethod) IsValid() bool { + switch s { + case + CALCULATION_PRICE_TYPE_FIX, + CALCULATION_PRICE_TYPE_BANK, + CALCULATION_PRICE_TYPE_EXEC: + return true + } + return false +} diff --git a/src/interfaces/product-entity.interface.go b/src/interfaces/product-entity.interface.go index 931c0c9..fd6b2de 100644 --- a/src/interfaces/product-entity.interface.go +++ b/src/interfaces/product-entity.interface.go @@ -13,8 +13,7 @@ type ( ProductBaseStruct struct { BullionId string `bson:"bullionId" json:"bullionId" validate:"required,uuid"` Name string `bson:"name" json:"name" validate:"required"` - SourceSymbol SymbolsEnum `bson:"sourceSymbol" json:"sourceSymbol" validate:"required,enum=SymbolsEnum"` - CalculationSymbol SymbolsEnum `bson:"calculationSymbol" json:"calculationSymbol" validate:"required,enum=SymbolsEnum"` + SourceSymbol SourceSymbolEnum `bson:"sourceSymbol" json:"sourceSymbol" validate:"required,enum=SourceSymbolEnum"` IsActive bool `bson:"isActive" json:"isActive" validate:"boolean"` IsHedging bool `bson:"isHedging" json:"isHedging" validate:"boolean"` FloatPoint int `bson:"floatPoint" json:"floatPoint" validate:"min=0,max=4"` diff --git a/src/interfaces/trade-user.entity.go b/src/interfaces/trade-user.entity.go index 75109e7..f9618f9 100644 --- a/src/interfaces/trade-user.entity.go +++ b/src/interfaces/trade-user.entity.go @@ -58,11 +58,11 @@ func (user *TradeUserEntity) DeletePassword() *TradeUserEntity { return user } -func (user *TradeUserEntity) UpdateMarginAfterOrder(weight int, symbol SymbolsEnum) (*TradeUserEntity, error) { +func (user *TradeUserEntity) UpdateMarginAfterOrder(weight int, symbol SourceSymbolEnum) (*TradeUserEntity, error) { availableMargin := 0 - if symbol == SYMBOL_GOLD { + if symbol == SOURCE_SYMBOL_GOLD { availableMargin = user.AllotedMargins.Gold - user.UsedMargins.Gold - } else if symbol == SYMBOL_SILVER { + } else if symbol == SOURCE_SYMBOL_SILVER { availableMargin = user.AllotedMargins.Silver - user.UsedMargins.Silver } @@ -76,9 +76,9 @@ func (user *TradeUserEntity) UpdateMarginAfterOrder(weight int, symbol SymbolsEn } } - if symbol == SYMBOL_GOLD { + if symbol == SOURCE_SYMBOL_GOLD { user.UsedMargins.Gold = user.UsedMargins.Gold + weight - } else if symbol == SYMBOL_SILVER { + } else if symbol == SOURCE_SYMBOL_SILVER { user.UsedMargins.Silver = user.UsedMargins.Silver + weight } return user, nil diff --git a/src/services/order-general.service.go b/src/services/order-general.service.go index 6cf46bb..484365b 100644 --- a/src/services/order-general.service.go +++ b/src/services/order-general.service.go @@ -8,14 +8,15 @@ import ( ) type orderGeneralService struct { - eventBus *eventBusService - firebaseDb *firebaseDatabaseService - bullionService *bullionDetailsService - flagService *FlagServiceStruct - groupService *tradeUserGroupServiceStruct - orderRepo *repos.OrderRepoStruct - userService *tradeUserServiceStruct - productService *productService + eventBus *eventBusService + firebaseDb *firebaseDatabaseService + bullionService *bullionDetailsService + flagService *FlagServiceStruct + groupService *tradeUserGroupServiceStruct + orderRepo *repos.OrderRepoStruct + bankRateService *bankRateService + userService *tradeUserServiceStruct + productService *productService } var OrderGeneralService *orderGeneralService @@ -26,14 +27,15 @@ func init() { func getOrderGeneralService() *orderGeneralService { if OrderGeneralService == nil { OrderGeneralService = &orderGeneralService{ - eventBus: getEventBusService(), - firebaseDb: getFirebaseRealTimeDatabase(), - bullionService: getBullionService(), - groupService: getTradeUserGroupService(), - flagService: getFlagService(), - userService: getTradeUserService(), - productService: getProductService(), - orderRepo: repos.OrderRepo, + eventBus: getEventBusService(), + firebaseDb: getFirebaseRealTimeDatabase(), + bullionService: getBullionService(), + groupService: getTradeUserGroupService(), + flagService: getFlagService(), + userService: getTradeUserService(), + bankRateService: getBankRateService(), + productService: getProductService(), + orderRepo: repos.OrderRepo, } println("Order General Service Initialized") } @@ -177,6 +179,8 @@ func (service *orderGeneralService) PlaceOrder(orderType interfaces.OrderStatus, // TODO Validate Pricing + // product.CalculatedOnPriceOf + _, err = user.UpdateMarginAfterOrder(weight, product.SourceSymbol) if err != nil { return nil, err @@ -187,3 +191,8 @@ func (service *orderGeneralService) PlaceOrder(orderType interfaces.OrderStatus, // return service.orderRepo.PlaceOrder(orderType, user, group, groupMap, price, placedBy) // return service.orderRepo.PlaceOrder(orderType, user, group, groupMap, price, placedBy) } + +// check user is valid +// check group is valid +// check group map is valid +// check for volume From 1cf4b67d8d1e85dc480e703d3178343f6690d6de Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Thu, 2 May 2024 03:32:48 +0530 Subject: [PATCH 20/23] THIS IS ADDED --- main.go | 28 ++++++---- src/interfaces/base-symbol.enum.go | 8 +++ src/interfaces/error-code.enum.go | 1 + src/interfaces/product-entity.interface.go | 15 +++--- src/services/live-rate.service.go | 8 +++ src/services/order-general.service.go | 61 +++++++++++++++++++++- 6 files changed, 103 insertions(+), 18 deletions(-) diff --git a/main.go b/main.go index ca9dd80..ab3c60c 100644 --- a/main.go +++ b/main.go @@ -1,6 +1,8 @@ package main import ( + "encoding/json" + "fmt" "strconv" "time" @@ -28,6 +30,7 @@ func main() { defer deferMainFunc() app := fiber.New(fiber.Config{ + ServerHeader: "Bullion Server V1.0.0", ErrorHandler: func(c *fiber.Ctx, err error) error { mappedError, ok := err.(*interfaces.RequestError) if !ok { @@ -45,15 +48,18 @@ func main() { app.Use(logger.New()) app.Use(middleware.TokenDecrypter) - app.Get("/token", func(c *fiber.Ctx) error { - a, _ := services.AccessTokenService.GenerateToken(jwt.GeneralUserAccessRefreshToken{ - Role: interfaces.ROLE_ADMIN, - RegisteredClaims: &j.RegisteredClaims{ - IssuedAt: j.NewNumericDate(time.Now()), - }, - }) - return c.SendString(a) - }) + if env.Env.APP_ENV != env.APP_ENV_PRODUCTION { + + app.Get("/token", func(c *fiber.Ctx) error { + a, _ := services.AccessTokenService.GenerateToken(jwt.GeneralUserAccessRefreshToken{ + Role: interfaces.ROLE_ADMIN, + RegisteredClaims: &j.RegisteredClaims{ + IssuedAt: j.NewNumericDate(time.Now()), + }, + }) + return c.SendString(a) + }).Name("Temp Admin Access Token") + } // repos.BullionSiteInfoRepo.Save(interfaces.CreateNewBullionSiteInfo("Akshat Bullion", "https://akshatbullion.com").AddGeneralUserInfo(true, true)) // app.Get("/", func(c *fiber.Ctx) error { // bull := repos.BullionSiteInfoRepo.FindOne("ad3cee16-e8d7-4a27-a060-46d99c133273") @@ -71,6 +77,10 @@ func main() { if env.Env.APP_ENV == env.APP_ENV_LOCAL || env.Env.APP_ENV == env.APP_ENV_DEVELOPE { hostAndPort = "127.0.0.1" } + // Print the router stack in JSON format + data, _ := json.MarshalIndent(app.Stack(), "", " ") + fmt.Println(string(data)) + hostAndPort = hostAndPort + ":" + strconv.Itoa(env.Env.PORT) app.Listen(hostAndPort) // log.Fatal(app.Listen(":" + strconv.Itoa(env.Env.PORT))) diff --git a/src/interfaces/base-symbol.enum.go b/src/interfaces/base-symbol.enum.go index bc14ebb..0dbb5e5 100644 --- a/src/interfaces/base-symbol.enum.go +++ b/src/interfaces/base-symbol.enum.go @@ -128,3 +128,11 @@ func (s SourceSymbolEnum) IsValid() bool { return false } + +func (s SourceSymbolEnum) ToSymbolEnum() SymbolsEnum { + if SOURCE_SYMBOL_GOLD == s { + return SYMBOL_GOLD + } else { + return SYMBOL_SILVER + } +} diff --git a/src/interfaces/error-code.enum.go b/src/interfaces/error-code.enum.go index 260b995..41b6989 100644 --- a/src/interfaces/error-code.enum.go +++ b/src/interfaces/error-code.enum.go @@ -41,4 +41,5 @@ const ( ERROR_TRADING_IS_DISABLED_FOR_GROUP = 236 ERROR_TRADING_IS_DISABLED_FOR_PRODUCT = 237 ERROR_GROUP_MAP_NOT_FOUND = 238 + ERROR_LIVE_RATE_NOT_FOUND = 239 ) diff --git a/src/interfaces/product-entity.interface.go b/src/interfaces/product-entity.interface.go index fd6b2de..d20aebf 100644 --- a/src/interfaces/product-entity.interface.go +++ b/src/interfaces/product-entity.interface.go @@ -11,13 +11,14 @@ type ( Sell CshPremiumBuySellSnapshot `bson:"sell" json:"sell" validate:"required"` } ProductBaseStruct struct { - BullionId string `bson:"bullionId" json:"bullionId" validate:"required,uuid"` - Name string `bson:"name" json:"name" validate:"required"` - SourceSymbol SourceSymbolEnum `bson:"sourceSymbol" json:"sourceSymbol" validate:"required,enum=SourceSymbolEnum"` - IsActive bool `bson:"isActive" json:"isActive" validate:"boolean"` - IsHedging bool `bson:"isHedging" json:"isHedging" validate:"boolean"` - FloatPoint int `bson:"floatPoint" json:"floatPoint" validate:"min=0,max=4"` - CalculatedOnPriceOf CalculateOnPriceType `bson:"calculatedOnPriceOf" json:"calculatedOnPriceOf" validate:"required,enum=CalculateOnPriceType"` + BullionId string `bson:"bullionId" json:"bullionId" validate:"required,uuid"` + Name string `bson:"name" json:"name" validate:"required"` + SourceSymbol SourceSymbolEnum `bson:"sourceSymbol" json:"sourceSymbol" validate:"required,enum=SourceSymbolEnum"` + IsActive bool `bson:"isActive" json:"isActive" validate:"boolean"` + IsHedging bool `bson:"isHedging" json:"isHedging" validate:"boolean"` + FloatPoint int `bson:"floatPoint" json:"floatPoint" validate:"min=0,max=4"` + CalcPriceMethod CalculationPriceMethod `bson:"calcPriceMethod" json:"calcPriceMethod" validate:"required,enum=CalculationPriceMethod"` + CalculatedOnPriceOf CalculateOnPriceType `bson:"calculatedOnPriceOf" json:"calculatedOnPriceOf" validate:"required,enum=CalculateOnPriceType"` } ProductEntity struct { diff --git a/src/services/live-rate.service.go b/src/services/live-rate.service.go index 8d52498..49f27bd 100644 --- a/src/services/live-rate.service.go +++ b/src/services/live-rate.service.go @@ -39,6 +39,14 @@ func (s *liveRateServiceStruct) GetLastRate() *interfaces.LiveRateData { return &s.LastRateMap } +func (s *liveRateServiceStruct) GetLiveRate(symbol interfaces.SymbolsEnum, priceKey interfaces.PriceKeyEnum) float64 { + rateMap := s.LastRateMap[symbol] + if len(rateMap) == 0 { + return 0 + } + return rateMap[priceKey] +} + func (s *liveRateServiceStruct) lastRateReaderFromRedis() { go func() { for { diff --git a/src/services/order-general.service.go b/src/services/order-general.service.go index 484365b..d5535d3 100644 --- a/src/services/order-general.service.go +++ b/src/services/order-general.service.go @@ -12,6 +12,7 @@ type orderGeneralService struct { firebaseDb *firebaseDatabaseService bullionService *bullionDetailsService flagService *FlagServiceStruct + liveRateService *liveRateServiceStruct groupService *tradeUserGroupServiceStruct orderRepo *repos.OrderRepoStruct bankRateService *bankRateService @@ -32,6 +33,7 @@ func getOrderGeneralService() *orderGeneralService { bullionService: getBullionService(), groupService: getTradeUserGroupService(), flagService: getFlagService(), + liveRateService: getLiveRateService(), userService: getTradeUserService(), bankRateService: getBankRateService(), productService: getProductService(), @@ -165,7 +167,7 @@ func (service *orderGeneralService) findOrderDetailsAndValidate(userId string, g service.ValidateUserAndGroupMapWithWeight(user, group, groupMap, weight) return user, group, groupMap, nil } -func (service *orderGeneralService) PlaceOrder(orderType interfaces.OrderStatus, userId string, groupId string, groupMapId string, weight int, price float64, placedBy string) (*interfaces.OrderEntity, error) { +func (service *orderGeneralService) PlaceOrder(orderType interfaces.OrderStatus, userId string, groupId string, groupMapId string, buySell interfaces.BuySell, weight int, price float64, placedBy string) (*interfaces.OrderEntity, error) { user, group, groupMap, err := service.findOrderDetailsAndValidate(userId, groupId, groupMapId, weight) if err != nil { @@ -178,8 +180,63 @@ func (service *orderGeneralService) PlaceOrder(orderType interfaces.OrderStatus, } // TODO Validate Pricing + priceReadKey := interfaces.PRICE_ASK + if product.CalculatedOnPriceOf == interfaces.CALCULATE_ON_BID { + priceReadKey = interfaces.PRICE_BID + } else if product.CalculatedOnPriceOf == interfaces.CALCULATE_ON_BID_ASK { + if buySell == interfaces.Sell { + priceReadKey = interfaces.PRICE_ASK + } else { + priceReadKey = interfaces.PRICE_BID + } + } + + productSymbol := product.SourceSymbol.ToSymbolEnum() + + if product.CalcPriceMethod == interfaces.CALCULATION_PRICE_TYPE_BANK { + if product.SourceSymbol == interfaces.SOURCE_SYMBOL_GOLD { + productSymbol = interfaces.SYMBOL_GOLD_SPOT + } else { + productSymbol = interfaces.SYMBOL_SILVER_SPOT + } + } + + rate := service.liveRateService.GetLiveRate(productSymbol, priceReadKey) + + if rate == 0 { + return nil, &interfaces.RequestError{ + StatusCode: 400, + Code: interfaces.ERROR_LIVE_RATE_NOT_FOUND, + Message: "Live Rate Not Found", + Name: "LIVE_RATE_NOT_FOUND", + } + } + + if product.CalcPriceMethod == interfaces.CALCULATION_PRICE_TYPE_BANK { + bankRate, err := service.bankRateService.GetBankRateCalcByBullionId(group.BullionId) + if err != nil { + return nil, err + } + inrRate := service.liveRateService.GetLiveRate(interfaces.SYMBOL_INR, priceReadKey) + calcFunc := bankRate.GOLD_SPOT.CalculatePrice + if product.SourceSymbol == interfaces.SOURCE_SYMBOL_SILVER { + calcFunc = bankRate.SILVER_SPOT.CalculatePrice + } + rate = calcFunc(rate, inrRate) + // rate = bankRate.Rate + } + calcSnapshot := &product.CalcSnapshot.Sell + if buySell == interfaces.Buy { + calcSnapshot = &product.CalcSnapshot.Buy + } + finalRate := interfaces.Calculate(rate, calcSnapshot) + + println("Final Rate", finalRate) + // order := &interfaces.OrderEntity{ + + // TODO Check Hedging And Place Order - // product.CalculatedOnPriceOf + // TODO Update Order Entity in DB _, err = user.UpdateMarginAfterOrder(weight, product.SourceSymbol) if err != nil { From 00f7a6c59723267174ff73d7c237e5a1112fb3a2 Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Thu, 20 Feb 2025 22:17:13 +0530 Subject: [PATCH 21/23] YESS --- main.go | 3 + src/apis/order/user/index.go | 9 ++- src/apis/order/user/placeMarketOrder.api.go | 30 ++++++++++ src/interfaces/req-interfaces.go | 11 ++-- src/services/order-general.service.go | 61 ++++++++++++--------- 5 files changed, 81 insertions(+), 33 deletions(-) create mode 100644 src/apis/order/user/placeMarketOrder.api.go diff --git a/main.go b/main.go index ab3c60c..7b25be0 100644 --- a/main.go +++ b/main.go @@ -41,6 +41,9 @@ func main() { Name: "Global Error Handler Function", }) } + if mappedError.LogTheDetails { + //Todo: Store The Details Of the Error With Body And Other Extra Details Like AUTH KEY AND ETC + } return c.Status(mappedError.StatusCode).JSON(mappedError) }, }) diff --git a/src/apis/order/user/index.go b/src/apis/order/user/index.go index 89591eb..6356c47 100644 --- a/src/apis/order/user/index.go +++ b/src/apis/order/user/index.go @@ -1,8 +1,11 @@ package user -import "github.com/gofiber/fiber/v2" +import ( + "github.com/gofiber/fiber/v2" + "github.com/rpsoftech/bullion-server/src/middleware" +) func AddUserOrderApis(router fiber.Router) { - - // router.Use(middleware.AllowAllAdminsAndTradeUsers.Validate) + router.Use(middleware.AllowAllAdminsAndTradeUsers.Validate) + // router.Put("/placeMarketOrder",) } diff --git a/src/apis/order/user/placeMarketOrder.api.go b/src/apis/order/user/placeMarketOrder.api.go new file mode 100644 index 0000000..14e355b --- /dev/null +++ b/src/apis/order/user/placeMarketOrder.api.go @@ -0,0 +1,30 @@ +package user + +import ( + "github.com/gofiber/fiber/v2" + "github.com/rpsoftech/bullion-server/src/utility" +) + +type placeMarketOrderApiBody struct { + BullionId string `json:"bullionId" validate:"required,uuid"` + UserId string `json:"userId" validate:"required,uuid"` + GroupId string `json:"groupId" validate:"required,uuid"` + Weight int `json:"weight" validate:"required,min=0"` + ProductGroupMapId string `json:"productGroupMapId" validate:"required,uuid"` + McxPrice float64 `json:"mcxPrice" validate:"required,min=0"` + Price float64 `json:"price" validate:"required,min=0"` + // ReqId float64 `json:"reqId" validate:"required,min=0"` + // @MessageBody('pgm_id') pgmid: number, + // @MessageBody('mcx') mcx: number, + // @MessageBody('price') price: number, + // @MessageBody('req_id') req_id: number, +} + +func PlaceMarkerOrderApi(c *fiber.Ctx) error { + body := new(placeMarketOrderApiBody) + c.BodyParser(body) + if err := utility.ValidateReqInput(body); err != nil { + return err + } + return nil +} diff --git a/src/interfaces/req-interfaces.go b/src/interfaces/req-interfaces.go index 1936d4c..655c4e7 100644 --- a/src/interfaces/req-interfaces.go +++ b/src/interfaces/req-interfaces.go @@ -17,11 +17,12 @@ const ( ) type RequestError struct { - StatusCode int `json:"-"` - Code int `json:"code"` - Message string `json:"message"` - Name string `json:"name"` - Extra any `json:"extra,omitempty"` + StatusCode int `json:"-"` + Code int `json:"code"` + Message string `json:"message"` + Name string `json:"name"` + Extra any `json:"extra,omitempty"` + LogTheDetails bool `json:"-"` } func (r *RequestError) Error() string { diff --git a/src/services/order-general.service.go b/src/services/order-general.service.go index d5535d3..df40ca9 100644 --- a/src/services/order-general.service.go +++ b/src/services/order-general.service.go @@ -44,29 +44,7 @@ func getOrderGeneralService() *orderGeneralService { return OrderGeneralService } -func (service *orderGeneralService) ValidateUserAndGroupMapWithWeight(user *interfaces.TradeUserEntity, group *interfaces.TradeUserGroupEntity, groupMap *interfaces.TradeUserGroupMapEntity, weight int) (bool, error) { - - // Check for User Activation - if !user.IsActive { - return false, &interfaces.RequestError{ - StatusCode: http.StatusUnauthorized, - Code: interfaces.ERROR_PERMISSION_NOT_ALLOWED, - Message: "Account Is Not Active Please Contact Admin", - Name: "ERROR_PERMISSION_NOT_ALLOWED", - } - } - - if flags, err := service.flagService.GetFlags(user.BullionId); err != nil { - return false, err - } else if !flags.CanTrade { - // Check If Trading Is Disabled - return false, &interfaces.RequestError{ - StatusCode: 400, - Code: interfaces.ERROR_TRADING_IS_DISABLED, - Message: "Trading is disabled. Contact User", - Name: "BULLION_NOT_ACTIVE", - } - } +func (service *orderGeneralService) ValidateUserGroupForTrade(group *interfaces.TradeUserGroupEntity) (bool, error) { // Check for Group Activation if !group.IsActive { return false, &interfaces.RequestError{ @@ -85,7 +63,10 @@ func (service *orderGeneralService) ValidateUserAndGroupMapWithWeight(user *inte Name: "GROUP_NOT_ACTIVE", } } + return true, nil +} +func (service *orderGeneralService) ValidateUserAndGroupMapWithWeight(groupMap *interfaces.TradeUserGroupMapEntity, weight int) (bool, error) { // Check for Group Map Activation if !groupMap.IsActive { return false, &interfaces.RequestError{ @@ -134,6 +115,28 @@ func (service *orderGeneralService) findOrderDetailsAndValidate(userId string, g Code: interfaces.ERROR_PERMISSION_NOT_ALLOWED, Message: "MissMatch Group Id", Name: "MISS_MATCH_GROUP_ID", + Extra: "Solution Logout And Relogin", + } + } + // Check for User Activation + if !user.IsActive { + return nil, nil, nil, &interfaces.RequestError{ + StatusCode: http.StatusUnauthorized, + Code: interfaces.ERROR_PERMISSION_NOT_ALLOWED, + Message: "Account Is Not Active Please Contact Admin", + Name: "ERROR_PERMISSION_NOT_ALLOWED", + } + } + + if flags, err := service.flagService.GetFlags(user.BullionId); err != nil { + return nil, nil, nil, err + } else if !flags.CanTrade { + // Check If Trading Is Disabled + return nil, nil, nil, &interfaces.RequestError{ + StatusCode: 400, + Code: interfaces.ERROR_TRADING_IS_DISABLED, + Message: "Trading is disabled. Contact User", + Name: "BULLION_NOT_ACTIVE", } } // Get Group @@ -141,7 +144,9 @@ func (service *orderGeneralService) findOrderDetailsAndValidate(userId string, g if err != nil { return nil, nil, nil, err } - + if valid, err := service.ValidateUserGroupForTrade(group); !valid && err != nil { + return nil, nil, nil, err + } // Get Group Map groupMaps, err := service.groupService.GetGroupMapByGroupId(groupId, user.BullionId) if err != nil { @@ -161,10 +166,14 @@ func (service *orderGeneralService) findOrderDetailsAndValidate(userId string, g Code: interfaces.ERROR_GROUP_MAP_NOT_FOUND, Message: "Group Map Not Found", Name: "GROUP_MAP_NOT_FOUND", + Extra: "Solution Logout And Relogin", } } - service.ValidateUserAndGroupMapWithWeight(user, group, groupMap, weight) + if valid, err := service.ValidateUserAndGroupMapWithWeight(groupMap, weight); !valid && err != nil { + return nil, nil, nil, err + } + return user, group, groupMap, nil } func (service *orderGeneralService) PlaceOrder(orderType interfaces.OrderStatus, userId string, groupId string, groupMapId string, buySell interfaces.BuySell, weight int, price float64, placedBy string) (*interfaces.OrderEntity, error) { @@ -229,9 +238,11 @@ func (service *orderGeneralService) PlaceOrder(orderType interfaces.OrderStatus, if buySell == interfaces.Buy { calcSnapshot = &product.CalcSnapshot.Buy } + finalRate := interfaces.Calculate(rate, calcSnapshot) println("Final Rate", finalRate) + // service.orderRepo. // order := &interfaces.OrderEntity{ // TODO Check Hedging And Place Order From 011e34d22112d344eced31d4f8399a4ee8c01a31 Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Fri, 21 Feb 2025 11:32:15 +0530 Subject: [PATCH 22/23] merging Pull Brnach --- .github/workflows/builder.yml | 2 +- go.mod | 104 ++++---- go.sum | 224 +++++++++--------- .../get-in-active-trade-user.api.go | 21 ++ src/apis/data/trade-user/index.go | 1 + src/apis/order/user/index.go | 9 +- src/interfaces/admin-user.entity_test.go | 47 ++++ src/interfaces/base-entity.go | 2 +- src/interfaces/base-entity_test.go | 71 ++++++ src/mongodb/repos/bank-rate-calc.repo.go | 2 + src/mongodb/repos/trade-user.repo.go | 16 ++ src/services/trade-user.service.go | 7 +- 12 files changed, 345 insertions(+), 161 deletions(-) create mode 100644 src/apis/data/trade-user/get-in-active-trade-user.api.go create mode 100644 src/interfaces/admin-user.entity_test.go create mode 100644 src/interfaces/base-entity_test.go diff --git a/.github/workflows/builder.yml b/.github/workflows/builder.yml index 965e20e..05868b2 100644 --- a/.github/workflows/builder.yml +++ b/.github/workflows/builder.yml @@ -12,7 +12,7 @@ jobs: - name: Set up Go uses: actions/setup-go@v4 with: - go-version: '1.22.2' + go-version: '1.23.4' - name: Build run: go build -v ./... diff --git a/go.mod b/go.mod index 05781a8..699a6de 100644 --- a/go.mod +++ b/go.mod @@ -1,78 +1,92 @@ module github.com/rpsoftech/bullion-server -go 1.22.2 +go 1.23.4 require ( - cloud.google.com/go/firestore v1.15.0 - firebase.google.com/go/v4 v4.14.0 - github.com/go-faker/faker/v4 v4.4.1 - github.com/go-playground/validator/v10 v10.20.0 - github.com/gofiber/fiber/v2 v2.52.4 + cloud.google.com/go/firestore v1.17.0 + firebase.google.com/go/v4 v4.15.1 + github.com/go-faker/faker/v4 v4.5.0 + github.com/go-playground/validator/v10 v10.23.0 + github.com/gofiber/fiber/v2 v2.52.5 github.com/golang-jwt/jwt/v5 v5.2.1 github.com/google/uuid v1.6.0 github.com/joho/godotenv v1.5.1 github.com/mitchellh/mapstructure v1.5.0 - github.com/redis/go-redis/v9 v9.5.1 - go.mongodb.org/mongo-driver v1.15.0 - golang.org/x/crypto v0.22.0 - google.golang.org/api v0.177.0 + github.com/redis/go-redis/v9 v9.7.0 + go.mongodb.org/mongo-driver v1.17.1 + golang.org/x/crypto v0.31.0 + google.golang.org/api v0.210.0 ) require ( - cloud.google.com/go v0.112.2 // indirect - cloud.google.com/go/auth v0.3.0 // indirect - cloud.google.com/go/auth/oauth2adapt v0.2.2 // indirect - cloud.google.com/go/compute/metadata v0.3.0 // indirect - cloud.google.com/go/iam v1.1.7 // indirect - cloud.google.com/go/longrunning v0.5.6 // indirect - cloud.google.com/go/storage v1.40.0 // indirect + cel.dev/expr v0.19.1 // indirect + cloud.google.com/go v0.116.0 // indirect + cloud.google.com/go/auth v0.12.0 // indirect + cloud.google.com/go/auth/oauth2adapt v0.2.6 // indirect + cloud.google.com/go/compute/metadata v0.5.2 // indirect + cloud.google.com/go/iam v1.3.0 // indirect + cloud.google.com/go/longrunning v0.6.3 // indirect + cloud.google.com/go/monitoring v1.22.0 // indirect + cloud.google.com/go/storage v1.48.0 // indirect + github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.25.0 // indirect + github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.49.0 // indirect + github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.49.0 // indirect github.com/MicahParks/keyfunc v1.9.0 // indirect - github.com/andybalholm/brotli v1.1.0 // indirect + github.com/andybalholm/brotli v1.1.1 // indirect + github.com/census-instrumentation/opencensus-proto v0.4.1 // indirect github.com/cespare/xxhash/v2 v2.3.0 // indirect + github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 // indirect github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f // indirect + github.com/envoyproxy/go-control-plane v0.13.1 // indirect + github.com/envoyproxy/protoc-gen-validate v1.1.0 // indirect github.com/felixge/httpsnoop v1.0.4 // indirect - github.com/gabriel-vasile/mimetype v1.4.3 // indirect - github.com/go-logr/logr v1.4.1 // indirect + github.com/gabriel-vasile/mimetype v1.4.7 // indirect + github.com/go-logr/logr v1.4.2 // indirect github.com/go-logr/stdr v1.2.2 // indirect github.com/go-playground/locales v0.14.1 // indirect github.com/go-playground/universal-translator v0.18.1 // indirect - github.com/golang-jwt/jwt/v4 v4.5.0 // indirect - github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect + github.com/golang-jwt/jwt/v4 v4.5.1 // indirect + github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 // indirect github.com/golang/protobuf v1.5.4 // indirect github.com/golang/snappy v0.0.4 // indirect - github.com/google/s2a-go v0.1.7 // indirect - github.com/googleapis/enterprise-certificate-proxy v0.3.2 // indirect - github.com/googleapis/gax-go/v2 v2.12.3 // indirect - github.com/klauspost/compress v1.17.8 // indirect + github.com/google/s2a-go v0.1.8 // indirect + github.com/googleapis/enterprise-certificate-proxy v0.3.4 // indirect + github.com/googleapis/gax-go/v2 v2.14.0 // indirect + github.com/klauspost/compress v1.17.11 // indirect github.com/leodido/go-urn v1.4.0 // indirect github.com/mattn/go-colorable v0.1.13 // indirect github.com/mattn/go-isatty v0.0.20 // indirect - github.com/mattn/go-runewidth v0.0.15 // indirect + github.com/mattn/go-runewidth v0.0.16 // indirect github.com/montanaflynn/stats v0.7.1 // indirect + github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect github.com/rivo/uniseg v0.4.7 // indirect github.com/valyala/bytebufferpool v1.0.0 // indirect - github.com/valyala/fasthttp v1.52.0 // indirect + github.com/valyala/fasthttp v1.57.0 // indirect github.com/valyala/tcplisten v1.0.0 // 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-20240424034433-3c2c7870ae76 // indirect + github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect go.opencensus.io v0.24.0 // indirect - go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0 // indirect - go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 // indirect - go.opentelemetry.io/otel v1.26.0 // indirect - go.opentelemetry.io/otel/metric v1.26.0 // indirect - go.opentelemetry.io/otel/trace v1.26.0 // indirect - golang.org/x/net v0.24.0 // indirect - golang.org/x/oauth2 v0.19.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 - golang.org/x/time v0.5.0 // indirect + go.opentelemetry.io/contrib/detectors/gcp v1.32.0 // indirect + go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.57.0 // indirect + go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0 // indirect + go.opentelemetry.io/otel v1.32.0 // indirect + go.opentelemetry.io/otel/metric v1.32.0 // indirect + go.opentelemetry.io/otel/sdk v1.32.0 // indirect + go.opentelemetry.io/otel/sdk/metric v1.32.0 // indirect + go.opentelemetry.io/otel/trace v1.32.0 // indirect + golang.org/x/net v0.32.0 // indirect + golang.org/x/oauth2 v0.24.0 // indirect + golang.org/x/sync v0.10.0 // indirect + golang.org/x/sys v0.28.0 // indirect + golang.org/x/text v0.21.0 // indirect + golang.org/x/time v0.8.0 // indirect google.golang.org/appengine/v2 v2.0.6 // indirect - google.golang.org/genproto v0.0.0-20240429193739-8cf5692501f6 // indirect - google.golang.org/genproto/googleapis/api v0.0.0-20240429193739-8cf5692501f6 // indirect - google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 // indirect - google.golang.org/grpc v1.63.2 // indirect - google.golang.org/protobuf v1.34.0 // indirect + google.golang.org/genproto v0.0.0-20241206012308-a4fef0638583 // indirect + google.golang.org/genproto/googleapis/api v0.0.0-20241206012308-a4fef0638583 // indirect + google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583 // indirect + google.golang.org/grpc v1.68.1 // indirect + google.golang.org/grpc/stats/opentelemetry v0.0.0-20241028142157-ada6787961b3 // indirect + google.golang.org/protobuf v1.35.2 // indirect ) diff --git a/go.sum b/go.sum index 8c23764..51c5bac 100644 --- a/go.sum +++ b/go.sum @@ -1,75 +1,86 @@ +cel.dev/expr v0.19.1 h1:NciYrtDRIR0lNCnH1LFJegdjspNx9fI59O7TWcua/W4= +cel.dev/expr v0.19.1/go.mod h1:MrpN08Q+lEBs+bGYdLxxHkZoUSsCp0nSKTs0nTymJgw= cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw= -cloud.google.com/go v0.112.2 h1:ZaGT6LiG7dBzi6zNOvVZwacaXlmf3lRqnC4DQzqyRQw= -cloud.google.com/go v0.112.2/go.mod h1:iEqjp//KquGIJV/m+Pk3xecgKNhV+ry+vVTsy4TbDms= -cloud.google.com/go/auth v0.3.0 h1:PRyzEpGfx/Z9e8+lHsbkoUVXD0gnu4MNmm7Gp8TQNIs= -cloud.google.com/go/auth v0.3.0/go.mod h1:lBv6NKTWp8E3LPzmO1TbiiRKc4drLOfHsgmlH9ogv5w= -cloud.google.com/go/auth/oauth2adapt v0.2.2 h1:+TTV8aXpjeChS9M+aTtN/TjdQnzJvmzKFt//oWu7HX4= -cloud.google.com/go/auth/oauth2adapt v0.2.2/go.mod h1:wcYjgpZI9+Yu7LyYBg4pqSiaRkfEK3GQcpb7C/uyF1Q= -cloud.google.com/go/compute/metadata v0.3.0 h1:Tz+eQXMEqDIKRsmY3cHTL6FVaynIjX2QxYC4trgAKZc= -cloud.google.com/go/compute/metadata v0.3.0/go.mod h1:zFmK7XCadkQkj6TtorcaGlCW1hT1fIilQDwofLpJ20k= -cloud.google.com/go/firestore v1.15.0 h1:/k8ppuWOtNuDHt2tsRV42yI21uaGnKDEQnRFeBpbFF8= -cloud.google.com/go/firestore v1.15.0/go.mod h1:GWOxFXcv8GZUtYpWHw/w6IuYNux/BtmeVTMmjrm4yhk= -cloud.google.com/go/iam v1.1.7 h1:z4VHOhwKLF/+UYXAJDFwGtNF0b6gjsW1Pk9Ml0U/IoM= -cloud.google.com/go/iam v1.1.7/go.mod h1:J4PMPg8TtyurAUvSmPj8FF3EDgY1SPRZxcUGrn7WXGA= -cloud.google.com/go/longrunning v0.5.6 h1:xAe8+0YaWoCKr9t1+aWe+OeQgN/iJK1fEgZSXmjuEaE= -cloud.google.com/go/longrunning v0.5.6/go.mod h1:vUaDrWYOMKRuhiv6JBnn49YxCPz2Ayn9GqyjaBT8/mA= -cloud.google.com/go/storage v1.40.0 h1:VEpDQV5CJxFmJ6ueWNsKxcr1QAYOXEgxDa+sBbJahPw= -cloud.google.com/go/storage v1.40.0/go.mod h1:Rrj7/hKlG87BLqDJYtwR0fbPld8uJPbQ2ucUMY7Ir0g= -firebase.google.com/go/v4 v4.14.0 h1:Tc9jWzMUApUFUA5UUx/HcBeZ+LPjlhG2vNRfWJrcMwU= -firebase.google.com/go/v4 v4.14.0/go.mod h1:pLATyL6xH2o9AMe7rqHdmmOUE/Ph7wcwepIs+uiEKPg= +cloud.google.com/go v0.116.0 h1:B3fRrSDkLRt5qSHWe40ERJvhvnQwdZiHu0bJOpldweE= +cloud.google.com/go v0.116.0/go.mod h1:cEPSRWPzZEswwdr9BxE6ChEn01dWlTaF05LiC2Xs70U= +cloud.google.com/go/auth v0.12.0 h1:ARAD8r0lkiHw2go7kEnmviF6TOYhzLM+yDGcDt9mP68= +cloud.google.com/go/auth v0.12.0/go.mod h1:xxA5AqpDrvS+Gkmo9RqrGGRh6WSNKKOXhY3zNOr38tI= +cloud.google.com/go/auth/oauth2adapt v0.2.6 h1:V6a6XDu2lTwPZWOawrAa9HUK+DB2zfJyTuciBG5hFkU= +cloud.google.com/go/auth/oauth2adapt v0.2.6/go.mod h1:AlmsELtlEBnaNTL7jCj8VQFLy6mbZv0s4Q7NGBeQ5E8= +cloud.google.com/go/compute/metadata v0.5.2 h1:UxK4uu/Tn+I3p2dYWTfiX4wva7aYlKixAHn3fyqngqo= +cloud.google.com/go/compute/metadata v0.5.2/go.mod h1:C66sj2AluDcIqakBq/M8lw8/ybHgOZqin2obFxa/E5k= +cloud.google.com/go/firestore v1.17.0 h1:iEd1LBbkDZTFsLw3sTH50eyg4qe8eoG6CjocmEXO9aQ= +cloud.google.com/go/firestore v1.17.0/go.mod h1:69uPx1papBsY8ZETooc71fOhoKkD70Q1DwMrtKuOT/Y= +cloud.google.com/go/iam v1.3.0 h1:4Wo2qTaGKFtajbLpF6I4mywg900u3TLlHDb6mriLDPU= +cloud.google.com/go/iam v1.3.0/go.mod h1:0Ys8ccaZHdI1dEUilwzqng/6ps2YB6vRsjIe00/+6JY= +cloud.google.com/go/longrunning v0.6.3 h1:A2q2vuyXysRcwzqDpMMLSI6mb6o39miS52UEG/Rd2ng= +cloud.google.com/go/longrunning v0.6.3/go.mod h1:k/vIs83RN4bE3YCswdXC5PFfWVILjm3hpEUlSko4PiI= +cloud.google.com/go/monitoring v1.22.0 h1:mQ0040B7dpuRq1+4YiQD43M2vW9HgoVxY98xhqGT+YI= +cloud.google.com/go/monitoring v1.22.0/go.mod h1:hS3pXvaG8KgWTSz+dAdyzPrGUYmi2Q+WFX8g2hqVEZU= +cloud.google.com/go/storage v1.48.0 h1:FhBDHACbVtdPx7S/AbcKujPWiHvfO6F8OXGgCEbB2+o= +cloud.google.com/go/storage v1.48.0/go.mod h1:aFoDYNMAjv67lp+xcuZqjUKv/ctmplzQ3wJgodA7b+M= +firebase.google.com/go/v4 v4.15.1 h1:tR2dzKw1MIfCfG2bhAyxa5KQ57zcE7iFKmeYClET6ZM= +firebase.google.com/go/v4 v4.15.1/go.mod h1:eunxbsh4UXI2rA8po3sOiebvWYuW0DVxAdZFO0I6wdY= github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.25.0 h1:3c8yed4lgqTt+oTQ+JNMDo+F4xprBf+O/il4ZC0nRLw= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/detectors/gcp v1.25.0/go.mod h1:obipzmGjfSjam60XLwGfqUkJsfiheAl+TUjG+4yzyPM= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.49.0 h1:o90wcURuxekmXrtxmYWTyNla0+ZEHhud6DI1ZTxd1vI= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/exporter/metric v0.49.0/go.mod h1:6fTWu4m3jocfUZLYF5KsZC1TUfRvEjs7lM4crme/irw= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.49.0 h1:GYUJLfvd++4DMuMhCFLgLXvFwofIxh/qOwoGuS/LTew= +github.com/GoogleCloudPlatform/opentelemetry-operations-go/internal/resourcemapping v0.49.0/go.mod h1:wRbFgBQUVm1YXrvWKofAEmq9HNJTDphbAaJSSX01KUI= github.com/MicahParks/keyfunc v1.9.0 h1:lhKd5xrFHLNOWrDc4Tyb/Q1AJ4LCzQ48GVJyVIID3+o= github.com/MicahParks/keyfunc v1.9.0/go.mod h1:IdnCilugA0O/99dW+/MkvlyrsX8+L8+x95xuVNtM5jw= -github.com/andybalholm/brotli v1.1.0 h1:eLKJA0d02Lf0mVpIDgYnqXcUn0GqVmEFny3VuID1U3M= -github.com/andybalholm/brotli v1.1.0/go.mod h1:sms7XGricyQI9K10gOSf56VKKWS4oLer58Q+mhRPtnY= -github.com/bsm/ginkgo/v2 v2.12.0 h1:Ny8MWAHyOepLGlLKYmXG4IEkioBysk6GpaRTLC8zwWs= -github.com/bsm/ginkgo/v2 v2.12.0/go.mod h1:SwYbGRRDovPVboqFv0tPTcG1sN61LM1Z4ARdbAV9g4c= -github.com/bsm/gomega v1.27.10 h1:yeMWxP2pV2fG3FgAODIY8EiRE3dy0aeFYt4l7wh6yKA= -github.com/bsm/gomega v1.27.10/go.mod h1:JyEr/xRbxbtgWNi8tIEVPUYZ5Dzef52k01W3YH0H+O0= +github.com/andybalholm/brotli v1.1.1 h1:PR2pgnyFznKEugtsUo0xLdDop5SKXd5Qf5ysW+7XdTA= +github.com/andybalholm/brotli v1.1.1/go.mod h1:05ib4cKhjx3OQYUY22hTVd34Bc8upXjOLL2rKwwZBoA= github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU= +github.com/census-instrumentation/opencensus-proto v0.4.1 h1:iKLQ0xPNFxR/2hzXZMrBo8f1j86j5WHzznCCQxV/b8g= +github.com/census-instrumentation/opencensus-proto v0.4.1/go.mod h1:4T9NM4+4Vw91VeyqjLS6ao50K5bOcLKN6Q42XnYaRYw= github.com/cespare/xxhash/v2 v2.3.0 h1:UL815xU9SqsFlibzuggzjXhog7bL6oX9BbNZnL2UFvs= github.com/cespare/xxhash/v2 v2.3.0/go.mod h1:VGX0DQ3Q6kWi7AoAeZDth3/j3BFtOZR5XLFGgcrjCOs= github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw= github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc= +github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78 h1:QVw89YDxXxEe+l8gU8ETbOasdwEV+avkR75ZzsVV9WI= +github.com/cncf/xds/go v0.0.0-20240905190251-b4127c9b8d78/go.mod h1:W+zGtBO5Y1IgJhy4+A9GOqVhqLpfZi+vwmdNXUehLA8= github.com/davecgh/go-spew v1.1.0/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= -github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f h1:lO4WD4F/rVNCu3HqELle0jiPLLBs70cWOduZpkS1E78= github.com/dgryski/go-rendezvous v0.0.0-20200823014737-9f7001d12a5f/go.mod h1:cuUVRXasLTGF7a8hSLbxyZXjz+1KgoB3wDUb6vlszIc= 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= github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98= +github.com/envoyproxy/go-control-plane v0.13.1 h1:vPfJZCkob6yTMEgS+0TwfTUfbHjfy/6vOJ8hUWX/uXE= +github.com/envoyproxy/go-control-plane v0.13.1/go.mod h1:X45hY0mufo6Fd0KW3rqsGvQMw58jvjymeCzBU3mWyHw= github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c= +github.com/envoyproxy/protoc-gen-validate v1.1.0 h1:tntQDh69XqOCOZsDz0lVJQez/2L6Uu2PdjCQwWCJ3bM= +github.com/envoyproxy/protoc-gen-validate v1.1.0/go.mod h1:sXRDRVmzEbkM7CVcM06s9shE/m23dg3wzjl0UWqJ2q4= github.com/felixge/httpsnoop v1.0.4 h1:NFTV2Zj1bL4mc9sqWACXbQFVBBg2W3GPvqp8/ESS2Wg= github.com/felixge/httpsnoop v1.0.4/go.mod h1:m8KPJKqk1gH5J9DgRY2ASl2lWCfGKXixSwevea8zH2U= -github.com/gabriel-vasile/mimetype v1.4.3 h1:in2uUcidCuFcDKtdcBxlR0rJ1+fsokWf+uqxgUFjbI0= -github.com/gabriel-vasile/mimetype v1.4.3/go.mod h1:d8uq/6HKRL6CGdk+aubisF/M5GcPfT7nKyLpA0lbSSk= -github.com/go-faker/faker/v4 v4.4.1 h1:LY1jDgjVkBZWIhATCt+gkl0x9i/7wC61gZx73GTFb+Q= -github.com/go-faker/faker/v4 v4.4.1/go.mod h1:HRLrjis+tYsbFtIHufEPTAIzcZiRu0rS9EYl2Ccwme4= +github.com/gabriel-vasile/mimetype v1.4.7 h1:SKFKl7kD0RiPdbht0s7hFtjl489WcQ1VyPW8ZzUMYCA= +github.com/gabriel-vasile/mimetype v1.4.7/go.mod h1:GDlAgAyIRT27BhFl53XNAFtfjzOkLaF35JdEG0P7LtU= +github.com/go-faker/faker/v4 v4.5.0 h1:ARzAY2XoOL9tOUK+KSecUQzyXQsUaZHefjyF8x6YFHc= +github.com/go-faker/faker/v4 v4.5.0/go.mod h1:p3oq1GRjG2PZ7yqeFFfQI20Xm61DoBDlCA8RiSyZ48M= github.com/go-logr/logr v1.2.2/go.mod h1:jdQByPbusPIv2/zmleS9BjJVeZ6kBagPoEUsqbVz/1A= -github.com/go-logr/logr v1.4.1 h1:pKouT5E8xu9zeFC39JXRDukb6JFQPXM5p5I91188VAQ= -github.com/go-logr/logr v1.4.1/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= +github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= +github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-logr/stdr v1.2.2 h1:hSWxHoqTgW2S2qGc0LTAI563KZ5YKYRhT3MFKZMbjag= github.com/go-logr/stdr v1.2.2/go.mod h1:mMo/vtBO5dYbehREoey6XUKy/eSumjCCveDpRre4VKE= -github.com/go-playground/assert/v2 v2.2.0 h1:JvknZsQTYeFEAhQwI4qEt9cyV5ONwRHC+lYKSsYSR8s= -github.com/go-playground/assert/v2 v2.2.0/go.mod h1:VDjEfimB/XKnb+ZQfWdccd7VUvScMdVu0Titje2rxJ4= github.com/go-playground/locales v0.14.1 h1:EWaQ/wswjilfKLTECiXz7Rh+3BjFhfDFKv/oXslEjJA= github.com/go-playground/locales v0.14.1/go.mod h1:hxrqLVvrK65+Rwrd5Fc6F2O76J/NuW9t0sjnWqG1slY= github.com/go-playground/universal-translator v0.18.1 h1:Bcnm0ZwsGyWbCzImXv+pAJnYK9S473LQFuzCbDbfSFY= github.com/go-playground/universal-translator v0.18.1/go.mod h1:xekY+UJKNuX9WP91TpwSH2VMlDf28Uj24BCp08ZFTUY= -github.com/go-playground/validator/v10 v10.20.0 h1:K9ISHbSaI0lyB2eWMPJo+kOS/FBExVwjEviJTixqxL8= -github.com/go-playground/validator/v10 v10.20.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= -github.com/gofiber/fiber/v2 v2.52.4 h1:P+T+4iK7VaqUsq2PALYEfBBo6bJZ4q3FP8cZ84EggTM= -github.com/gofiber/fiber/v2 v2.52.4/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ= +github.com/go-playground/validator/v10 v10.23.0 h1:/PwmTwZhS0dPkav3cdK9kV1FsAmrL8sThn8IHr/sO+o= +github.com/go-playground/validator/v10 v10.23.0/go.mod h1:dbuPbCMFw/DrkbEynArYaCwl3amGuJotoKCe95atGMM= +github.com/gofiber/fiber/v2 v2.52.5 h1:tWoP1MJQjGEe4GB5TUGOi7P2E0ZMMRx5ZTG4rT+yGMo= +github.com/gofiber/fiber/v2 v2.52.5/go.mod h1:KEOE+cXMhXG0zHc9d8+E38hoX+ZN7bhOtgeF2oT6jrQ= github.com/golang-jwt/jwt/v4 v4.4.2/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= -github.com/golang-jwt/jwt/v4 v4.5.0 h1:7cYmW1XlMY7h7ii7UhUyChSgS5wUJEnm9uZVTGqOWzg= -github.com/golang-jwt/jwt/v4 v4.5.0/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= +github.com/golang-jwt/jwt/v4 v4.5.1 h1:JdqV9zKUdtaa9gdPlywC3aeoEsR681PlKC+4F5gQgeo= +github.com/golang-jwt/jwt/v4 v4.5.1/go.mod h1:m21LjoU+eqJr34lmDMbreY2eSTRJ1cv77w39/MY0Ch0= github.com/golang-jwt/jwt/v5 v5.2.1 h1:OuVbFODueb089Lh128TAcimifWaLhJwVflnrgM17wHk= github.com/golang-jwt/jwt/v5 v5.2.1/go.mod h1:pqrtFR0X4osieyHYxtmOUWsAWrfe1Q5UVIyoH402zdk= github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q= github.com/golang/groupcache v0.0.0-20200121045136-8c9f03a8e57e/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da h1:oI5xCqsCo564l8iNU+DwB5epxmsaqB+rhGL0m5jtYqE= -github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da/go.mod h1:cIg4eruTrX1D+g88fzRXU5OdNfaM+9IcxsU14FzY7Hc= +github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8 h1:f+oWsMOmNPc8JmEHVZIycC7hBoQxHH9pNKQORJNozsQ= +github.com/golang/groupcache v0.0.0-20241129210726-2c02b8208cf8/go.mod h1:wcDNUvekVysuuOpQKo3191zZyTpiI6se1N1ULghS0sw= github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A= github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U= @@ -92,23 +103,19 @@ github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/ github.com/google/go-cmp v0.5.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.3/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= github.com/google/go-cmp v0.5.5/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE= -github.com/google/go-cmp v0.6.0 h1:ofyhxvXcZhMsU5ulbFiLKl/XBFqE1GSq7atu8tAmTRI= -github.com/google/go-cmp v0.6.0/go.mod h1:17dUlkBOakJ0+DkrSSNjCkIjxS6bF9zb3elmeNGIjoY= -github.com/google/martian/v3 v3.3.2 h1:IqNFLAmvJOgVlpdEBiQbDc2EwKW77amAycfTuWKdfvw= -github.com/google/martian/v3 v3.3.2/go.mod h1:oBOf6HBosgwRXnUGWUB05QECsc6uvmMiJ3+6W4l/CUk= -github.com/google/s2a-go v0.1.7 h1:60BLSyTrOV4/haCDW4zb1guZItoSq8foHCXrAnjBo/o= -github.com/google/s2a-go v0.1.7/go.mod h1:50CgR4k1jNlWBu4UfS4AcfhVe1r6pdZPygJ3R8F0Qdw= +github.com/google/s2a-go v0.1.8 h1:zZDs9gcbt9ZPLV0ndSyQk6Kacx2g/X+SKYovpnz3SMM= +github.com/google/s2a-go v0.1.8/go.mod h1:6iNWHTpQ+nfNRN5E00MSdfDwVesa8hhS32PhPO8deJA= github.com/google/uuid v1.1.2/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= github.com/google/uuid v1.6.0 h1:NIvaJDMOsjHA8n1jAhLSgzrAzy1Hgr+hNrb57e+94F0= github.com/google/uuid v1.6.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= -github.com/googleapis/enterprise-certificate-proxy v0.3.2 h1:Vie5ybvEvT75RniqhfFxPRy3Bf7vr3h0cechB90XaQs= -github.com/googleapis/enterprise-certificate-proxy v0.3.2/go.mod h1:VLSiSSBs/ksPL8kq3OBOQ6WRI2QnaFynd1DCjZ62+V0= -github.com/googleapis/gax-go/v2 v2.12.3 h1:5/zPPDvw8Q1SuXjrqrZslrqT7dL/uJT2CQii/cLCKqA= -github.com/googleapis/gax-go/v2 v2.12.3/go.mod h1:AKloxT6GtNbaLm8QTNSidHUVsHYcBHwWRvkNFJUQcS4= +github.com/googleapis/enterprise-certificate-proxy v0.3.4 h1:XYIDZApgAnrN1c855gTgghdIA6Stxb52D5RnLI1SLyw= +github.com/googleapis/enterprise-certificate-proxy v0.3.4/go.mod h1:YKe7cfqYXjKGpGvmSg28/fFvhNzinZQm8DGnaburhGA= +github.com/googleapis/gax-go/v2 v2.14.0 h1:f+jMrjBPl+DL9nI4IQzLUxMq7XrAqFYB7hBPqMNIe8o= +github.com/googleapis/gax-go/v2 v2.14.0/go.mod h1:lhBCnjdLrWRaPvLWhmc8IS24m9mr07qSYnHncrgo+zk= github.com/joho/godotenv v1.5.1 h1:7eLL/+HRGLY0ldzfGMeQkb7vMd0as4CfYvUVzLqw0N0= github.com/joho/godotenv v1.5.1/go.mod h1:f4LDr5Voq0i2e/R5DDNOoa2zzDfwtkZa6DnEwAbqwq4= -github.com/klauspost/compress v1.17.8 h1:YcnTYrq7MikUT7k0Yb5eceMmALQPYBW/Xltxn0NAMnU= -github.com/klauspost/compress v1.17.8/go.mod h1:Di0epgTjJY877eYKx5yC51cX2A2Vl2ibi7bDH9ttBbw= +github.com/klauspost/compress v1.17.11 h1:In6xLpyWOi1+C7tXUUWv2ot1QvBjxevKAaI6IXrJmUc= +github.com/klauspost/compress v1.17.11/go.mod h1:pMDklpSncoRMuLFrf1W9Ss9KT+0rH90U12bZKk7uwG0= github.com/leodido/go-urn v1.4.0 h1:WT9HwE9SGECu3lg4d/dIA+jxlljEa1/ffXKmRjqdmIQ= github.com/leodido/go-urn v1.4.0/go.mod h1:bvxc+MVxLKB4z00jd1z+Dvzr47oO32F/QSNjSBOlFxI= github.com/mattn/go-colorable v0.1.13 h1:fFA4WZxdEF4tXPZVKMLwD8oUnCTTo08duU7wxecdEvA= @@ -116,17 +123,18 @@ github.com/mattn/go-colorable v0.1.13/go.mod h1:7S9/ev0klgBDR4GtXTXX8a3vIGJpMovk github.com/mattn/go-isatty v0.0.16/go.mod h1:kYGgaQfpe5nmfYZH+SKPsOc2e4SrIfOl2e/yFXSvRLM= github.com/mattn/go-isatty v0.0.20 h1:xfD0iDuEKnDkl03q4limB+vH+GxLEtL/jb4xVJSWWEY= github.com/mattn/go-isatty v0.0.20/go.mod h1:W+V8PltTTMOvKvAeJH7IuucS94S2C6jfK/D7dTCTo3Y= -github.com/mattn/go-runewidth v0.0.15 h1:UNAjwbU9l54TA3KzvqLGxwWjHmMgBUVhBiTjelZgg3U= -github.com/mattn/go-runewidth v0.0.15/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= +github.com/mattn/go-runewidth v0.0.16 h1:E5ScNMtiwvlvB5paMFdw9p4kSQzbXFikJ5SQO6TULQc= +github.com/mattn/go-runewidth v0.0.16/go.mod h1:Jdepj2loyihRzMpdS35Xk/zdY8IAYHsh153qUoGf23w= github.com/mitchellh/mapstructure v1.5.0 h1:jeMsZIYE/09sWLaz43PL7Gy6RuMjD2eJVyuac5Z2hdY= github.com/mitchellh/mapstructure v1.5.0/go.mod h1:bFUtVrKA4DC2yAKiSyO/QUcy7e+RRV2QTWOzhPopBRo= github.com/montanaflynn/stats v0.7.1 h1:etflOAAHORrCC44V+aR6Ftzort912ZU+YLiSTuV8eaE= github.com/montanaflynn/stats v0.7.1/go.mod h1:etXPPgVO6n31NxCd9KQUMvCM+ve0ruNzt6R8Bnaayow= -github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= +github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 h1:GFCKgmp0tecUJ0sJuv4pzYCqS9+RGSn52M3FUwPs+uo= +github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10/go.mod h1:t/avpk3KcrXxUnYOhZhMXJlSEyie6gQbtLq5NM3loB8= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA= -github.com/redis/go-redis/v9 v9.5.1 h1:H1X4D3yHPaYrkL5X06Wh6xNVM/pX0Ft4RV0vMGvLBh8= -github.com/redis/go-redis/v9 v9.5.1/go.mod h1:hdY0cQFCN4fnSYT6TkisLufl/4W5UIXyv0b/CLO2V2M= +github.com/redis/go-redis/v9 v9.7.0 h1:HhLSs+B6O021gwzl+locl0zEDnyNkxMtf/Z3NNBMa9E= +github.com/redis/go-redis/v9 v9.7.0/go.mod h1:f6zhXITC7JUJIlPEiBOTXxJgPLdZcA93GewI7inzyWw= github.com/rivo/uniseg v0.2.0/go.mod h1:J6wj4VEh+S6ZtnVlnTBMWIodfgj8LQOQFoIToxlJtxc= github.com/rivo/uniseg v0.4.7 h1:WUdvkW8uEhrYfLC4ZzdpI2ztxP1I582+49Oc5Mq64VQ= github.com/rivo/uniseg v0.4.7/go.mod h1:FN3SvrM+Zdj16jyLfmOkMNblXMcoc8DfTHruCPUcx88= @@ -136,12 +144,10 @@ github.com/stretchr/objx v0.5.0/go.mod h1:Yh+to48EsGEfYuaHDzXPcE3xhTkx73EhmCGUpE github.com/stretchr/testify v1.7.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg= github.com/stretchr/testify v1.8.0/go.mod h1:yNjHg4UonilssWZ8iaSj1OCr/vHnekPRkoO+kdMU+MU= github.com/stretchr/testify v1.8.1/go.mod h1:w2LPCIKwWwSfY2zedu0+kehJoqGctiVI29o6fzry7u4= -github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg= -github.com/stretchr/testify v1.9.0/go.mod h1:r2ic/lqez/lEtzL7wO/rwa5dbSLXVDPFyf8C91i36aY= github.com/valyala/bytebufferpool v1.0.0 h1:GqA5TC/0021Y/b9FG4Oi9Mr3q7XYx6KllzawFIhcdPw= github.com/valyala/bytebufferpool v1.0.0/go.mod h1:6bBcMArwyJ5K/AmCkWv1jt77kVWyCJ6HpOuEn7z0Csc= -github.com/valyala/fasthttp v1.52.0 h1:wqBQpxH71XW0e2g+Og4dzQM8pk34aFYlA1Ga8db7gU0= -github.com/valyala/fasthttp v1.52.0/go.mod h1:hf5C4QnVMkNXMspnsUlfM3WitlgYflyhHYoKol/szxQ= +github.com/valyala/fasthttp v1.57.0 h1:Xw8SjWGEP/+wAAgyy5XTvgrWlOD1+TxbbvNADYCm1Tg= +github.com/valyala/fasthttp v1.57.0/go.mod h1:h6ZBaPRlzpZ6O3H5t2gEk1Qi33+TmLvfwgLLp0t9CpE= github.com/valyala/tcplisten v1.0.0 h1:rBHj/Xf+E1tRGZyWIWwJDiRY0zc1Js+CV5DqwacVSA8= github.com/valyala/tcplisten v1.0.0/go.mod h1:T0xQ8SeCZGxckz9qRXTfG43PvQ/mcWh7FwZEA7Ioqkc= github.com/xdg-go/pbkdf2 v1.0.0 h1:Su7DPu48wXMwC3bs7MCNG+z4FhcyEuz5dlvchbq0B0c= @@ -150,30 +156,35 @@ github.com/xdg-go/scram v1.1.2 h1:FHX5I5B4i4hKRVRBCFRxq1iQRej7WO3hhBuJf+UUySY= github.com/xdg-go/scram v1.1.2/go.mod h1:RT/sEzTbU5y00aCK8UOx6R7YryM0iF1N2MOmC3kKLN4= github.com/xdg-go/stringprep v1.0.4 h1:XLI/Ng3O1Atzq0oBs3TWm+5ZVgkq2aqdlvP9JtoZ6c8= github.com/xdg-go/stringprep v1.0.4/go.mod h1:mPGuuIYwz7CmR2bT9j4GbQqutWS1zV24gijq1dTyGkM= -github.com/youmark/pkcs8 v0.0.0-20240424034433-3c2c7870ae76 h1:tBiBTKHnIjovYoLX/TPkcf+OjqqKGQrPtGT3Foz+Pgo= -github.com/youmark/pkcs8 v0.0.0-20240424034433-3c2c7870ae76/go.mod h1:SQliXeA7Dhkt//vS29v3zpbEwoa+zb2Cn5xj5uO4K5U= +github.com/xyproto/randomstring v1.0.5/go.mod h1:rgmS5DeNXLivK7YprL0pY+lTuhNQW3iGxZ18UQApw/E= +github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 h1:ilQV1hzziu+LLM3zUTJ0trRztfwgjqKnBWNtSRkbmwM= +github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78/go.mod h1:aL8wCCfTfSfmXjznFBSZNN13rSJjlIOI1fUNAtF7rmI= github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= -go.mongodb.org/mongo-driver v1.15.0 h1:rJCKC8eEliewXjZGf0ddURtl7tTVy1TK3bfl0gkUSLc= -go.mongodb.org/mongo-driver v1.15.0/go.mod h1:Vzb0Mk/pa7e6cWw85R4F/endUC3u0U9jGcNU603k65c= +go.mongodb.org/mongo-driver v1.17.1 h1:Wic5cJIwJgSpBhe3lx3+/RybR5PiYRMpVFgO7cOHyIM= +go.mongodb.org/mongo-driver v1.17.1/go.mod h1:wwWm/+BuOddhcq3n68LKRmgk2wXzmF6s0SFOa0GINL4= go.opencensus.io v0.24.0 h1:y73uSU6J157QMP2kn2r30vwW1A2W2WFwSCGnAVxeaD0= go.opencensus.io v0.24.0/go.mod h1:vNK8G9p7aAivkbmorf4v+7Hgx+Zs0yY+0fOtgBfjQKo= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0 h1:A3SayB3rNyt+1S6qpI9mHPkeHTZbD7XILEqWnYZb2l0= -go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.51.0/go.mod h1:27iA5uvhuRNmalO+iEUdVn5ZMj2qy10Mm+XRIpRmyuU= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0 h1:Xs2Ncz0gNihqu9iosIZ5SkBbWo5T8JhhLJFMQL1qmLI= -go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.51.0/go.mod h1:vy+2G/6NvVMpwGX/NyLqcC41fxepnuKHk16E6IZUcJc= -go.opentelemetry.io/otel v1.26.0 h1:LQwgL5s/1W7YiiRwxf03QGnWLb2HW4pLiAhaA5cZXBs= -go.opentelemetry.io/otel v1.26.0/go.mod h1:UmLkJHUAidDval2EICqBMbnAd0/m2vmpf/dAM+fvFs4= -go.opentelemetry.io/otel/metric v1.26.0 h1:7S39CLuY5Jgg9CrnA9HHiEjGMF/X2VHvoXGgSllRz30= -go.opentelemetry.io/otel/metric v1.26.0/go.mod h1:SY+rHOI4cEawI9a7N1A4nIg/nTQXe1ccCNWYOJUrpX4= -go.opentelemetry.io/otel/sdk v1.22.0 h1:6coWHw9xw7EfClIC/+O31R8IY3/+EiRFHevmHafB2Gw= -go.opentelemetry.io/otel/sdk v1.22.0/go.mod h1:iu7luyVGYovrRpe2fmj3CVKouQNdTOkxtLzPvPz1DOc= -go.opentelemetry.io/otel/trace v1.26.0 h1:1ieeAUb4y0TE26jUFrCIXKpTuVK7uJGN9/Z/2LP5sQA= -go.opentelemetry.io/otel/trace v1.26.0/go.mod h1:4iDxvGDQuUkHve82hJJ8UqrwswHYsZuWCBllGV2U2y0= +go.opentelemetry.io/contrib/detectors/gcp v1.32.0 h1:P78qWqkLSShicHmAzfECaTgvslqHxblNE9j62Ws1NK8= +go.opentelemetry.io/contrib/detectors/gcp v1.32.0/go.mod h1:TVqo0Sda4Cv8gCIixd7LuLwW4EylumVWfhjZJjDD4DU= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.57.0 h1:qtFISDHKolvIxzSs0gIaiPUPR0Cucb0F2coHC7ZLdps= +go.opentelemetry.io/contrib/instrumentation/google.golang.org/grpc/otelgrpc v0.57.0/go.mod h1:Y+Pop1Q6hCOnETWTW4NROK/q1hv50hM7yDaUTjG8lp8= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0 h1:DheMAlT6POBP+gh8RUH19EOTnQIor5QE0uSRPtzCpSw= +go.opentelemetry.io/contrib/instrumentation/net/http/otelhttp v0.57.0/go.mod h1:wZcGmeVO9nzP67aYSLDqXNWK87EZWhi7JWj1v7ZXf94= +go.opentelemetry.io/otel v1.32.0 h1:WnBN+Xjcteh0zdk01SVqV55d/m62NJLJdIyb4y/WO5U= +go.opentelemetry.io/otel v1.32.0/go.mod h1:00DCVSB0RQcnzlwyTfqtxSm+DRr9hpYrHjNGiBHVQIg= +go.opentelemetry.io/otel/metric v1.32.0 h1:xV2umtmNcThh2/a/aCP+h64Xx5wsj8qqnkYZktzNa0M= +go.opentelemetry.io/otel/metric v1.32.0/go.mod h1:jH7CIbbK6SH2V2wE16W05BHCtIDzauciCRLoc/SyMv8= +go.opentelemetry.io/otel/sdk v1.32.0 h1:RNxepc9vK59A8XsgZQouW8ue8Gkb4jpWtJm9ge5lEG4= +go.opentelemetry.io/otel/sdk v1.32.0/go.mod h1:LqgegDBjKMmb2GC6/PrTnteJG39I8/vJCAP9LlJXEjU= +go.opentelemetry.io/otel/sdk/metric v1.32.0 h1:rZvFnvmvawYb0alrYkjraqJq0Z4ZUJAiyYCU9snn1CU= +go.opentelemetry.io/otel/sdk/metric v1.32.0/go.mod h1:PWeZlq0zt9YkYAp3gjKZ0eicRYvOh1Gd+X99x6GHpCQ= +go.opentelemetry.io/otel/trace v1.32.0 h1:WIC9mYrXf8TmY/EXuULKc8hR17vE+Hjv2cssQDe03fM= +go.opentelemetry.io/otel/trace v1.32.0/go.mod h1:+i4rkvCraA+tG6AzwloGaCtkx53Fa+L+V8e9a7YvhT8= golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= golang.org/x/crypto v0.0.0-20200622213623-75b288015ac9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto= golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= -golang.org/x/crypto v0.22.0 h1:g1v0xeRhjcugydODzvb3mEM9SQ0HGp9s/nh3COQ/C30= -golang.org/x/crypto v0.22.0/go.mod h1:vr6Su+7cTlO45qkww3VDJlzDn0ctJvRgYbC2NvXHt+M= +golang.org/x/crypto v0.31.0 h1:ihbySMvVjLAeSH1IbfcRTkD/iNscyz8rGzjF/E5hV6U= +golang.org/x/crypto v0.31.0/go.mod h1:kDsLvtWBEx7MV9tJOj9bnXsPbxwJQ6csT/x4KIN4Ssk= golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA= golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE= golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU= @@ -188,17 +199,17 @@ golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLL golang.org/x/net v0.0.0-20201110031124-69a78807bb2b/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU= golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= -golang.org/x/net v0.24.0 h1:1PcaxkF854Fu3+lvBIx5SYn9wRlBzzcnHZSiaFFAb0w= -golang.org/x/net v0.24.0/go.mod h1:2Q7sJY5mzlzWjKtYUEXSlBWCdyaioyXzRB2RtU8KVE8= +golang.org/x/net v0.32.0 h1:ZqPmj8Kzc+Y6e0+skZsuACbx+wzMgo5MQsJh9Qd6aYI= +golang.org/x/net v0.32.0/go.mod h1:CwU0IoeOlnQQWJ6ioyFrfRuomB8GKF6KbYXZVyeXNfs= golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U= -golang.org/x/oauth2 v0.19.0 h1:9+E/EZBCbTLNrbN35fHv/a/d/mOBatymz1zbtQrXpIg= -golang.org/x/oauth2 v0.19.0/go.mod h1:vYi7skDa1x015PmRRYZ7+s1cWyPgrPiSYRe4rnsexc8= +golang.org/x/oauth2 v0.24.0 h1:KTBBxWqUa0ykRPLtV69rRto9TLXcqYkeswu48x/gvNE= +golang.org/x/oauth2 v0.24.0/go.mod h1:XYTD2NtWslqkgxebSiOHnXEap4TF09sJSc7H1sXbhtI= golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= -golang.org/x/sync v0.7.0 h1:YsImfSBoP9QPYL0xyKJPq0gcaJdG3rInoqxTWbfQu9M= -golang.org/x/sync v0.7.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= +golang.org/x/sync v0.10.0 h1:3NQrjDixjgGwUOCaF8w2+VYHv0Ve/vGYSbdkTa98gmQ= +golang.org/x/sync v0.10.0/go.mod h1:Czt+wKu1gCyEFDUtn0jG5QVvpJ6rzVqr5aXyt9drQfk= golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= golang.org/x/sys v0.0.0-20190412213103-97732733099d/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= @@ -209,18 +220,18 @@ golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBc golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.0.0-20220811171246-fbc7d0a398ab/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= golang.org/x/sys v0.6.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= -golang.org/x/sys v0.19.0 h1:q5f1RH2jigJ1MoAWp2KTp3gm5zAGFUTarQZ5U386+4o= -golang.org/x/sys v0.19.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= +golang.org/x/sys v0.28.0 h1:Fksou7UEQUWlKvIdsqzJmUmCX3cZuD2+P3XyyzwMhlA= +golang.org/x/sys v0.28.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= golang.org/x/text v0.3.8/go.mod h1:E6s5w1FMmriuDzIBO73fBruAKo1PCIq6d2Q6DHfQ8WQ= -golang.org/x/text v0.14.0 h1:ScX5w1eTa3QqT8oi6+ziP7dTV1S2+ALU0bI+0zXKWiQ= -golang.org/x/text v0.14.0/go.mod h1:18ZOQIKpY8NJVqYksKHtTdi31H5itFRjB5/qKTNYzSU= -golang.org/x/time v0.5.0 h1:o7cqy6amK/52YcAKIPlM3a+Fpj35zvRj2TP+e1xFSfk= -golang.org/x/time v0.5.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= +golang.org/x/text v0.21.0 h1:zyQAAkrwaneQ066sspRyJaG9VNi/YJ1NfzcGB3hZ/qo= +golang.org/x/text v0.21.0/go.mod h1:4IBbMaMmOPCJ8SecivzSH54+73PCFmPWxNTLm+vZkEQ= +golang.org/x/time v0.8.0 h1:9i3RxcPv3PZnitoVGMPDKZSq1xW1gK1Xy3ArNOGZfEg= +golang.org/x/time v0.8.0/go.mod h1:3BpzKBy/shNhVucY/MWOyx10tF3SFh9QdLuxbVysPQM= golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY= @@ -230,10 +241,8 @@ golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtn golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= -golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028 h1:+cNy6SZtPcJQH3LJVLOSmiC7MMxXNOb3PU/VUEz+EhU= -golang.org/x/xerrors v0.0.0-20231012003039-104605ab7028/go.mod h1:NDW/Ps6MPRej6fsCIbMTohpP40sJ/P/vI1MoTEGwX90= -google.golang.org/api v0.177.0 h1:8a0p/BbPa65GlqGWtUKxot4p0TV8OGOfyTjtmkXNXmk= -google.golang.org/api v0.177.0/go.mod h1:srbhue4MLjkjbkux5p3dw/ocYOSZTaIEvf7bCOnFQDw= +google.golang.org/api v0.210.0 h1:HMNffZ57OoZCRYSbdWVRoqOa8V8NIHLL0CzdBPLztWk= +google.golang.org/api v0.210.0/go.mod h1:B9XDZGnx2NtyjzVkOVTGrFSAVZgPcbedzKg/gTLwqBs= google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM= google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4= google.golang.org/appengine/v2 v2.0.6 h1:LvPZLGuchSBslPBp+LAhihBeGSiRh1myRoYK4NtuBIw= @@ -241,19 +250,21 @@ google.golang.org/appengine/v2 v2.0.6/go.mod h1:WoEXGoXNfa0mLvaH5sV3ZSGXwVmy8yf7 google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc= google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc= google.golang.org/genproto v0.0.0-20200526211855-cb27e3aa2013/go.mod h1:NbSheEEYHJ7i3ixzK3sjbqSGDJWnxyFXZblF3eUsNvo= -google.golang.org/genproto v0.0.0-20240429193739-8cf5692501f6 h1:MTmrc2F5TZKDKXigcZetYkH04YwqtOPEQJwh4PPOgfk= -google.golang.org/genproto v0.0.0-20240429193739-8cf5692501f6/go.mod h1:2ROWwqCIx97Y7CSyp11xB8fori0wzvD6+gbacaf5c8I= -google.golang.org/genproto/googleapis/api v0.0.0-20240429193739-8cf5692501f6 h1:DTJM0R8LECCgFeUwApvcEJHz85HLagW8uRENYxHh1ww= -google.golang.org/genproto/googleapis/api v0.0.0-20240429193739-8cf5692501f6/go.mod h1:10yRODfgim2/T8csjQsMPgZOMvtytXKTDRzH6HRGzRw= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6 h1:DujSIu+2tC9Ht0aPNA7jgj23Iq8Ewi5sgkQ++wdvonE= -google.golang.org/genproto/googleapis/rpc v0.0.0-20240429193739-8cf5692501f6/go.mod h1:WtryC6hu0hhx87FDGxWCDptyssuo68sk10vYjF+T9fY= +google.golang.org/genproto v0.0.0-20241206012308-a4fef0638583 h1:pjPnE7Rv3PAwHISLRJhA3HQTnM2uu5qcnroxTkRb5G8= +google.golang.org/genproto v0.0.0-20241206012308-a4fef0638583/go.mod h1:dW27OyXi0Ph+N43jeCWMFC86aTT5VgdeQtOSf0Hehdw= +google.golang.org/genproto/googleapis/api v0.0.0-20241206012308-a4fef0638583 h1:v+j+5gpj0FopU0KKLDGfDo9ZRRpKdi5UBrCP0f76kuY= +google.golang.org/genproto/googleapis/api v0.0.0-20241206012308-a4fef0638583/go.mod h1:jehYqy3+AhJU9ve55aNOaSml7wUXjF9x6z2LcCfpAhY= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583 h1:IfdSdTcLFy4lqUQrQJLkLt1PB+AsqVz6lwkWPzWEz10= +google.golang.org/genproto/googleapis/rpc v0.0.0-20241206012308-a4fef0638583/go.mod h1:5uTbfoYQed2U9p3KIj2/Zzm02PYhndfdmML0qC3q3FU= google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c= google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg= google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY= google.golang.org/grpc v1.27.0/go.mod h1:qbnxyOmOxrQa7FizSgH+ReBfzJrCY1pSN7KXBS8abTk= google.golang.org/grpc v1.33.2/go.mod h1:JMHMWHQWaTccqQQlmk3MJZS+GWXOdAesneDmEnv2fbc= -google.golang.org/grpc v1.63.2 h1:MUeiw1B2maTVZthpU5xvASfTh3LDbxHd6IJ6QQVU+xM= -google.golang.org/grpc v1.63.2/go.mod h1:WAX/8DgncnokcFUldAxq7GeB5DXHDbMF+lLvDomNkRA= +google.golang.org/grpc v1.68.1 h1:oI5oTa11+ng8r8XMMN7jAOmWfPZWbYpCFaMUTACxkM0= +google.golang.org/grpc v1.68.1/go.mod h1:+q1XYFJjShcqn0QZHvCyeR4CXPA+llXIeUIfIe00waw= +google.golang.org/grpc/stats/opentelemetry v0.0.0-20241028142157-ada6787961b3 h1:hUfOButuEtpc0UvYiaYRbNwxVYr0mQQOWq6X8beJ9Gc= +google.golang.org/grpc/stats/opentelemetry v0.0.0-20241028142157-ada6787961b3/go.mod h1:jzYlkSMbKypzuu6xoAEijsNVo9ZeDF1u/zCfFgsx7jg= google.golang.org/protobuf v0.0.0-20200109180630-ec00e32a8dfd/go.mod h1:DFci5gLYBciE7Vtevhsrf46CRTquxDuWsQurQQe4oz8= google.golang.org/protobuf v0.0.0-20200221191635-4d8936d0db64/go.mod h1:kwYJMbMJ01Woi6D6+Kah6886xMZcty6N08ah7+eCXa0= google.golang.org/protobuf v0.0.0-20200228230310-ab0ca4ff8a60/go.mod h1:cfTl7dwQJ+fmap5saPgwCLgHXTUD7jkjRqWcaiX5VyM= @@ -265,11 +276,10 @@ google.golang.org/protobuf v1.23.1-0.20200526195155-81db48ad09cc/go.mod h1:EGpAD google.golang.org/protobuf v1.25.0/go.mod h1:9JNX74DMeImyA3h4bdi1ymwjUzf21/xIlbajtzgsN7c= google.golang.org/protobuf v1.26.0-rc.1/go.mod h1:jlhhOSvTdKEhbULTjvd4ARK9grFBp09yW+WbY/TyQbw= google.golang.org/protobuf v1.30.0/go.mod h1:HV8QOd/L58Z+nl8r43ehVNZIU/HEI6OcFqwMG9pJV4I= -google.golang.org/protobuf v1.34.0 h1:Qo/qEd2RZPCf2nKuorzksSknv0d3ERwp1vFG38gSmH4= -google.golang.org/protobuf v1.34.0/go.mod h1:c6P6GXX6sHbq/GpV6MGZEdwhWPcYBgnhAHhKbcUYpos= +google.golang.org/protobuf v1.35.2 h1:8Ar7bF+apOIoThw1EdZl0p1oWvMqTHmpA2fRTyZO8io= +google.golang.org/protobuf v1.35.2/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= -gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4= diff --git a/src/apis/data/trade-user/get-in-active-trade-user.api.go b/src/apis/data/trade-user/get-in-active-trade-user.api.go new file mode 100644 index 0000000..620a9ce --- /dev/null +++ b/src/apis/data/trade-user/get-in-active-trade-user.api.go @@ -0,0 +1,21 @@ +package tradeuser + +import ( + "github.com/gofiber/fiber/v2" + "github.com/rpsoftech/bullion-server/src/interfaces" + "github.com/rpsoftech/bullion-server/src/services" +) + +func apiGetInActiveTradeUsers(c *fiber.Ctx) error { + bullionId, err := interfaces.ExtractBullionIdFromCtx(c) + if err != nil { + return err + } + entity, err := services.TradeUserService.FindAndReturnAllInActiveTradeUsers(bullionId) + if err != nil { + return err + } else { + return c.JSON(entity) + } + +} diff --git a/src/apis/data/trade-user/index.go b/src/apis/data/trade-user/index.go index 238af0d..5bd9435 100644 --- a/src/apis/data/trade-user/index.go +++ b/src/apis/data/trade-user/index.go @@ -7,6 +7,7 @@ import ( func AddTradeUserAPIs(router fiber.Router) { adminGroup := router.Use(middleware.AllowOnlyBigAdmins.Validate) + adminGroup.Get("/getInActiveTradeUsers", apiGetInActiveTradeUsers) adminGroup.Get("/getTradeUser", apiGetTradeUserDetails) adminGroup.Patch("/updateTradeUserDetails", apiUpdateTradeUserDetails) adminGroup.Patch("/updateTradeUserStatus", apiChangeTradeUserStatus) diff --git a/src/apis/order/user/index.go b/src/apis/order/user/index.go index 6356c47..89591eb 100644 --- a/src/apis/order/user/index.go +++ b/src/apis/order/user/index.go @@ -1,11 +1,8 @@ package user -import ( - "github.com/gofiber/fiber/v2" - "github.com/rpsoftech/bullion-server/src/middleware" -) +import "github.com/gofiber/fiber/v2" func AddUserOrderApis(router fiber.Router) { - router.Use(middleware.AllowAllAdminsAndTradeUsers.Validate) - // router.Put("/placeMarketOrder",) + + // router.Use(middleware.AllowAllAdminsAndTradeUsers.Validate) } diff --git a/src/interfaces/admin-user.entity_test.go b/src/interfaces/admin-user.entity_test.go new file mode 100644 index 0000000..5779616 --- /dev/null +++ b/src/interfaces/admin-user.entity_test.go @@ -0,0 +1,47 @@ +package interfaces + +import ( + "testing" +) + +func TestAdminUserEntity(t *testing.T) { + e := &AdminUserEntity{} + // // c.createNewId() + // Admin() + t.Run("Create New Admin Entity", func(t *testing.T) { + if e.BaseEntity != nil { + t.Fatalf("BaseEntity is not nil") + } + if e.UserRolesInterface != nil { + t.Fatalf("UserRolesInterface is not nil") + } + e.CreateNewEntity("admin", "password", "nickName", "bullionId") + if e.BaseEntity == nil { + t.Fatalf("BaseEntity is nil") + } + if e.UserName != "admin" { + t.Fatalf("UserName is not admin") + } + if e.Password != "password" { + t.Fatalf("Password is not password") + } + if e.NickName != "nickName" { + t.Fatalf("NickName is not nickName") + } + if e.BullionId != "bullionId" { + t.Fatalf("BullionId is not bullionId") + } + if e.UserRolesInterface == nil { + t.Fatalf("UserRolesInterface is nil") + } + if e.UserRolesInterface.Role != ROLE_ADMIN { + t.Fatalf("UserRolesInterface Role is not ROLE_ADMIN") + } + testBaseEntityCreateNewId(t, e.BaseEntity) + t.Run("password match", func(t *testing.T) { + if !e.MatchPassword("password") { + t.Fatalf("Password does not match") + } + }) + }) +} diff --git a/src/interfaces/base-entity.go b/src/interfaces/base-entity.go index 37da61e..7989e85 100644 --- a/src/interfaces/base-entity.go +++ b/src/interfaces/base-entity.go @@ -46,7 +46,7 @@ func (b *BaseEntity) createNewId() *BaseEntity { id := uuid.New().String() b.ID = id b.CreatedAt = time.Now() - b.ModifiedAt = time.Now() + b.ModifiedAt = b.CreatedAt return b } diff --git a/src/interfaces/base-entity_test.go b/src/interfaces/base-entity_test.go new file mode 100644 index 0000000..d6675f6 --- /dev/null +++ b/src/interfaces/base-entity_test.go @@ -0,0 +1,71 @@ +package interfaces + +import ( + "testing" + "time" +) + +func testBaseEntityCreateNewId(t *testing.T, c *BaseEntity) { + + if c.ID == "" { + t.Fatalf("Id is empty") + } + + if c.CreatedAt.IsZero() { + t.Fatalf("CreatedAt is empty") + } + if c.ModifiedAt.IsZero() { + t.Fatalf("ModifiedAt is empty") + } + if !c.CreatedAtExported.IsZero() { + t.Fatalf("CreatedAtExported is not empty %d", c.CreatedAtExported.Unix()) + } + if !c.ModifiedAtExported.IsZero() { + t.Fatalf("ModifiedAtExported is not empty") + } +} + +func TestBaseEntity(t *testing.T) { + c := &BaseEntity{} + c.createNewId() + t.Run("Create New ID", func(t *testing.T) { + id := c.ID + c.createNewId() + if c.ID == id { + t.Fatalf("Id Should Be Different") + } + testBaseEntityCreateNewId(t, c) + }) + t.Run("AddTimeStamps", func(t *testing.T) { + now := time.Now() + c.CreatedAt = now + c.ModifiedAt = now + c.AddTimeStamps() + if c.CreatedAtExported != now { + t.Fatalf("CreatedAt and CreatedAtExported Should be same") + } + if c.ModifiedAtExported != now { + t.Fatalf("ModifiedAt and ModifiedAtExported Should be same") + } + }) + t.Run("RestoreTimeStamp", func(t *testing.T) { + now := time.Now() + c.CreatedAtExported = now + c.ModifiedAtExported = now + c.RestoreTimeStamp() + if c.CreatedAt != now { + t.Fatalf("CreatedAt and CreatedAtExported Should be same") + } + if c.ModifiedAt != now { + t.Fatalf("ModifiedAt and ModifiedAtExported Should be same") + } + }) + t.Run("Updated", func(t *testing.T) { + now := time.Now() + c.ModifiedAt = now + c.Updated() + if c.ModifiedAt.Before(now) { + t.Fatalf("ModifiedAt Should be greater than now") + } + }) +} diff --git a/src/mongodb/repos/bank-rate-calc.repo.go b/src/mongodb/repos/bank-rate-calc.repo.go index fd53733..c2b5b2f 100644 --- a/src/mongodb/repos/bank-rate-calc.repo.go +++ b/src/mongodb/repos/bank-rate-calc.repo.go @@ -41,6 +41,7 @@ func init() { } func (repo *BankRateCalcRepoStruct) cacheDataToRedis(entity *interfaces.BankRateCalcEntity) { + entity.AddTimeStamps() if entityStringBytes, err := json.Marshal(entity); err == nil { entityString := string(entityStringBytes) repo.redis.SetStringDataWithExpiry(fmt.Sprintf("%s/%s", bankRateRedisCollection, entity.BullionId), entityString, time.Duration(24)*time.Hour) @@ -73,6 +74,7 @@ func (repo *BankRateCalcRepoStruct) FindOneByBullionId(id string) (*interfaces.B result := new(interfaces.BankRateCalcEntity) if redisData := repo.redis.GetStringData(fmt.Sprintf("%s/%s", bankRateRedisCollection, id)); redisData != "" { if err := json.Unmarshal([]byte(redisData), result); err == nil { + result.RestoreTimeStamp() return result, err } } diff --git a/src/mongodb/repos/trade-user.repo.go b/src/mongodb/repos/trade-user.repo.go index 82f4b81..f8bd3b9 100644 --- a/src/mongodb/repos/trade-user.repo.go +++ b/src/mongodb/repos/trade-user.repo.go @@ -133,10 +133,25 @@ func (repo *TradeUserRepoStruct) findByFilter(filter *mongoDbFilter) (*[]interfa return &result, err } +func (repo *TradeUserRepoStruct) FindAllInActiveUser(bullionId string) (*[]interfaces.TradeUserEntity, error) { + return repo.findByFilter(&mongoDbFilter{ + conditions: &bson.D{ + { + Key: "$and", + Value: bson.A{ + bson.D{{Key: "bullionId", Value: bullionId}}, + bson.D{{Key: "isActive", Value: false}}, + }, + }, + }, + }) +} + func (repo *TradeUserRepoStruct) FindOne(id string) (*interfaces.TradeUserEntity, error) { result := new(interfaces.TradeUserEntity) if redisData := repo.redis.GetStringData(fmt.Sprintf("tradeUser/%s", id)); redisData != "" { if err := json.Unmarshal([]byte(redisData), result); err == nil { + result.RestoreTimeStamp() return result, err } } @@ -167,6 +182,7 @@ func (repo *TradeUserRepoStruct) FindOne(id string) (*interfaces.TradeUserEntity } func (repo *TradeUserRepoStruct) cacheDataToRedis(entity *interfaces.TradeUserEntity) { + entity.AddTimeStamps() if entityStringBytes, err := json.Marshal(entity); err == nil { entityString := string(entityStringBytes) repo.redis.SetStringDataWithExpiry(fmt.Sprintf("tradeUser/%s", entity.ID), entityString, time.Duration(24)*time.Hour) diff --git a/src/services/trade-user.service.go b/src/services/trade-user.service.go index 316a1dd..180838d 100644 --- a/src/services/trade-user.service.go +++ b/src/services/trade-user.service.go @@ -300,7 +300,9 @@ func (service *tradeUserServiceStruct) UpdateTradeUser(entity *interfaces.TradeU user.TradeUserBase = entity.TradeUserBase user.TradeUserAdvanced.IsActive = entity.TradeUserAdvanced.IsActive user.TradeUserMargins = entity.TradeUserMargins - if _, err := service.tradeUserRepo.Save(entity); err != nil { + // TODO: Password Entity + // user.Password = entity.Password + if _, err := service.tradeUserRepo.Save(user); err != nil { return err } service.eventBus.Publish(events.CreateTradeUserUpdated(entity.BullionId, user, adminId)) @@ -327,6 +329,9 @@ func (service *tradeUserServiceStruct) generateTokensForTradeUserWithPasswordMat return service.generateTokensForTradeUser(tradeUser) } +func (service *tradeUserServiceStruct) FindAndReturnAllInActiveTradeUsers(bullionId string) (*[]interfaces.TradeUserEntity, error) { + return service.tradeUserRepo.FindAllInActiveUser(bullionId) +} func (service *tradeUserServiceStruct) FindOneUserById(id string) (*interfaces.TradeUserEntity, error) { return service.tradeUserRepo.FindOne(id) } From 7c5c353a99cb96348c45c42bc7ae8e51f7ab14d6 Mon Sep 17 00:00:00 2001 From: Keyur Shah Date: Sat, 22 Feb 2025 23:03:56 +0530 Subject: [PATCH 23/23] SOMW WIP --- src/interfaces/base-entity.go | 3 +- src/interfaces/trade-user-group.entity.go | 2 + src/services/order-general.service.go | 74 +++++++++++++++++------ 3 files changed, 57 insertions(+), 22 deletions(-) diff --git a/src/interfaces/base-entity.go b/src/interfaces/base-entity.go index 7989e85..241f76f 100644 --- a/src/interfaces/base-entity.go +++ b/src/interfaces/base-entity.go @@ -43,8 +43,7 @@ func (b *BaseEntity) RestoreTimeStamp() *BaseEntity { return b } func (b *BaseEntity) createNewId() *BaseEntity { - id := uuid.New().String() - b.ID = id + b.ID = uuid.New().String() b.CreatedAt = time.Now() b.ModifiedAt = b.CreatedAt return b diff --git a/src/interfaces/trade-user-group.entity.go b/src/interfaces/trade-user-group.entity.go index d685a85..2069e65 100644 --- a/src/interfaces/trade-user-group.entity.go +++ b/src/interfaces/trade-user-group.entity.go @@ -11,6 +11,8 @@ type ( TradeUserGroupEntity struct { *BaseEntity `bson:"inline"` *TradeUserGroupBase `bson:"inline"` + Gold *GroupPremiumBase `bson:"gold" json:"gold" validate:"required"` + Silver *GroupPremiumBase `bson:"silver" json:"silver" validate:"required"` } TradeUserGroupMapEntity struct { diff --git a/src/services/order-general.service.go b/src/services/order-general.service.go index d5535d3..9307a27 100644 --- a/src/services/order-general.service.go +++ b/src/services/order-general.service.go @@ -179,7 +179,46 @@ func (service *orderGeneralService) PlaceOrder(orderType interfaces.OrderStatus, return nil, err } - // TODO Validate Pricing + // Validate Pricing + finalRate, err := service.calCulateAndReturnFinalRateForOrder(product, group, groupMap, buySell) + println("Final Rate", finalRate) + order := &interfaces.OrderEntity{ + BaseEntity: &interfaces.BaseEntity{}, + OrderBase: &interfaces.OrderBase{ + BullionId: group.BullionId, + OrderType: interfaces.OrderType(orderType), + BuySell: buySell, + ProductName: product.Name, + }, + LimitWatcherRequired: &interfaces.LimitWatcherRequired{ + ProductId: product.ID, + GroupId: group.ID, + ProductGroupMapId: groupMap.ID, + Volume: float64(weight), + Weight: weight, + }, + // DeliveryData: , + // Identity: , + // AfterSuccessOrder: , + } + println("Order", order) + // order.BaseEntity. + // TODO Check Hedging And Place Order + + // TODO Update Order Entity in DB + + _, err = user.UpdateMarginAfterOrder(weight, product.SourceSymbol) + if err != nil { + return nil, err + } + + // TODO Check Hedging And Place Order + return nil, nil + // return service.orderRepo.PlaceOrder(orderType, user, group, groupMap, price, placedBy) + // return service.orderRepo.PlaceOrder(orderType, user, group, groupMap, price, placedBy) +} + +func (service *orderGeneralService) calCulateAndReturnFinalRateForOrder(product *interfaces.ProductEntity, group *interfaces.TradeUserGroupEntity, groupMap *interfaces.TradeUserGroupMapEntity, buySell interfaces.BuySell) (float64, error) { priceReadKey := interfaces.PRICE_ASK if product.CalculatedOnPriceOf == interfaces.CALCULATE_ON_BID { priceReadKey = interfaces.PRICE_BID @@ -193,18 +232,21 @@ func (service *orderGeneralService) PlaceOrder(orderType interfaces.OrderStatus, productSymbol := product.SourceSymbol.ToSymbolEnum() + groupPremium := group.Gold + if product.CalcPriceMethod == interfaces.CALCULATION_PRICE_TYPE_BANK { if product.SourceSymbol == interfaces.SOURCE_SYMBOL_GOLD { productSymbol = interfaces.SYMBOL_GOLD_SPOT } else { productSymbol = interfaces.SYMBOL_SILVER_SPOT + groupPremium = group.Silver } } rate := service.liveRateService.GetLiveRate(productSymbol, priceReadKey) if rate == 0 { - return nil, &interfaces.RequestError{ + return 0, &interfaces.RequestError{ StatusCode: 400, Code: interfaces.ERROR_LIVE_RATE_NOT_FOUND, Message: "Live Rate Not Found", @@ -215,7 +257,7 @@ func (service *orderGeneralService) PlaceOrder(orderType interfaces.OrderStatus, if product.CalcPriceMethod == interfaces.CALCULATION_PRICE_TYPE_BANK { bankRate, err := service.bankRateService.GetBankRateCalcByBullionId(group.BullionId) if err != nil { - return nil, err + return 0, err } inrRate := service.liveRateService.GetLiveRate(interfaces.SYMBOL_INR, priceReadKey) calcFunc := bankRate.GOLD_SPOT.CalculatePrice @@ -225,28 +267,20 @@ func (service *orderGeneralService) PlaceOrder(orderType interfaces.OrderStatus, rate = calcFunc(rate, inrRate) // rate = bankRate.Rate } - calcSnapshot := &product.CalcSnapshot.Sell - if buySell == interfaces.Buy { - calcSnapshot = &product.CalcSnapshot.Buy - } - finalRate := interfaces.Calculate(rate, calcSnapshot) - println("Final Rate", finalRate) - // order := &interfaces.OrderEntity{ + // Extra Premium For Group + extraPremium := groupMap.Sell + groupPremium.Sell - // TODO Check Hedging And Place Order - - // TODO Update Order Entity in DB + calcSnapshot := &product.CalcSnapshot.Sell - _, err = user.UpdateMarginAfterOrder(weight, product.SourceSymbol) - if err != nil { - return nil, err + if buySell == interfaces.Buy { + calcSnapshot = &product.CalcSnapshot.Buy + extraPremium = groupMap.Buy + groupPremium.Buy } - // TODO Check Hedging And Place Order - return nil, nil - // return service.orderRepo.PlaceOrder(orderType, user, group, groupMap, price, placedBy) - // return service.orderRepo.PlaceOrder(orderType, user, group, groupMap, price, placedBy) + finalRate := interfaces.Calculate(rate+extraPremium, calcSnapshot) + return finalRate, nil + // return service.orderRepo.GetOrderById(orderId) } // check user is valid