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:
parent
4fc18647ca
commit
25cbd65777
20 changed files with 80 additions and 77 deletions
|
@ -38,7 +38,7 @@ func (c *Controller) ShowCategories(ctx *core.Context, request *core.Request, re
|
|||
// ShowCategoryEntries shows all entries for the given category.
|
||||
func (c *Controller) ShowCategoryEntries(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.GetLoggedUser()
|
||||
offset := request.GetQueryIntegerParam("offset", 0)
|
||||
offset := request.QueryIntegerParam("offset", 0)
|
||||
|
||||
args, err := c.getCommonTemplateArgs(ctx)
|
||||
if err != nil {
|
||||
|
@ -102,7 +102,7 @@ func (c *Controller) SaveCategory(ctx *core.Context, request *core.Request, resp
|
|||
return
|
||||
}
|
||||
|
||||
categoryForm := form.NewCategoryForm(request.GetRequest())
|
||||
categoryForm := form.NewCategoryForm(request.Request())
|
||||
if err := categoryForm.Validate(); err != nil {
|
||||
response.Html().Render("create_category", args.Merge(tplParams{
|
||||
"errorMessage": err.Error(),
|
||||
|
@ -165,7 +165,7 @@ func (c *Controller) UpdateCategory(ctx *core.Context, request *core.Request, re
|
|||
return
|
||||
}
|
||||
|
||||
categoryForm := form.NewCategoryForm(request.GetRequest())
|
||||
categoryForm := form.NewCategoryForm(request.Request())
|
||||
args, err := c.getCategoryFormTemplateArgs(ctx, user, category, categoryForm)
|
||||
if err != nil {
|
||||
response.Html().ServerError(err)
|
||||
|
@ -216,7 +216,7 @@ func (c *Controller) RemoveCategory(ctx *core.Context, request *core.Request, re
|
|||
}
|
||||
|
||||
func (c *Controller) getCategoryFromURL(ctx *core.Context, request *core.Request, response *core.Response) (*model.Category, error) {
|
||||
categoryID, err := request.GetIntegerParam("categoryID")
|
||||
categoryID, err := request.IntegerParam("categoryID")
|
||||
if err != nil {
|
||||
response.Html().BadRequest(err)
|
||||
return nil, err
|
||||
|
|
|
@ -18,13 +18,13 @@ func (c *Controller) ShowFeedEntry(ctx *core.Context, request *core.Request, res
|
|||
user := ctx.GetLoggedUser()
|
||||
sortingDirection := model.DefaultSortingDirection
|
||||
|
||||
entryID, err := request.GetIntegerParam("entryID")
|
||||
entryID, err := request.IntegerParam("entryID")
|
||||
if err != nil {
|
||||
response.Html().BadRequest(err)
|
||||
return
|
||||
}
|
||||
|
||||
feedID, err := request.GetIntegerParam("feedID")
|
||||
feedID, err := request.IntegerParam("feedID")
|
||||
if err != nil {
|
||||
response.Html().BadRequest(err)
|
||||
return
|
||||
|
@ -111,13 +111,13 @@ func (c *Controller) ShowCategoryEntry(ctx *core.Context, request *core.Request,
|
|||
user := ctx.GetLoggedUser()
|
||||
sortingDirection := model.DefaultSortingDirection
|
||||
|
||||
categoryID, err := request.GetIntegerParam("categoryID")
|
||||
categoryID, err := request.IntegerParam("categoryID")
|
||||
if err != nil {
|
||||
response.Html().BadRequest(err)
|
||||
return
|
||||
}
|
||||
|
||||
entryID, err := request.GetIntegerParam("entryID")
|
||||
entryID, err := request.IntegerParam("entryID")
|
||||
if err != nil {
|
||||
response.Html().BadRequest(err)
|
||||
return
|
||||
|
@ -205,7 +205,7 @@ func (c *Controller) ShowUnreadEntry(ctx *core.Context, request *core.Request, r
|
|||
user := ctx.GetLoggedUser()
|
||||
sortingDirection := model.DefaultSortingDirection
|
||||
|
||||
entryID, err := request.GetIntegerParam("entryID")
|
||||
entryID, err := request.IntegerParam("entryID")
|
||||
if err != nil {
|
||||
response.Html().BadRequest(err)
|
||||
return
|
||||
|
@ -292,7 +292,7 @@ func (c *Controller) ShowReadEntry(ctx *core.Context, request *core.Request, res
|
|||
user := ctx.GetLoggedUser()
|
||||
sortingDirection := model.DefaultSortingDirection
|
||||
|
||||
entryID, err := request.GetIntegerParam("entryID")
|
||||
entryID, err := request.IntegerParam("entryID")
|
||||
if err != nil {
|
||||
response.Html().BadRequest(err)
|
||||
return
|
||||
|
@ -369,7 +369,7 @@ func (c *Controller) ShowReadEntry(ctx *core.Context, request *core.Request, res
|
|||
func (c *Controller) UpdateEntriesStatus(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.GetLoggedUser()
|
||||
|
||||
entryIDs, status, err := payload.DecodeEntryStatusPayload(request.GetBody())
|
||||
entryIDs, status, err := payload.DecodeEntryStatusPayload(request.Body())
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
response.Json().BadRequest(nil)
|
||||
|
|
|
@ -39,7 +39,7 @@ func (c *Controller) ShowFeedsPage(ctx *core.Context, request *core.Request, res
|
|||
// ShowFeedEntries shows all entries for the given feed.
|
||||
func (c *Controller) ShowFeedEntries(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.GetLoggedUser()
|
||||
offset := request.GetQueryIntegerParam("offset", 0)
|
||||
offset := request.QueryIntegerParam("offset", 0)
|
||||
|
||||
args, err := c.getCommonTemplateArgs(ctx)
|
||||
if err != nil {
|
||||
|
@ -108,7 +108,7 @@ func (c *Controller) UpdateFeed(ctx *core.Context, request *core.Request, respon
|
|||
return
|
||||
}
|
||||
|
||||
feedForm := form.NewFeedForm(request.GetRequest())
|
||||
feedForm := form.NewFeedForm(request.Request())
|
||||
args, err := c.getFeedFormTemplateArgs(ctx, user, feed, feedForm)
|
||||
if err != nil {
|
||||
response.Html().ServerError(err)
|
||||
|
@ -136,7 +136,7 @@ func (c *Controller) UpdateFeed(ctx *core.Context, request *core.Request, respon
|
|||
|
||||
// RemoveFeed delete a subscription from the database and redirect to the list of feeds page.
|
||||
func (c *Controller) RemoveFeed(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
feedID, err := request.GetIntegerParam("feedID")
|
||||
feedID, err := request.IntegerParam("feedID")
|
||||
if err != nil {
|
||||
response.Html().ServerError(err)
|
||||
return
|
||||
|
@ -153,7 +153,7 @@ func (c *Controller) RemoveFeed(ctx *core.Context, request *core.Request, respon
|
|||
|
||||
// RefreshFeed refresh a subscription and redirect to the feed entries page.
|
||||
func (c *Controller) RefreshFeed(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
feedID, err := request.GetIntegerParam("feedID")
|
||||
feedID, err := request.IntegerParam("feedID")
|
||||
if err != nil {
|
||||
response.Html().BadRequest(err)
|
||||
return
|
||||
|
@ -168,7 +168,7 @@ func (c *Controller) RefreshFeed(ctx *core.Context, request *core.Request, respo
|
|||
}
|
||||
|
||||
func (c *Controller) getFeedFromURL(request *core.Request, response *core.Response, user *model.User) (*model.Feed, error) {
|
||||
feedID, err := request.GetIntegerParam("feedID")
|
||||
feedID, err := request.IntegerParam("feedID")
|
||||
if err != nil {
|
||||
response.Html().BadRequest(err)
|
||||
return nil, err
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
// ShowHistoryPage renders the page with all read entries.
|
||||
func (c *Controller) ShowHistoryPage(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.GetLoggedUser()
|
||||
offset := request.GetQueryIntegerParam("offset", 0)
|
||||
offset := request.QueryIntegerParam("offset", 0)
|
||||
|
||||
args, err := c.getCommonTemplateArgs(ctx)
|
||||
if err != nil {
|
||||
|
|
|
@ -10,7 +10,7 @@ import (
|
|||
)
|
||||
|
||||
func (c *Controller) ShowIcon(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
iconID, err := request.GetIntegerParam("iconID")
|
||||
iconID, err := request.IntegerParam("iconID")
|
||||
if err != nil {
|
||||
response.Html().BadRequest(err)
|
||||
return
|
||||
|
|
|
@ -26,7 +26,7 @@ func (c *Controller) ShowLoginPage(ctx *core.Context, request *core.Request, res
|
|||
}
|
||||
|
||||
func (c *Controller) CheckLogin(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
authForm := form.NewAuthForm(request.GetRequest())
|
||||
authForm := form.NewAuthForm(request.Request())
|
||||
tplParams := tplParams{
|
||||
"errorMessage": "Invalid username or password.",
|
||||
"csrf": ctx.GetCsrfToken(),
|
||||
|
@ -46,8 +46,8 @@ func (c *Controller) CheckLogin(ctx *core.Context, request *core.Request, respon
|
|||
|
||||
sessionToken, err := c.store.CreateSession(
|
||||
authForm.Username,
|
||||
request.GetHeaders().Get("User-Agent"),
|
||||
realip.RealIP(request.GetRequest()),
|
||||
request.Request().UserAgent(),
|
||||
realip.RealIP(request.Request()),
|
||||
)
|
||||
if err != nil {
|
||||
response.Html().ServerError(err)
|
||||
|
@ -71,7 +71,7 @@ func (c *Controller) CheckLogin(ctx *core.Context, request *core.Request, respon
|
|||
func (c *Controller) Logout(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.GetLoggedUser()
|
||||
|
||||
sessionCookie := request.GetCookie("sessionID")
|
||||
sessionCookie := request.Cookie("sessionID")
|
||||
if err := c.store.RemoveSessionByToken(user.ID, sessionCookie); err != nil {
|
||||
log.Printf("[UI:Logout] %v", err)
|
||||
}
|
||||
|
|
|
@ -34,7 +34,7 @@ func (c *Controller) Import(ctx *core.Context, request *core.Request, response *
|
|||
}
|
||||
|
||||
func (c *Controller) UploadOPML(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
file, fileHeader, err := request.GetFile("file")
|
||||
file, fileHeader, err := request.File("file")
|
||||
if err != nil {
|
||||
log.Println(err)
|
||||
response.Redirect(ctx.GetRoute("import"))
|
||||
|
|
|
@ -16,7 +16,7 @@ import (
|
|||
)
|
||||
|
||||
func (c *Controller) ImageProxy(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
encodedURL := request.GetStringParam("encodedURL", "")
|
||||
encodedURL := request.StringParam("encodedURL", "")
|
||||
if encodedURL == "" {
|
||||
response.Html().BadRequest(errors.New("No URL provided"))
|
||||
return
|
||||
|
|
|
@ -23,7 +23,7 @@ func (c *Controller) ShowSessions(ctx *core.Context, request *core.Request, resp
|
|||
return
|
||||
}
|
||||
|
||||
sessionCookie := request.GetCookie("sessionID")
|
||||
sessionCookie := request.Cookie("sessionID")
|
||||
response.Html().Render("sessions", args.Merge(tplParams{
|
||||
"sessions": sessions,
|
||||
"currentSessionToken": sessionCookie,
|
||||
|
@ -34,7 +34,7 @@ func (c *Controller) ShowSessions(ctx *core.Context, request *core.Request, resp
|
|||
func (c *Controller) RemoveSession(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.GetLoggedUser()
|
||||
|
||||
sessionID, err := request.GetIntegerParam("sessionID")
|
||||
sessionID, err := request.IntegerParam("sessionID")
|
||||
if err != nil {
|
||||
response.Html().BadRequest(err)
|
||||
return
|
||||
|
|
|
@ -27,7 +27,7 @@ func (c *Controller) ShowSettings(ctx *core.Context, request *core.Request, resp
|
|||
func (c *Controller) UpdateSettings(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.GetLoggedUser()
|
||||
|
||||
settingsForm := form.NewSettingsForm(request.GetRequest())
|
||||
settingsForm := form.NewSettingsForm(request.Request())
|
||||
args, err := c.getSettingsFormTemplateArgs(ctx, user, settingsForm)
|
||||
if err != nil {
|
||||
response.Html().ServerError(err)
|
||||
|
|
|
@ -13,7 +13,7 @@ import (
|
|||
)
|
||||
|
||||
func (c *Controller) Stylesheet(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
stylesheet := request.GetStringParam("name", "white")
|
||||
stylesheet := request.StringParam("name", "white")
|
||||
body := static.Stylesheets["common"]
|
||||
etag := static.StylesheetsChecksums["common"]
|
||||
|
||||
|
|
|
@ -33,7 +33,7 @@ func (c *Controller) SubmitSubscription(ctx *core.Context, request *core.Request
|
|||
return
|
||||
}
|
||||
|
||||
subscriptionForm := form.NewSubscriptionForm(request.GetRequest())
|
||||
subscriptionForm := form.NewSubscriptionForm(request.Request())
|
||||
if err := subscriptionForm.Validate(); err != nil {
|
||||
response.Html().Render("add_subscription", args.Merge(tplParams{
|
||||
"form": subscriptionForm,
|
||||
|
@ -89,7 +89,7 @@ func (c *Controller) ChooseSubscription(ctx *core.Context, request *core.Request
|
|||
return
|
||||
}
|
||||
|
||||
subscriptionForm := form.NewSubscriptionForm(request.GetRequest())
|
||||
subscriptionForm := form.NewSubscriptionForm(request.Request())
|
||||
if err := subscriptionForm.Validate(); err != nil {
|
||||
response.Html().Render("add_subscription", args.Merge(tplParams{
|
||||
"form": subscriptionForm,
|
||||
|
|
|
@ -12,7 +12,7 @@ import (
|
|||
// ShowUnreadPage render the page with all unread entries.
|
||||
func (c *Controller) ShowUnreadPage(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
user := ctx.GetLoggedUser()
|
||||
offset := request.GetQueryIntegerParam("offset", 0)
|
||||
offset := request.QueryIntegerParam("offset", 0)
|
||||
|
||||
builder := c.store.GetEntryQueryBuilder(user.ID, user.Timezone)
|
||||
builder.WithStatus(model.EntryStatusUnread)
|
||||
|
|
|
@ -72,7 +72,7 @@ func (c *Controller) SaveUser(ctx *core.Context, request *core.Request, response
|
|||
return
|
||||
}
|
||||
|
||||
userForm := form.NewUserForm(request.GetRequest())
|
||||
userForm := form.NewUserForm(request.Request())
|
||||
if err := userForm.ValidateCreation(); err != nil {
|
||||
response.Html().Render("create_user", args.Merge(tplParams{
|
||||
"menu": "settings",
|
||||
|
@ -153,7 +153,7 @@ func (c *Controller) UpdateUser(ctx *core.Context, request *core.Request, respon
|
|||
return
|
||||
}
|
||||
|
||||
userForm := form.NewUserForm(request.GetRequest())
|
||||
userForm := form.NewUserForm(request.Request())
|
||||
if err := userForm.ValidateModification(); err != nil {
|
||||
response.Html().Render("edit_user", args.Merge(tplParams{
|
||||
"menu": "settings",
|
||||
|
@ -210,7 +210,7 @@ func (c *Controller) RemoveUser(ctx *core.Context, request *core.Request, respon
|
|||
}
|
||||
|
||||
func (c *Controller) getUserFromURL(ctx *core.Context, request *core.Request, response *core.Response) (*model.User, error) {
|
||||
userID, err := request.GetIntegerParam("userID")
|
||||
userID, err := request.IntegerParam("userID")
|
||||
if err != nil {
|
||||
response.Html().BadRequest(err)
|
||||
return nil, err
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue