示例#1
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)
}
示例#2
0
func GetPhotosByUserId(w http.ResponseWriter, r *http.Request) {
	vars := mux.Vars(r)
	userId, _ := strconv.Atoi(vars["userId"])
	photos := repository.GetPhotosByUserId(userId)
	json.NewEncoder(w).Encode(photos)
}