Http Server / Client communication #7
2 changed files with 17 additions and 1 deletions
|
@ -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
|
||||||
)
|
)
|
||||||
|
|
|
@ -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 -> {
|
||||||
|
|
Loading…
Reference in a new issue