mirror of
https://github.com/miniflux/v2.git
synced 2025-06-27 16:36:00 +00:00
Add API handler to fetch user by username
This commit is contained in:
parent
d5b8f2fb88
commit
c3c27e3637
6 changed files with 115 additions and 23 deletions
|
@ -88,8 +88,8 @@ func (c *Controller) UpdateUser(ctx *core.Context, request *core.Request, respon
|
|||
response.JSON().Created(originalUser)
|
||||
}
|
||||
|
||||
// GetUsers is the API handler to get the list of users.
|
||||
func (c *Controller) GetUsers(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
// Users is the API handler to get the list of users.
|
||||
func (c *Controller) Users(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
if !ctx.IsAdminUser() {
|
||||
response.JSON().Forbidden()
|
||||
return
|
||||
|
@ -104,8 +104,8 @@ func (c *Controller) GetUsers(ctx *core.Context, request *core.Request, response
|
|||
response.JSON().Standard(users)
|
||||
}
|
||||
|
||||
// GetUser is the API handler to fetch the given user.
|
||||
func (c *Controller) GetUser(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
// UserByID is the API handler to fetch the given user by the ID.
|
||||
func (c *Controller) UserByID(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
if !ctx.IsAdminUser() {
|
||||
response.JSON().Forbidden()
|
||||
return
|
||||
|
@ -131,6 +131,28 @@ func (c *Controller) GetUser(ctx *core.Context, request *core.Request, response
|
|||
response.JSON().Standard(user)
|
||||
}
|
||||
|
||||
// UserByUsername is the API handler to fetch the given user by the username.
|
||||
func (c *Controller) UserByUsername(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
if !ctx.IsAdminUser() {
|
||||
response.JSON().Forbidden()
|
||||
return
|
||||
}
|
||||
|
||||
username := request.StringParam("username", "")
|
||||
user, err := c.store.UserByUsername(username)
|
||||
if err != nil {
|
||||
response.JSON().BadRequest(errors.New("Unable to fetch this user from the database"))
|
||||
return
|
||||
}
|
||||
|
||||
if user == nil {
|
||||
response.JSON().NotFound(errors.New("User not found"))
|
||||
return
|
||||
}
|
||||
|
||||
response.JSON().Standard(user)
|
||||
}
|
||||
|
||||
// RemoveUser is the API handler to remove an existing user.
|
||||
func (c *Controller) RemoveUser(ctx *core.Context, request *core.Request, response *core.Response) {
|
||||
if !ctx.IsAdminUser() {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue