Skip to content
Snippets Groups Projects
Commit 39eb96e1 authored by thaihoangdang's avatar thaihoangdang
Browse files

fix Note class issue

parent ae2df386
No related branches found
No related tags found
1 merge request!22Http request
Pipeline #89242 failed
......@@ -16,11 +16,14 @@ class HttpOperations {
.GET()
.build()
val response = client.send(request, HttpResponse.BodyHandlers.ofString())
return response.body()
}
fun post(note: RemoteNote): String {
val jsonNote = Klaxon().toJsonString(note)
fun post(note: Note): String {
val tempNote = RemoteNote(note.id, note.title, note.text.toString(), note.dateCreated, note.lastModified)
val jsonNote = Klaxon().toJsonString(tempNote)
val client = HttpClient.newBuilder().build()
val request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:8080/notes/"))
......@@ -28,11 +31,14 @@ class HttpOperations {
.POST(HttpRequest.BodyPublishers.ofString(jsonNote))
.build()
val response = client.send(request, HttpResponse.BodyHandlers.ofString())
return response.body()
}
fun put(note: RemoteNote): String {
val jsonNote = Klaxon().toJsonString(note)
fun put(note: Note): String {
val tempNote = RemoteNote(note.id, note.title, note.text.toString(), note.dateCreated, note.lastModified)
val jsonNote = Klaxon().toJsonString(tempNote)
val client = HttpClient.newBuilder().build()
val request = HttpRequest.newBuilder()
.uri(URI.create("http://localhost:8080/notes/"))
......@@ -40,6 +46,7 @@ class HttpOperations {
.PUT(HttpRequest.BodyPublishers.ofString(jsonNote))
.build()
val response = client.send(request, HttpResponse.BodyHandlers.ofString())
return response.body()
}
......@@ -50,6 +57,7 @@ class HttpOperations {
.DELETE()
.build()
val response = client.send(request, HttpResponse.BodyHandlers.ofString())
return response.body()
}
}
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment