mirror of
https://github.com/Govor-team/Govor.git
synced 2026-07-21 19:54:55 +00:00
3.6 KiB
3.6 KiB
description
| description |
|---|
| Controller for managing user sessions, including retrieving and closing sessions. |
SessionController
Controller Description
- Route:
api/session - Authorize: Requires authenticated user with roles "Admin" or "User" (
[Authorize(Roles = "Admin,User")]).
Endpoints
GetAllSessions
- Description: Retrieves all active sessions for the authenticated user.
- Route:
[GET] api/session/all - HTTP Method:
GET - Request: None
- Responses:
-
200 OK: Returns a list of user sessions.
[ { "id": "Guid", "deviceInfo": "string", "createdAt": "DateTime", "expiresAt": "DateTime", "isRevoked": "boolean" } ] -
403 Forbidden: If user lacks authorization.
"string" -
500 Internal Server Error: Indicates an unexpected error.
"Unexpected Error! Please try again later."
-
CloseSession
- Description: Closes a specific session for the authenticated user.
- Route:
[DELETE] api/session/close/{sessionId} - HTTP Method:
DELETE - Request:
- Path Parameter:
sessionId(Guid, required): ID of the session to close.
- Path Parameter:
- Responses:
-
200 OK: Indicates session was successfully closed.
- No body.
-
400 Bad Request: If
sessionIdis invalid or operation fails."string" -
403 Forbidden: If user lacks authorization.
"string" -
404 Not Found: If session is not found.
"string" -
500 Internal Server Error: Indicates an unexpected error.
"Unexpected Error! Please try again later."
-
CloseAllSessions
- Description: Closes all active sessions for the authenticated user.
- Route:
[DELETE] api/session/close/all - HTTP Method:
DELETE - Request: None
- Responses:
-
200 OK: Indicates all sessions were successfully closed.
- No body.
-
403 Forbidden: If user lacks authorization.
"string" -
500 Internal Server Error: Indicates an unexpected error.
"Unexpected Error! Please try again later."
-
Data Models
SessionDto
-
Description: Data transfer object for session information.
-
Structure:
{ "id": "Guid", "deviceInfo": "string", "createdAt": "DateTime", "expiresAt": "DateTime", "isRevoked": "boolean" }
Error Handling
- Invalid User ID: Handled by
ICurrentUserService, aborts if invalid. - Invalid Operations: Returns
400 Bad RequestforInvalidOperationException. - Unauthorized Access: Returns
403 ForbiddenforUnauthorizedAccessException. - Resource Not Found: Returns
404 Not FoundforNotFoundException. - Unexpected Errors: Caught and returned as
500 Internal Server Error.
Logging
- Logs warnings for
UnauthorizedAccessExceptionandNotFoundException. - Logs errors for
InvalidOperationExceptionand unexpected exceptions.