From 29d6db20096e61efa9a792ef837ef93ca14107ae Mon Sep 17 00:00:00 2001 From: Derrick Hammer Date: Fri, 9 Jun 2023 07:38:46 -0400 Subject: [PATCH] feat: add getCurrentUserId helper function --- controller/controller.go | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/controller/controller.go b/controller/controller.go index 7ad659c..b84527e 100644 --- a/controller/controller.go +++ b/controller/controller.go @@ -5,6 +5,7 @@ import ( "git.lumeweb.com/LumeWeb/portal/logger" "github.com/kataras/iris/v12" "go.uber.org/zap" + "strconv" ) func tryParseRequest(r interface{}, ctx iris.Context) (interface{}, bool) { @@ -70,3 +71,16 @@ func (c Controller) respondJSON(data interface{}) { logger.Get().Error("failed to generate response", zap.Error(err)) } } + +func getCurrentUserId(ctx iris.Context) uint { + usr := ctx.User() + + if usr == nil { + return 0 + } + + sid, _ := usr.GetID() + userID, _ := strconv.Atoi(sid) + + return uint(userID) +}