Restructure project layout

This commit is contained in:
eikendev 2021-01-16 16:56:49 +01:00
parent a49db216d5
commit 9a4a096526
No known key found for this signature in database
GPG key ID: A1BDB1B28C8EF694
32 changed files with 35 additions and 35 deletions

29
internal/api/util.go Normal file
View file

@ -0,0 +1,29 @@
package api
import (
"errors"
"net/http"
"github.com/pushbits/server/internal/authentication"
"github.com/gin-gonic/gin"
)
func successOrAbort(ctx *gin.Context, code int, err error) bool {
if err != nil {
ctx.AbortWithError(code, err)
}
return err == nil
}
func isCurrentUser(ctx *gin.Context, ID uint) bool {
user := authentication.GetUser(ctx)
if user.ID != ID {
ctx.AbortWithError(http.StatusForbidden, errors.New("only owner can delete application"))
return false
}
return true
}