@@ -11,6 +11,7 @@ import (
1111 "github.com/gobitfly/beaconchain/pkg/api/enums"
1212 "github.com/gobitfly/beaconchain/pkg/api/types"
1313 "github.com/gorilla/mux"
14+ "github.com/shopspring/decimal"
1415)
1516
1617// All handler function names must include the HTTP method and the path they handle
@@ -2098,7 +2099,7 @@ func (h *HandlerService) PublicGetUserNotificationClients(w http.ResponseWriter,
20982099// @Param cursor query string false "Return data for the given cursor value. Pass the `paging.next_cursor`` value of the previous response to navigate to forward, or pass the `paging.prev_cursor`` value of the previous response to navigate to backward."
20992100// @Param limit query integer false "The maximum number of results that may be returned."
21002101// @Param sort query string false "The field you want to sort by. Append with `:desc` for descending order." Enums(timestamp, event_type, node_address)
2101- // @Param search query string false "Search for TODO "
2102+ // @Param search query string false "Search for Node Address "
21022103// @Success 200 {object} types.InternalGetUserNotificationRocketPoolResponse
21032104// @Failure 400 {object} types.ApiErrorResponse
21042105// @Router /users/me/notifications/rocket-pool [get]
@@ -2137,7 +2138,6 @@ func (h *HandlerService) PublicGetUserNotificationRocketPool(w http.ResponseWrit
21372138// @Param cursor query string false "Return data for the given cursor value. Pass the `paging.next_cursor`` value of the previous response to navigate to forward, or pass the `paging.prev_cursor`` value of the previous response to navigate to backward."
21382139// @Param limit query integer false "The maximum number of results that may be returned."
21392140// @Param sort query string false "The field you want to sort by. Append with `:desc` for descending order." Enums(timestamp, event_type)
2140- // @Param search query string false "Search for TODO"
21412141// @Success 200 {object} types.InternalGetUserNotificationNetworksResponse
21422142// @Failure 400 {object} types.ApiErrorResponse
21432143// @Router /users/me/notifications/networks [get]
@@ -2155,7 +2155,7 @@ func (h *HandlerService) PublicGetUserNotificationNetworks(w http.ResponseWriter
21552155 handleErr (w , r , v )
21562156 return
21572157 }
2158- data , paging , err := h .dai .GetNetworkNotifications (r .Context (), userId , pagingParams .cursor , * sort , pagingParams .search , pagingParams . limit )
2158+ data , paging , err := h .dai .GetNetworkNotifications (r .Context (), userId , pagingParams .cursor , * sort , pagingParams .limit )
21592159 if err != nil {
21602160 handleErr (w , r , err )
21612161 return
@@ -2218,8 +2218,6 @@ func (h *HandlerService) PublicPutUserNotificationSettingsGeneral(w http.Respons
22182218 checkMinMax (& v , req .MachineStorageUsageThreshold , 0 , 1 , "machine_storage_usage_threshold" )
22192219 checkMinMax (& v , req .MachineCpuUsageThreshold , 0 , 1 , "machine_cpu_usage_threshold" )
22202220 checkMinMax (& v , req .MachineMemoryUsageThreshold , 0 , 1 , "machine_memory_usage_threshold" )
2221- checkMinMax (& v , req .RocketPoolMaxCollateralThreshold , 0 , 1 , "rocket_pool_max_collateral_threshold" )
2222- checkMinMax (& v , req .RocketPoolMinCollateralThreshold , 0 , 1 , "rocket_pool_min_collateral_threshold" )
22232221 if v .hasErrors () {
22242222 handleErr (w , r , v )
22252223 return
@@ -2243,7 +2241,7 @@ func (h *HandlerService) PublicPutUserNotificationSettingsGeneral(w http.Respons
22432241// @Accept json
22442242// @Produce json
22452243// @Param network path string true "The networks name or chain ID."
2246- // @Param request body types.NotificationSettingsNetwork true "Description Todo"
2244+ // @Param request body handlers.PublicPutUserNotificationSettingsNetworks.request true "Description Todo"
22472245// @Success 200 {object} types.InternalPutUserNotificationSettingsNetworksResponse
22482246// @Failure 400 {object} types.ApiErrorResponse
22492247// @Router /users/me/notifications/settings/networks/{network} [put]
@@ -2254,27 +2252,50 @@ func (h *HandlerService) PublicPutUserNotificationSettingsNetworks(w http.Respon
22542252 handleErr (w , r , err )
22552253 return
22562254 }
2257- var req types.NotificationSettingsNetwork
2255+ type request struct {
2256+ IsGasAboveSubscribed bool `json:"is_gas_above_subscribed"`
2257+ GasAboveThreshold string `json:"gas_above_threshold"`
2258+ IsGasBelowSubscribed bool `json:"is_gas_below_subscribed"`
2259+ GasBelowThreshold string `json:"gas_below_threshold" `
2260+ IsParticipationRateSubscribed bool `json:"is_participation_rate_subscribed"`
2261+ ParticipationRateThreshold float64 `json:"participation_rate_threshold"`
2262+ IsNewRewardRoundSubscribed bool `json:"is_new_reward_round_subscribed"`
2263+ }
2264+ var req request
22582265 if err := v .checkBody (& req , r ); err != nil {
22592266 handleErr (w , r , err )
22602267 return
22612268 }
22622269 checkMinMax (& v , req .ParticipationRateThreshold , 0 , 1 , "participation_rate_threshold" )
2263-
22642270 chainId := v .checkNetworkParameter (mux .Vars (r )["network" ])
2271+
2272+ minWei := decimal .New (1000000 , 1 ) // 0.001 Gwei
2273+ maxWei := decimal .New (1000000000000 , 1 ) // 1000 Gwei
2274+ gasAboveThreshold := v .checkWeiMinMax (req .GasAboveThreshold , "gas_above_threshold" , minWei , maxWei )
2275+ gasBelowThreshold := v .checkWeiMinMax (req .GasBelowThreshold , "gas_below_threshold" , minWei , maxWei )
22652276 if v .hasErrors () {
22662277 handleErr (w , r , v )
22672278 return
22682279 }
2269- err = h .dai .UpdateNotificationSettingsNetworks (r .Context (), userId , chainId , req )
2280+ settings := types.NotificationSettingsNetwork {
2281+ IsGasAboveSubscribed : req .IsGasAboveSubscribed ,
2282+ GasAboveThreshold : gasAboveThreshold ,
2283+ IsGasBelowSubscribed : req .IsGasBelowSubscribed ,
2284+ GasBelowThreshold : gasBelowThreshold ,
2285+ IsParticipationRateSubscribed : req .IsParticipationRateSubscribed ,
2286+ ParticipationRateThreshold : req .ParticipationRateThreshold ,
2287+ IsNewRewardRoundSubscribed : req .IsNewRewardRoundSubscribed ,
2288+ }
2289+
2290+ err = h .dai .UpdateNotificationSettingsNetworks (r .Context (), userId , chainId , settings )
22702291 if err != nil {
22712292 handleErr (w , r , err )
22722293 return
22732294 }
22742295 response := types.InternalPutUserNotificationSettingsNetworksResponse {
22752296 Data : types.NotificationNetwork {
22762297 ChainId : chainId ,
2277- Settings : req ,
2298+ Settings : settings ,
22782299 },
22792300 }
22802301 returnOk (w , r , response )
@@ -2469,6 +2490,9 @@ func (h *HandlerService) PublicPutUserNotificationSettingsValidatorDashboard(w h
24692490 vars := mux .Vars (r )
24702491 dashboardId := v .checkPrimaryDashboardId (vars ["dashboard_id" ])
24712492 groupId := v .checkExistingGroupId (vars ["group_id" ])
2493+
2494+ checkMinMax (& v , req .MaxCollateralThreshold , 0 , 1 , "max_collateral_threshold" )
2495+ checkMinMax (& v , req .MinCollateralThreshold , 0 , 1 , "min_collateral_threshold" )
24722496 if v .hasErrors () {
24732497 handleErr (w , r , v )
24742498 return
0 commit comments