Esempio n. 1
0
File: http.go Progetto: jackc/tpr
func MarkItemReadHandler(w http.ResponseWriter, req *http.Request, env *environment) {
	itemID, err := strconv.ParseInt(req.FormValue("id"), 10, 32)
	if err != nil {
		// If not an integer it clearly can't be found
		http.NotFound(w, req)
		return
	}

	err = data.MarkItemRead(env.pool, env.user.ID.Value, int32(itemID))
	if err == data.ErrNotFound {
		http.NotFound(w, req)
		return
	}
	if err != nil {
		http.Error(w, "Internal server error", http.StatusInternalServerError)
	}
}
Esempio n. 2
0
File: http.go Progetto: jackc/tpr
func MarkMultipleItemsReadHandler(w http.ResponseWriter, req *http.Request, env *environment) {
	var request struct {
		ItemIDs []int32 `json:"itemIDs"`
	}

	decoder := json.NewDecoder(req.Body)
	if err := decoder.Decode(&request); err != nil {
		w.WriteHeader(422)
		fmt.Fprintf(w, "Error decoding request: %v", err)
		return
	}

	for _, itemID := range request.ItemIDs {
		err := data.MarkItemRead(env.pool, env.user.ID.Value, itemID)
		if err != nil && err != data.ErrNotFound {
			http.Error(w, "Internal server error", http.StatusInternalServerError)
		}
	}
}