func UserUpdateAddressHandler(w http.ResponseWriter, r *http.Request) { addressController := controller.Address{} //verify user jwtToken := auth.JwtToken{} userToken, err := jwtToken.ParseToken(r) if err != nil { http.Error(w, "Invalid user", 400) } else { userId := userToken.Claims["userId"].(float64) addressController.UserId = int64(userId) _, err := addressController.UpdateAddress(r) if err != nil { http.Error(w, "Invalid user", 400) } } fmt.Fprint(w, true) }
func UserGetAddressHandler(w http.ResponseWriter, r *http.Request) { addressController := controller.Address{} //verify user jwtToken := auth.JwtToken{} userToken, err := jwtToken.ParseToken(r) if err != nil { http.Error(w, "Invalid user", 400) } else { userId := userToken.Claims["userId"].(float64) addressController.UserId = int64(userId) address, err := addressController.GetAddress(r) if err != nil { http.Error(w, "Invalid user", 400) } else { jsonRes, _ := json.Marshal(address) fmt.Fprint(w, string(jsonRes)) } } }