Exemple #1
0
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)
}
Exemple #2
0
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))
		}
	}
}