Implement note creation + update tests
This commit is contained in:
parent
ecf292bccf
commit
3ab0e395b3
@ -25,13 +25,20 @@ client.test("Request executed successfully", function() {
|
|||||||
%}
|
%}
|
||||||
|
|
||||||
### Create a note
|
### Create a note
|
||||||
POST http://localhost:8081/notes/babar
|
POST http://localhost:8081/notes/tortue
|
||||||
Content-Type: application/json
|
Content-Type: application/json
|
||||||
Authorization: Bearer {{token}}
|
Authorization: Bearer {{token}}
|
||||||
|
|
||||||
|
{
|
||||||
|
"tags": [
|
||||||
|
"Dev",
|
||||||
|
"Server"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
|
||||||
> {%
|
> {%
|
||||||
client.test("Request executed successfully", function() {
|
client.test("Request executed successfully", function() {
|
||||||
client.assert(response.status === 200, "Response status is not 200");
|
client.assert(response.status === 201, "Response status is not 200");
|
||||||
});
|
});
|
||||||
%}
|
%}
|
||||||
|
|
||||||
|
|||||||
@ -8,6 +8,7 @@ import me.liuwj.ktorm.dsl.*
|
|||||||
import org.kodein.di.Kodein
|
import org.kodein.di.Kodein
|
||||||
import org.kodein.di.KodeinAware
|
import org.kodein.di.KodeinAware
|
||||||
import org.kodein.di.generic.instance
|
import org.kodein.di.generic.instance
|
||||||
|
import java.time.LocalDateTime
|
||||||
import java.time.format.DateTimeFormatter
|
import java.time.format.DateTimeFormatter
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -47,7 +48,20 @@ class NotesService(override val kodein: Kodein) : KodeinAware {
|
|||||||
.firstOrNull()
|
.firstOrNull()
|
||||||
|
|
||||||
fun createNote(userId: Int, title: String, tags: List<String>) {
|
fun createNote(userId: Int, title: String, tags: List<String>) {
|
||||||
TODO()
|
db.useTransaction {
|
||||||
|
val noteId = db.insertAndGenerateKey(Notes) {
|
||||||
|
it.title to title
|
||||||
|
it.userId to userId
|
||||||
|
it.updatedAt to LocalDateTime.now()
|
||||||
|
}
|
||||||
|
|
||||||
|
tags.forEach { tagName ->
|
||||||
|
db.insert(Tags) {
|
||||||
|
it.name to tagName
|
||||||
|
it.noteId to noteId
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fun getTagsAndChapters(noteId: Int): TagsChaptersDTO {
|
fun getTagsAndChapters(noteId: Int): TagsChaptersDTO {
|
||||||
@ -72,6 +86,7 @@ class NotesService(override val kodein: Kodein) : KodeinAware {
|
|||||||
if (title != null) {
|
if (title != null) {
|
||||||
db.update(Notes) {
|
db.update(Notes) {
|
||||||
it.title to title
|
it.title to title
|
||||||
|
it.updatedAt to LocalDateTime.now()
|
||||||
where { it.id eq noteId }
|
where { it.id eq noteId }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user