Fakultas Ilmu Komputer UI

Commit 91f97679 authored by Qadzif Kamil Zahari's avatar Qadzif Kamil Zahari
Browse files

fix: fix double create because options request

parent 437ca99e
......@@ -101,16 +101,18 @@ func getTaskWithStatus(status string, returnList []Task, taskList []Task) []Task
func createNewTask(w http.ResponseWriter, r *http.Request) {
setupCORS(&w, r)
reqBody, _ := ioutil.ReadAll(r.Body)
var task Task
err := json.Unmarshal(reqBody, &task)
if err != nil {
fmt.Println(err)
if r.Method == "POST" {
reqBody, _ := ioutil.ReadAll(r.Body)
var task Task
err := json.Unmarshal(reqBody, &task)
if err != nil {
fmt.Println(err)
}
task.Id = FindTaskMaxId(Tasklist) + 1
task.Status = "waiting"
Tasklist = append(Tasklist, task)
json.NewEncoder(w).Encode(Tasklist)
}
task.Id = FindTaskMaxId(Tasklist) + 1
task.Status = "waiting"
Tasklist = append(Tasklist, task)
json.NewEncoder(w).Encode(Tasklist)
}
func changeTaskStatus(w http.ResponseWriter, r *http.Request) {
......@@ -143,16 +145,18 @@ func deleteTask(w http.ResponseWriter, r *http.Request) {
func createNewCheck(w http.ResponseWriter, r *http.Request) {
setupCORS(&w, r)
reqBody, _ := ioutil.ReadAll(r.Body)
var check Checklist
err := json.Unmarshal(reqBody, &check)
if err != nil {
fmt.Println(err)
if r.Method == "POST" {
reqBody, _ := ioutil.ReadAll(r.Body)
var check Checklist
err := json.Unmarshal(reqBody, &check)
if err != nil {
fmt.Println(err)
}
check.Id = FindCheckMaxId(Checks) + 1
check.Status = false
Checks = append(Checks, check)
json.NewEncoder(w).Encode(Checks)
}
check.Id = FindCheckMaxId(Checks) + 1
check.Status = false
Checks = append(Checks, check)
json.NewEncoder(w).Encode(Checks)
}
func changeCheckStatus(w http.ResponseWriter, r *http.Request) {
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment