2018-04-29 16:35:04 -07:00
|
|
|
// Copyright 2018 Frédéric Guillot. All rights reserved.
|
|
|
|
// Use of this source code is governed by the Apache 2.0
|
|
|
|
// license that can be found in the LICENSE file.
|
|
|
|
|
2018-09-03 14:26:40 -07:00
|
|
|
package ui // import "miniflux.app/ui"
|
2018-04-29 16:35:04 -07:00
|
|
|
|
|
|
|
import (
|
2021-01-04 15:32:32 -08:00
|
|
|
json_parser "encoding/json"
|
2018-04-29 16:35:04 -07:00
|
|
|
"net/http"
|
|
|
|
|
2018-09-03 14:26:40 -07:00
|
|
|
"miniflux.app/http/request"
|
2018-08-24 21:51:50 -07:00
|
|
|
"miniflux.app/http/response/json"
|
2021-01-04 15:32:32 -08:00
|
|
|
"miniflux.app/model"
|
|
|
|
"miniflux.app/validator"
|
2018-04-29 16:35:04 -07:00
|
|
|
)
|
|
|
|
|
2018-11-11 11:28:29 -08:00
|
|
|
func (h *handler) updateEntriesStatus(w http.ResponseWriter, r *http.Request) {
|
2021-01-04 15:32:32 -08:00
|
|
|
var entriesStatusUpdateRequest model.EntriesStatusUpdateRequest
|
|
|
|
if err := json_parser.NewDecoder(r.Body).Decode(&entriesStatusUpdateRequest); err != nil {
|
2018-10-07 18:42:43 -07:00
|
|
|
json.BadRequest(w, r, err)
|
2018-04-29 16:35:04 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-01-04 15:32:32 -08:00
|
|
|
if err := validator.ValidateEntriesStatusUpdateRequest(&entriesStatusUpdateRequest); err != nil {
|
|
|
|
json.BadRequest(w, r, err)
|
2018-04-29 16:35:04 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-06-03 02:39:47 +02:00
|
|
|
count, err := h.store.SetEntriesStatusCount(request.UserID(r), entriesStatusUpdateRequest.EntryIDs, entriesStatusUpdateRequest.Status)
|
|
|
|
if err != nil {
|
2018-10-07 18:42:43 -07:00
|
|
|
json.ServerError(w, r, err)
|
2018-04-29 16:35:04 -07:00
|
|
|
return
|
|
|
|
}
|
|
|
|
|
2021-06-03 02:39:47 +02:00
|
|
|
json.OK(w, r, count)
|
2018-04-29 16:35:04 -07:00
|
|
|
}
|