[WIP] added api read session data

This commit is contained in:
Faraphel 2024-05-10 13:41:51 +02:00
parent 6b4b420a22
commit d92d57c9e9
2 changed files with 17 additions and 1 deletions

View file

@ -1,10 +1,13 @@
package com.faraphel.tasks_valider.connectivity.task.session package com.faraphel.tasks_valider.connectivity.task.session
import kotlinx.serialization.Serializable
/** /**
* store the data of a session in the task system * store the data of a session in the task system
* @param role the role accorded to the session * @param role the role accorded to the session
*/ */
@Serializable
data class TaskSession( data class TaskSession(
var role: TaskRole = TaskRole.STUDENT var role: TaskRole = TaskRole.STUDENT
) )

View file

@ -94,7 +94,20 @@ class TaskSessionManager {
when (method) { when (method) {
// get a client session data // get a client session data
NanoHTTPD.Method.GET -> { NanoHTTPD.Method.GET -> {
TODO("Faraphel: implement get") // check the permission of the session
if (taskSession.role.permissions.contains(TaskPermission.READ))
return NanoHTTPD.newFixedLengthResponse(
NanoHTTPD.Response.Status.FORBIDDEN,
"text/plain",
"Forbidden"
)
// return the session data
return NanoHTTPD.newFixedLengthResponse(
NanoHTTPD.Response.Status.OK,
"application/json",
jsonParser.toJson(taskSession)
)
} }
// change a client session data // change a client session data
NanoHTTPD.Method.POST -> { NanoHTTPD.Method.POST -> {