Implement retrieving of application data

This commit is contained in:
eikendev 2020-08-03 23:27:17 +02:00
parent 76c2fe9c22
commit a3de04b2a5
No known key found for this signature in database
GPG key ID: A1BDB1B28C8EF694
4 changed files with 70 additions and 20 deletions

View file

@ -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
}