Http Server / Client communication #7

Merged
faraphel merged 24 commits from test-http into main 2024-05-17 17:22:56 +02:00
2 changed files with 17 additions and 1 deletions
Showing only changes of commit d92d57c9e9 - Show all commits

View file

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

View file

@ -94,7 +94,20 @@ class TaskSessionManager {
when (method) {
// get a client session data
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
NanoHTTPD.Method.POST -> {