mirror of
https://github.com/pushbits/server.git
synced 2025-06-12 23:52:05 +02:00
Implement retrieving of application data
This commit is contained in:
parent
76c2fe9c22
commit
a3de04b2a5
4 changed files with 70 additions and 20 deletions
|
@ -4,9 +4,15 @@ import (
|
|||
"errors"
|
||||
"net/http"
|
||||
|
||||
"github.com/eikendev/pushbits/model"
|
||||
|
||||
"github.com/gin-gonic/gin"
|
||||
)
|
||||
|
||||
type database interface {
|
||||
GetUserByID(ID uint) (*model.User, error)
|
||||
}
|
||||
|
||||
func getID(ctx *gin.Context) (uint, error) {
|
||||
id, ok := ctx.MustGet("id").(uint)
|
||||
if !ok {
|
||||
|
@ -17,3 +23,17 @@ func getID(ctx *gin.Context) (uint, error) {
|
|||
|
||||
return id, nil
|
||||
}
|
||||
|
||||
func getUser(ctx *gin.Context, db database) (*model.User, error) {
|
||||
id, err := getID(ctx)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
application, err := db.GetUserByID(id)
|
||||
if success := successOrAbort(ctx, http.StatusNotFound, err); !success {
|
||||
return nil, err
|
||||
}
|
||||
|
||||
return application, nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue