From 8578a3954a1abafa8042b35000a1c71e1d5480be Mon Sep 17 00:00:00 2001 From: TheComputerM Date: Wed, 4 Sep 2024 00:39:13 +0530 Subject: [PATCH] feat: add userinfo endpoint --- api/Multipartus/Get lecture videos.bru | 2 +- api/Multipartus/Get lectures.bru | 2 +- api/Multipartus/Get pinned subjects.bru | 2 +- api/Multipartus/Get subjects.bru | 2 +- api/Multipartus/Get userinfo.bru | 11 +++++++++++ api/Multipartus/Get video chunk.bru | 2 +- api/Multipartus/Get video index.bru | 2 +- api/Multipartus/Get video key.bru | 2 +- internal/routes/impartus.go | 22 ++++++++++++++++++++++ 9 files changed, 40 insertions(+), 7 deletions(-) create mode 100644 api/Multipartus/Get userinfo.bru diff --git a/api/Multipartus/Get lecture videos.bru b/api/Multipartus/Get lecture videos.bru index 3f00942..e293a7d 100644 --- a/api/Multipartus/Get lecture videos.bru +++ b/api/Multipartus/Get lecture videos.bru @@ -1,7 +1,7 @@ meta { name: Get lecture videos type: http - seq: 5 + seq: 6 } get { diff --git a/api/Multipartus/Get lectures.bru b/api/Multipartus/Get lectures.bru index 31b421d..f1ba389 100644 --- a/api/Multipartus/Get lectures.bru +++ b/api/Multipartus/Get lectures.bru @@ -1,7 +1,7 @@ meta { name: Get lectures type: http - seq: 4 + seq: 5 } get { diff --git a/api/Multipartus/Get pinned subjects.bru b/api/Multipartus/Get pinned subjects.bru index 7aa1af7..665727e 100644 --- a/api/Multipartus/Get pinned subjects.bru +++ b/api/Multipartus/Get pinned subjects.bru @@ -1,7 +1,7 @@ meta { name: Get pinned subjects type: http - seq: 3 + seq: 4 } get { diff --git a/api/Multipartus/Get subjects.bru b/api/Multipartus/Get subjects.bru index c8ab38d..5280088 100644 --- a/api/Multipartus/Get subjects.bru +++ b/api/Multipartus/Get subjects.bru @@ -1,7 +1,7 @@ meta { name: Get subjects type: http - seq: 2 + seq: 3 } get { diff --git a/api/Multipartus/Get userinfo.bru b/api/Multipartus/Get userinfo.bru new file mode 100644 index 0000000..cc079a6 --- /dev/null +++ b/api/Multipartus/Get userinfo.bru @@ -0,0 +1,11 @@ +meta { + name: Get userinfo + type: http + seq: 2 +} + +get { + url: {{baseUrl}}/impartus/user + body: none + auth: inherit +} diff --git a/api/Multipartus/Get video chunk.bru b/api/Multipartus/Get video chunk.bru index 7f07748..eafd24c 100644 --- a/api/Multipartus/Get video chunk.bru +++ b/api/Multipartus/Get video chunk.bru @@ -1,7 +1,7 @@ meta { name: Get video chunk type: http - seq: 8 + seq: 9 } get { diff --git a/api/Multipartus/Get video index.bru b/api/Multipartus/Get video index.bru index e1b686c..4af499e 100644 --- a/api/Multipartus/Get video index.bru +++ b/api/Multipartus/Get video index.bru @@ -1,7 +1,7 @@ meta { name: Get video index type: http - seq: 7 + seq: 8 } get { diff --git a/api/Multipartus/Get video key.bru b/api/Multipartus/Get video key.bru index b933f42..965a7be 100644 --- a/api/Multipartus/Get video key.bru +++ b/api/Multipartus/Get video key.bru @@ -1,7 +1,7 @@ meta { name: Get video key type: http - seq: 6 + seq: 7 } get { diff --git a/internal/routes/impartus.go b/internal/routes/impartus.go index ad34764..7445709 100644 --- a/internal/routes/impartus.go +++ b/internal/routes/impartus.go @@ -65,6 +65,28 @@ func RegisterImpartusRoutes(router *gin.Engine) { r.GET("/user", func(ctx *gin.Context) { // TODO: return a bunch of user info such as number of pinned subjects etc // also return if user currently has a valid impartus jwt + + claims := auth.GetClaims(ctx) + registered, err := surrealdb.SmartUnmarshal[bool]( + impartus.Repository.DB.Query( + "SELECT VALUE count(email = $email) == 1 FROM ONLY user LIMIT 1", + map[string]interface{}{ + "email": claims.EMail, + }, + ), + ) + + if err != nil { + ctx.AbortWithStatusJSON(http.StatusInternalServerError, gin.H{ + "message": err.Error(), + }) + return + } + + ctx.JSON(http.StatusOK, gin.H{ + "registered": registered, + // TODO: add number of subjects/lectures added to database to response + }) }) // Creates a new entry for the user in the database.