This repository has been archived by the owner on Nov 8, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(handlers): implement
auth.sessions.get
- 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
Showing
2 changed files
with
39 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters