mirror of
https://github.com/miniflux/v2.git
synced 2025-06-27 16:36:00 +00:00
Improve Context to be more idiomatic
This commit is contained in:
parent
02ff7b4bcf
commit
1bc43ec2bc
17 changed files with 107 additions and 106 deletions
|
@ -18,7 +18,7 @@ func (c *Controller) CreateCategory(ctx *core.Context, request *core.Request, re
|
|||
return
|
||||
}
|
||||
|
||||
category.UserID = ctx.GetUserID()
|
||||
category.UserID = ctx.UserID()
|
||||
if err := category.ValidateCategoryCreation(); err != nil {
|
||||
response.JSON().ServerError(err)
|
||||
return
|
||||
|
@ -47,7 +47,7 @@ func (c *Controller) UpdateCategory(ctx *core.Context, request *core.Request, re
|
|||
return
|
||||
}
|
||||
|
||||
category.UserID = ctx.GetUserID()
|
||||
category.UserID = ctx.UserID()
|
||||
category.ID = categoryID
|
||||
if err := category.ValidateCategoryModification(); err != nil {
|
||||
response.JSON().BadRequest(err)
|
||||
|
@ -65,7 +65,7 @@ func (c *Controller) UpdateCategory(ctx *core.Context, request *core.Request, re
|
|||
|
||||
// GetCategories is the API handler to get a list of categories for a given user.
|
||||
func (c *Controller) GetCategories(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
categories, err := c.store.GetCategories(ctx.GetUserID())
|
||||
categories, err := c.store.GetCategories(ctx.UserID())
|
||||
if err != nil {
|
||||
response.JSON().ServerError(errors.New("Unable to fetch categories"))
|
||||
return
|
||||
|
@ -76,7 +76,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()
|
||||
userID := ctx.UserID()
|
||||
categoryID, err := request.IntegerParam("categoryID")
|
||||
if err != nil {
|
||||
response.JSON().BadRequest(err)
|
||||
|
|
|
@ -13,7 +13,7 @@ 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()
|
||||
userID := ctx.UserID()
|
||||
feedID, err := request.IntegerParam("feedID")
|
||||
if err != nil {
|
||||
response.JSON().BadRequest(err)
|
||||
|
@ -26,7 +26,7 @@ func (c *Controller) GetEntry(ctx *core.Context, request *core.Request, response
|
|||
return
|
||||
}
|
||||
|
||||
builder := c.store.GetEntryQueryBuilder(userID, ctx.GetUserTimezone())
|
||||
builder := c.store.GetEntryQueryBuilder(userID, ctx.UserTimezone())
|
||||
builder.WithFeedID(feedID)
|
||||
builder.WithEntryID(entryID)
|
||||
|
||||
|
@ -46,7 +46,7 @@ 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()
|
||||
userID := ctx.UserID()
|
||||
feedID, err := request.IntegerParam("feedID")
|
||||
if err != nil {
|
||||
response.JSON().BadRequest(err)
|
||||
|
@ -76,7 +76,7 @@ func (c *Controller) GetFeedEntries(ctx *core.Context, request *core.Request, re
|
|||
limit := request.QueryIntegerParam("limit", 100)
|
||||
offset := request.QueryIntegerParam("offset", 0)
|
||||
|
||||
builder := c.store.GetEntryQueryBuilder(userID, ctx.GetUserTimezone())
|
||||
builder := c.store.GetEntryQueryBuilder(userID, ctx.UserTimezone())
|
||||
builder.WithFeedID(feedID)
|
||||
builder.WithStatus(status)
|
||||
builder.WithOrder(model.DefaultSortingOrder)
|
||||
|
@ -101,7 +101,7 @@ func (c *Controller) GetFeedEntries(ctx *core.Context, request *core.Request, re
|
|||
|
||||
// SetEntryStatus is the API handler to change the status of an entry.
|
||||
func (c *Controller) SetEntryStatus(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
userID := ctx.GetUserID()
|
||||
userID := ctx.UserID()
|
||||
|
||||
feedID, err := request.IntegerParam("feedID")
|
||||
if err != nil {
|
||||
|
@ -126,7 +126,7 @@ func (c *Controller) SetEntryStatus(ctx *core.Context, request *core.Request, re
|
|||
return
|
||||
}
|
||||
|
||||
builder := c.store.GetEntryQueryBuilder(userID, ctx.GetUserTimezone())
|
||||
builder := c.store.GetEntryQueryBuilder(userID, ctx.UserTimezone())
|
||||
builder.WithFeedID(feedID)
|
||||
builder.WithEntryID(entryID)
|
||||
|
||||
|
|
|
@ -12,7 +12,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()
|
||||
userID := ctx.UserID()
|
||||
feedURL, categoryID, err := payload.DecodeFeedCreationPayload(request.Body())
|
||||
if err != nil {
|
||||
response.JSON().BadRequest(err)
|
||||
|
@ -30,7 +30,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()
|
||||
userID := ctx.UserID()
|
||||
feedID, err := request.IntegerParam("feedID")
|
||||
if err != nil {
|
||||
response.JSON().BadRequest(err)
|
||||
|
@ -48,7 +48,7 @@ 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()
|
||||
userID := ctx.UserID()
|
||||
feedID, err := request.IntegerParam("feedID")
|
||||
if err != nil {
|
||||
response.JSON().BadRequest(err)
|
||||
|
@ -83,7 +83,7 @@ func (c *Controller) UpdateFeed(ctx *core.Context, request *core.Request, respon
|
|||
|
||||
// GetFeeds is the API handler that get all feeds that belongs to the given user.
|
||||
func (c *Controller) GetFeeds(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
feeds, err := c.store.GetFeeds(ctx.GetUserID())
|
||||
feeds, err := c.store.GetFeeds(ctx.UserID())
|
||||
if err != nil {
|
||||
response.JSON().ServerError(errors.New("Unable to fetch feeds from the database"))
|
||||
return
|
||||
|
@ -94,7 +94,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()
|
||||
userID := ctx.UserID()
|
||||
feedID, err := request.IntegerParam("feedID")
|
||||
if err != nil {
|
||||
response.JSON().BadRequest(err)
|
||||
|
@ -117,7 +117,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()
|
||||
userID := ctx.UserID()
|
||||
feedID, err := request.IntegerParam("feedID")
|
||||
if err != nil {
|
||||
response.JSON().BadRequest(err)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue