fix
All checks were successful
Deploy Dev / Build (pull_request) Successful in 39s
Deploy Dev / Push (pull_request) Successful in 24s
Deploy Dev / Deploy dev (pull_request) Successful in 8s
Deploy Prod / Build (pull_request) Successful in 38s
Deploy Prod / Push (pull_request) Successful in 25s
Deploy Prod / Deploy prod (pull_request) Successful in 8s
All checks were successful
Deploy Dev / Build (pull_request) Successful in 39s
Deploy Dev / Push (pull_request) Successful in 24s
Deploy Dev / Deploy dev (pull_request) Successful in 8s
Deploy Prod / Build (pull_request) Successful in 38s
Deploy Prod / Push (pull_request) Successful in 25s
Deploy Prod / Deploy prod (pull_request) Successful in 8s
This commit is contained in:
@@ -10,20 +10,18 @@ type FinishRequestBody struct {
|
||||
Id string `json:"id"`
|
||||
}
|
||||
|
||||
func Finish(w http.ResponseWriter, r *http.Request) {
|
||||
func Finish(r *http.Request) (interface{}, int) {
|
||||
d := json.NewDecoder(r.Body)
|
||||
body := FinishRequestBody{}
|
||||
err := d.Decode(&body)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
return nil, http.StatusBadRequest
|
||||
}
|
||||
|
||||
err = tasks.Finish(body.Id)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
return nil, http.StatusInternalServerError
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
return nil, http.StatusAccepted
|
||||
}
|
||||
|
||||
@@ -15,13 +15,12 @@ type PutRequestBody struct {
|
||||
Delay *int `json:"delay"`
|
||||
}
|
||||
|
||||
func Put(w http.ResponseWriter, r *http.Request) {
|
||||
func Put(r *http.Request) (interface{}, int) {
|
||||
d := json.NewDecoder(r.Body)
|
||||
body := PutRequestBody{}
|
||||
err := d.Decode(&body)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusBadRequest)
|
||||
return
|
||||
return nil, http.StatusBadRequest
|
||||
}
|
||||
|
||||
queue := r.Header.Get("queue")
|
||||
@@ -44,9 +43,8 @@ func Put(w http.ResponseWriter, r *http.Request) {
|
||||
|
||||
err = tasks.Add(task)
|
||||
if err != nil {
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
return nil, http.StatusInternalServerError
|
||||
}
|
||||
|
||||
w.WriteHeader(http.StatusAccepted)
|
||||
return nil, http.StatusAccepted
|
||||
}
|
||||
|
||||
@@ -1,7 +1,6 @@
|
||||
package routers
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"net/http"
|
||||
tasks "queues-go/app/storage/mongo/collections"
|
||||
)
|
||||
@@ -16,13 +15,11 @@ type TakeResponse struct {
|
||||
Task *TaskResponse `json:"task"`
|
||||
}
|
||||
|
||||
func Take(w http.ResponseWriter, r *http.Request) {
|
||||
func Take(r *http.Request) (interface{}, int) {
|
||||
queue := r.Header.Get("queue")
|
||||
task, err := tasks.Take(queue)
|
||||
if err != nil {
|
||||
println("Error taking")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
return nil, http.StatusInternalServerError
|
||||
}
|
||||
|
||||
var response TakeResponse
|
||||
@@ -36,12 +33,5 @@ func Take(w http.ResponseWriter, r *http.Request) {
|
||||
}
|
||||
}
|
||||
|
||||
data, err := json.Marshal(response)
|
||||
if err != nil {
|
||||
println("Error marshalling")
|
||||
w.WriteHeader(http.StatusInternalServerError)
|
||||
return
|
||||
}
|
||||
|
||||
w.Write(data)
|
||||
return response, http.StatusOK
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user