1
0
Fork 0
mirror of https://github.com/miniflux/v2.git synced 2025-08-01 17:38:37 +00:00

Improve Request to be more idiomatic

This commit is contained in:
Frédéric Guillot 2017-11-21 18:14:45 -08:00
parent 4fc18647ca
commit 25cbd65777
20 changed files with 80 additions and 77 deletions

View file

@ -12,7 +12,7 @@ import (
// CreateCategory is the API handler to create a new category.
func (c *Controller) CreateCategory(ctx *core.Context, request *core.Request, response *core.Response) {
category, err := payload.DecodeCategoryPayload(request.GetBody())
category, err := payload.DecodeCategoryPayload(request.Body())
if err != nil {
response.Json().BadRequest(err)
return
@ -35,13 +35,13 @@ func (c *Controller) CreateCategory(ctx *core.Context, request *core.Request, re
// UpdateCategory is the API handler to update a category.
func (c *Controller) UpdateCategory(ctx *core.Context, request *core.Request, response *core.Response) {
categoryID, err := request.GetIntegerParam("categoryID")
categoryID, err := request.IntegerParam("categoryID")
if err != nil {
response.Json().BadRequest(err)
return
}
category, err := payload.DecodeCategoryPayload(request.GetBody())
category, err := payload.DecodeCategoryPayload(request.Body())
if err != nil {
response.Json().BadRequest(err)
return
@ -77,7 +77,7 @@ func (c *Controller) GetCategories(ctx *core.Context, request *core.Request, res
// RemoveCategory is the API handler to remove a category.
func (c *Controller) RemoveCategory(ctx *core.Context, request *core.Request, response *core.Response) {
userID := ctx.GetUserID()
categoryID, err := request.GetIntegerParam("categoryID")
categoryID, err := request.IntegerParam("categoryID")
if err != nil {
response.Json().BadRequest(err)
return

View file

@ -14,13 +14,13 @@ import (
// GetEntry is the API handler to get a single feed entry.
func (c *Controller) GetEntry(ctx *core.Context, request *core.Request, response *core.Response) {
userID := ctx.GetUserID()
feedID, err := request.GetIntegerParam("feedID")
feedID, err := request.IntegerParam("feedID")
if err != nil {
response.Json().BadRequest(err)
return
}
entryID, err := request.GetIntegerParam("entryID")
entryID, err := request.IntegerParam("entryID")
if err != nil {
response.Json().BadRequest(err)
return
@ -47,13 +47,13 @@ func (c *Controller) GetEntry(ctx *core.Context, request *core.Request, response
// GetFeedEntries is the API handler to get all feed entries.
func (c *Controller) GetFeedEntries(ctx *core.Context, request *core.Request, response *core.Response) {
userID := ctx.GetUserID()
feedID, err := request.GetIntegerParam("feedID")
feedID, err := request.IntegerParam("feedID")
if err != nil {
response.Json().BadRequest(err)
return
}
status := request.GetQueryStringParam("status", "")
status := request.QueryStringParam("status", "")
if status != "" {
if err := model.ValidateEntryStatus(status); err != nil {
response.Json().BadRequest(err)
@ -61,20 +61,20 @@ func (c *Controller) GetFeedEntries(ctx *core.Context, request *core.Request, re
}
}
order := request.GetQueryStringParam("order", "id")
order := request.QueryStringParam("order", "id")
if err := model.ValidateEntryOrder(order); err != nil {
response.Json().BadRequest(err)
return
}
direction := request.GetQueryStringParam("direction", "desc")
direction := request.QueryStringParam("direction", "desc")
if err := model.ValidateDirection(direction); err != nil {
response.Json().BadRequest(err)
return
}
limit := request.GetQueryIntegerParam("limit", 100)
offset := request.GetQueryIntegerParam("offset", 0)
limit := request.QueryIntegerParam("limit", 100)
offset := request.QueryIntegerParam("offset", 0)
builder := c.store.GetEntryQueryBuilder(userID, ctx.GetUserTimezone())
builder.WithFeedID(feedID)
@ -103,19 +103,19 @@ func (c *Controller) GetFeedEntries(ctx *core.Context, request *core.Request, re
func (c *Controller) SetEntryStatus(ctx *core.Context, request *core.Request, response *core.Response) {
userID := ctx.GetUserID()
feedID, err := request.GetIntegerParam("feedID")
feedID, err := request.IntegerParam("feedID")
if err != nil {
response.Json().BadRequest(err)
return
}
entryID, err := request.GetIntegerParam("entryID")
entryID, err := request.IntegerParam("entryID")
if err != nil {
response.Json().BadRequest(err)
return
}
status, err := payload.DecodeEntryStatusPayload(request.GetBody())
status, err := payload.DecodeEntryStatusPayload(request.Body())
if err != nil {
response.Json().BadRequest(errors.New("Invalid JSON payload"))
return

View file

@ -13,7 +13,7 @@ import (
// CreateFeed is the API handler to create a new feed.
func (c *Controller) CreateFeed(ctx *core.Context, request *core.Request, response *core.Response) {
userID := ctx.GetUserID()
feedURL, categoryID, err := payload.DecodeFeedCreationPayload(request.GetBody())
feedURL, categoryID, err := payload.DecodeFeedCreationPayload(request.Body())
if err != nil {
response.Json().BadRequest(err)
return
@ -31,7 +31,7 @@ func (c *Controller) CreateFeed(ctx *core.Context, request *core.Request, respon
// RefreshFeed is the API handler to refresh a feed.
func (c *Controller) RefreshFeed(ctx *core.Context, request *core.Request, response *core.Response) {
userID := ctx.GetUserID()
feedID, err := request.GetIntegerParam("feedID")
feedID, err := request.IntegerParam("feedID")
if err != nil {
response.Json().BadRequest(err)
return
@ -49,13 +49,13 @@ func (c *Controller) RefreshFeed(ctx *core.Context, request *core.Request, respo
// UpdateFeed is the API handler that is used to update a feed.
func (c *Controller) UpdateFeed(ctx *core.Context, request *core.Request, response *core.Response) {
userID := ctx.GetUserID()
feedID, err := request.GetIntegerParam("feedID")
feedID, err := request.IntegerParam("feedID")
if err != nil {
response.Json().BadRequest(err)
return
}
newFeed, err := payload.DecodeFeedModificationPayload(request.GetBody())
newFeed, err := payload.DecodeFeedModificationPayload(request.Body())
if err != nil {
response.Json().BadRequest(err)
return
@ -95,7 +95,7 @@ func (c *Controller) GetFeeds(ctx *core.Context, request *core.Request, response
// GetFeed is the API handler to get a feed.
func (c *Controller) GetFeed(ctx *core.Context, request *core.Request, response *core.Response) {
userID := ctx.GetUserID()
feedID, err := request.GetIntegerParam("feedID")
feedID, err := request.IntegerParam("feedID")
if err != nil {
response.Json().BadRequest(err)
return
@ -118,7 +118,7 @@ func (c *Controller) GetFeed(ctx *core.Context, request *core.Request, response
// RemoveFeed is the API handler to remove a feed.
func (c *Controller) RemoveFeed(ctx *core.Context, request *core.Request, response *core.Response) {
userID := ctx.GetUserID()
feedID, err := request.GetIntegerParam("feedID")
feedID, err := request.IntegerParam("feedID")
if err != nil {
response.Json().BadRequest(err)
return

View file

@ -14,7 +14,7 @@ import (
// GetSubscriptions is the API handler to find subscriptions.
func (c *Controller) GetSubscriptions(ctx *core.Context, request *core.Request, response *core.Response) {
websiteURL, err := payload.DecodeURLPayload(request.GetBody())
websiteURL, err := payload.DecodeURLPayload(request.Body())
if err != nil {
response.Json().BadRequest(err)
return

View file

@ -17,7 +17,7 @@ func (c *Controller) CreateUser(ctx *core.Context, request *core.Request, respon
return
}
user, err := payload.DecodeUserPayload(request.GetBody())
user, err := payload.DecodeUserPayload(request.Body())
if err != nil {
response.Json().BadRequest(err)
return
@ -50,13 +50,13 @@ func (c *Controller) UpdateUser(ctx *core.Context, request *core.Request, respon
return
}
userID, err := request.GetIntegerParam("userID")
userID, err := request.IntegerParam("userID")
if err != nil {
response.Json().BadRequest(err)
return
}
user, err := payload.DecodeUserPayload(request.GetBody())
user, err := payload.DecodeUserPayload(request.Body())
if err != nil {
response.Json().BadRequest(err)
return
@ -110,7 +110,7 @@ func (c *Controller) GetUser(ctx *core.Context, request *core.Request, response
return
}
userID, err := request.GetIntegerParam("userID")
userID, err := request.IntegerParam("userID")
if err != nil {
response.Json().BadRequest(err)
return
@ -137,7 +137,7 @@ func (c *Controller) RemoveUser(ctx *core.Context, request *core.Request, respon
return
}
userID, err := request.GetIntegerParam("userID")
userID, err := request.IntegerParam("userID")
if err != nil {
response.Json().BadRequest(err)
return