Beispiel #1
0
func UpdateUser(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	userId, _ := strconv.Atoi(vars["userId"])
	user := repository.GetUserById(userId)

	// oldPassword := r.FormValue("oldPassword")
	// newPassword := r.FormValue("newPassword")

	// if oldPassword != "" && newPassword != "" {
	// 	result := updatePassword(&user, oldPassword, newPassword)

	// 	if result {
	// 		w.Write([]byte(`{"result":true}`))
	// 	} else {
	// 		w.Write([]byte(`{"result":false}`))
	// 	}

	// 	return
	// }

	// User is exist
	displayName := r.FormValue("displayName")
	email := r.FormValue("email")
	if displayName != "" {
		user.DisplayName = displayName
	}
	user.Email.Scan(email)

	repository.UpdateUser(&user)
	json.NewEncoder(w).Encode(user)
}
Beispiel #2
0
func GetUserById(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	userId, _ := strconv.Atoi(vars["userId"])

	// TODO validate userId is number
	user := repository.GetUserById(userId)

	json.NewEncoder(w).Encode(user)
}
Beispiel #3
0
func GetPhotosByUserId(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	userId, _ := strconv.Atoi(vars["userId"])

	user := repository.GetUserById(userId)
	if user.Id == 0 {
		w.Write([]byte(`{"Error":"Khong co user"}`))
		return
	}

	photos := repository.GetPhotosByUserId(userId)
	json.NewEncoder(w).Encode(photos)
}