Skip to content
This repository has been archived by the owner on Nov 8, 2023. It is now read-only.

Commit

Permalink
feat(handlers): implement auth.sessions.get
Browse files Browse the repository at this point in the history
- implement handler for `auth.sessions.get`
- add server for `auth.sessions.get` to main.go

#3 Closes #6
  • Loading branch information
Leo Breuer committed Jul 22, 2023
1 parent 07746a4 commit e1e94c1
Show file tree
Hide file tree
Showing 2 changed files with 39 additions and 0 deletions.
38 changes: 38 additions & 0 deletions handlers/session_get.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package handlers

import (
"encoding/json"
"fmt"

"gorm.io/gorm"
)

type GetUserSessionData struct {
UserID string
}

func GetUserSession(db *gorm.DB, rawData []byte) (Response, error) {
var sessionData GetUserSessionData
err := json.Unmarshal(rawData, &sessionData)
if err != nil {
return Response{
Content: nil,
Status: ResponseStatus{
Code: 422,
Title: "Not processable!",
Detail: "The data send to the worker was not processable.",
Type: "https://auth.miauw.social/login/not-processable",
},
}, err
}
// var sessions []models.Session
results := make(map[string]interface{})
db.Where("user = ?", sessionData.UserID).Take(&results)
fmt.Println(results)
return Response{
Content: &results,
Status: ResponseStatus{
Code: 200,
},
}, nil
}
1 change: 1 addition & 0 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,5 +7,6 @@ func main() {
go Serve("auth.initial", handlers.UserCreate)
go Serve("auth.login", handlers.UserLogin)
go Serve("auth.verify", handlers.UserVerify)
go Serve("auth.sessions.get", handlers.GetUserSession)
<-forever
}

0 comments on commit e1e94c1

Please sign in to comment.