Skip to content

Commit f2b464f

Browse files
committed
Update v1 elasticsearch when ranking mapset
1 parent 9814048 commit f2b464f

File tree

4 files changed

+42
-0
lines changed

4 files changed

+42
-0
lines changed

config.example.json

+4
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,10 @@
1010
"127.0.0.1"
1111
]
1212
},
13+
"api_v1": {
14+
"url": "http://localhost:8082",
15+
"secret_key": ""
16+
},
1317
"steam": {
1418
"app_id": 980610,
1519
"publisher_key": "",

config/config.go

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,11 @@ type Config struct {
2121
RateLimitIpWhitelist []string `json:"rate_limit_ip_whitelist"`
2222
} `json:"server"`
2323

24+
ApiV1 struct {
25+
Url string `json:"url"`
26+
SecretKey string `json:"secret_key"`
27+
} `json:"api_v1"`
28+
2429
Steam struct {
2530
AppId int `json:"app_id"`
2631
PublisherKey string `json:"publisher_key"`

handlers/ranking_actions.go

+6
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,10 @@ import (
44
"github.com/Quaver/api2/config"
55
"github.com/Quaver/api2/db"
66
"github.com/Quaver/api2/enums"
7+
v1 "github.com/Quaver/api2/v1"
78
"github.com/Quaver/api2/webhooks"
89
"github.com/gin-gonic/gin"
10+
"github.com/sirupsen/logrus"
911
"gorm.io/gorm"
1012
"net/http"
1113
"strconv"
@@ -155,6 +157,10 @@ func VoteForRankingQueueMapset(c *gin.Context) *APIError {
155157
return APIErrorServerError("Error inserting ranked mapset notification", err)
156158
}
157159

160+
if err := v1.UpdateElasticSearchMapset(data.QueueMapset.MapsetId); err != nil {
161+
logrus.Warn("Error updating v1 elastic search for mapset: ", data.QueueMapset.MapsetId, err)
162+
}
163+
158164
_ = webhooks.SendRankedWebhook(data.QueueMapset.Mapset, existingVotes)
159165
}
160166

v1/elastic.go

+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
package v1
2+
3+
import (
4+
"fmt"
5+
"github.com/Quaver/api2/config"
6+
"github.com/go-resty/resty/v2"
7+
)
8+
9+
// UpdateElasticSearchMapset Makes an API call to v1 to update elastic search for a given mapset
10+
func UpdateElasticSearchMapset(id int) error {
11+
resp, err := resty.New().R().
12+
SetHeader("Accept", "application/json").
13+
SetBody(map[string]interface{}{
14+
"key": config.Instance.ApiV1.SecretKey,
15+
"id": id,
16+
}).Post(fmt.Sprintf("%v/v1/mapsets/elastic", config.Instance.ApiV1.Url))
17+
18+
if err != nil {
19+
return err
20+
}
21+
22+
if resp.IsError() {
23+
return fmt.Errorf("request to update elastic mapset (v1) failed: %v", resp.Error())
24+
}
25+
26+
return nil
27+
}

0 commit comments

Comments
 (0)