Skip to content

Commit

Permalink
feat: add userinfo endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
TheComputerM committed Sep 3, 2024
1 parent f885ad0 commit 8578a39
Show file tree
Hide file tree
Showing 9 changed files with 40 additions and 7 deletions.
2 changes: 1 addition & 1 deletion api/Multipartus/Get lecture videos.bru
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: Get lecture videos
type: http
seq: 5
seq: 6
}

get {
Expand Down
2 changes: 1 addition & 1 deletion api/Multipartus/Get lectures.bru
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: Get lectures
type: http
seq: 4
seq: 5
}

get {
Expand Down
2 changes: 1 addition & 1 deletion api/Multipartus/Get pinned subjects.bru
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: Get pinned subjects
type: http
seq: 3
seq: 4
}

get {
Expand Down
2 changes: 1 addition & 1 deletion api/Multipartus/Get subjects.bru
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: Get subjects
type: http
seq: 2
seq: 3
}

get {
Expand Down
11 changes: 11 additions & 0 deletions api/Multipartus/Get userinfo.bru
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
meta {
name: Get userinfo
type: http
seq: 2
}

get {
url: {{baseUrl}}/impartus/user
body: none
auth: inherit
}
2 changes: 1 addition & 1 deletion api/Multipartus/Get video chunk.bru
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: Get video chunk
type: http
seq: 8
seq: 9
}

get {
Expand Down
2 changes: 1 addition & 1 deletion api/Multipartus/Get video index.bru
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: Get video index
type: http
seq: 7
seq: 8
}

get {
Expand Down
2 changes: 1 addition & 1 deletion api/Multipartus/Get video key.bru
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
meta {
name: Get video key
type: http
seq: 6
seq: 7
}

get {
Expand Down
22 changes: 22 additions & 0 deletions internal/routes/impartus.go
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 8578a39

Please sign in to comment.