github.com/mysteriumnetwork/node@v0.0.0-20240516044423-365054f76801/tequilapi/contract/entertainment.go (about) 1 /* 2 * Copyright (C) 2021 The "MysteriumNetwork/node" Authors. 3 * 4 * This program is free software: you can redistribute it and/or modify 5 * it under the terms of the GNU General Public License as published by 6 * the Free Software Foundation, either version 3 of the License, or 7 * (at your option) any later version. 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program. If not, see <http://www.gnu.org/licenses/>. 16 */ 17 18 package contract 19 20 import ( 21 "net/http" 22 "strconv" 23 24 "github.com/mysteriumnetwork/go-rest/apierror" 25 ) 26 27 // EntertainmentEstimateRequest request to estimate entertainment amounts. 28 type EntertainmentEstimateRequest struct { 29 Amount float64 30 } 31 32 // Bind fills and validates EntertainmentEstimateRequest from API request. 33 func (req *EntertainmentEstimateRequest) Bind(request *http.Request) *apierror.APIError { 34 v := apierror.NewValidator() 35 36 amt := request.URL.Query().Get("amount") 37 if amt == "" { 38 v.Required("amount") 39 return v.Err() 40 } 41 42 amtf, err := strconv.ParseFloat(amt, 64) 43 if err != nil { 44 v.Invalid("amount", "Failed to parse amount (not a valid decimal)") 45 return v.Err() 46 } 47 48 req.Amount = amtf 49 return nil 50 } 51 52 // EntertainmentEstimateResponse represents estimated entertainment. 53 // swagger:model EntertainmentEstimateResponse 54 type EntertainmentEstimateResponse struct { 55 VideoMinutes uint64 `json:"video_minutes"` 56 MusicMinutes uint64 `json:"music_minutes"` 57 BrowsingMinutes uint64 `json:"browsing_minutes"` 58 TrafficMB uint64 `json:"traffic_mb"` 59 PriceGiB float64 `json:"price_gib"` 60 PriceMin float64 `json:"price_min"` 61 }