Skip to content

Commit e8fd1b3

Browse files
committed
feat: clean code and 201
Signed-off-by: Jad Chahed <[email protected]>
1 parent ef1aa34 commit e8fd1b3

File tree

3 files changed

+25
-7
lines changed

3 files changed

+25
-7
lines changed

go/admin/api.go

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,14 @@ func (a *Admin) handleGitHubCallback(c *gin.Context) {
165165

166166
randomKey := random.String(32)
167167
tokens[randomKey] = *token
168-
c.SetCookie("ghtoken", randomKey, int(time.Hour.Seconds()), "/", "localhost", true, true)
168+
169+
domain := "localhost"
170+
171+
if a.Mode == server.ProductionMode {
172+
domain = "benchmark.vitess.io"
173+
}
174+
175+
c.SetCookie("ghtoken", randomKey, int(time.Hour.Seconds()), "/", domain, true, true)
169176

170177
c.Redirect(http.StatusSeeOther, "/admin/dashboard")
171178
} else {
@@ -253,6 +260,10 @@ func (a *Admin) handleExecutionsAdd(c *gin.Context) {
253260

254261
serverAPIURL := "http://localhost:8080/api/executions/add"
255262

263+
if a.Mode == server.ProductionMode {
264+
serverAPIURL = "https://benchmark.vitess.io/api/executions/add"
265+
}
266+
256267
req, err := http.NewRequest("POST", serverAPIURL, bytes.NewBuffer(jsonData))
257268

258269
if err != nil {
@@ -275,11 +286,11 @@ func (a *Admin) handleExecutionsAdd(c *gin.Context) {
275286

276287
defer resp.Body.Close()
277288

278-
if resp.StatusCode != http.StatusOK {
289+
if resp.StatusCode != http.StatusCreated {
279290
slog.Error("Server API returned an error: ", resp.Status)
280291
c.JSON(resp.StatusCode, gin.H{"error": "Failed to process request on server API"})
281292
return
282293
}
283294

284-
c.JSON(http.StatusOK, gin.H{"message": "Execution(s) added successfully"})
295+
c.JSON(http.StatusCreated, gin.H{"message": "Execution(s) added successfully"})
285296
}

go/admin/templates/content.html

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,13 @@
130130
document.getElementById("response").classList.add("text-red-500");
131131
document.getElementById("response").innerHTML = errorMessage;
132132
});
133+
134+
// Display success on 201
135+
document.body.addEventListener("htmx:afterOnLoad", function(e) {
136+
if (e.detail.xhr.status == 201) {
137+
document.getElementById("response").classList.remove("text-red-500");
138+
document.getElementById("response").classList.add("text-green-500");
139+
document.getElementById("response").innerHTML = "Execution added successfully!";
140+
}
141+
});
133142
</script>

go/server/api.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -569,8 +569,6 @@ func (s *Server) addExecutions(c *gin.Context) {
569569
return
570570
}
571571

572-
slog.Info(decryptedToken)
573-
574572
if req.Source == "" || req.SHA == "" || len(req.Workloads) == 0 || req.NumberOfExecutions == "" {
575573
c.JSON(http.StatusBadRequest, &ErrorAPI{Error: "missing argument"})
576574
return
@@ -594,9 +592,9 @@ func (s *Server) addExecutions(c *gin.Context) {
594592
}
595593
}
596594

597-
// s.appendToQueue(newElements)
595+
s.appendToQueue(newElements)
598596

599-
c.JSON(http.StatusOK, "ok")
597+
c.JSON(http.StatusCreated, "")
600598
}
601599

602600
func IsUserAuthenticated(accessToken string) (bool, error) {

0 commit comments

Comments
 (0)