Merge branch 'feature/create-note'

This commit is contained in:
Hubert Van De Walle 2020-04-23 00:36:57 +02:00
commit acda25d410
4 changed files with 90 additions and 33 deletions

View File

@ -9,4 +9,5 @@ fun Routing.registerRoutes(kodein: Kodein) {
notes(kodein)
title(kodein)
chapters(kodein)
tags(kodein)
}

View File

@ -0,0 +1,20 @@
package be.vandewalleh.routing
import be.vandewalleh.extensions.userId
import be.vandewalleh.services.NotesService
import io.ktor.application.*
import io.ktor.auth.*
import io.ktor.response.*
import io.ktor.routing.*
import org.kodein.di.Kodein
import org.kodein.di.generic.instance
fun Routing.tags(kodein: Kodein) {
val notesService by kodein.instance<NotesService>()
authenticate {
get("/tags") {
call.respond(notesService.getTags(call.userId()))
}
}
}

View File

@ -111,6 +111,12 @@ class NotesService(override val kodein: Kodein) : KodeinAware {
db.useTransaction {
db.delete(Notes) { it.id eq noteId }
}
fun getTags(userId: Int): List<String> = db.from(Tags)
.leftJoin(Notes, on = Tags.noteId eq Notes.id)
.select(Tags.name)
.where { Notes.userId eq userId }
.map { it[Tags.name]!! }
}
data class ChaptersDTO(val title: String, val content: String)

View File

@ -9,40 +9,41 @@
<v-toolbar-title>Create a note</v-toolbar-title>
</v-toolbar>
<v-card-text>
<v-text-field label="Title" outlined value="My new note"></v-text-field>
<v-alert v-if="conflict" type="error">
A note with the same title already exists
</v-alert>
<v-textarea
label="Text"
outlined
counter
loader-height="5"
spellcheck="false"
value="Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse"
></v-textarea>
<v-form
ref="form"
lazy-validation
>
<v-card-text>
<v-text-field label="Title" v-model="form.title" outlined value="My new note"></v-text-field>
<v-combobox
outlined
v-model="tags"
:items="possibleTags"
:delimiters="delimiters"
label="Tags"
multiple
chips
deletable-chips
></v-combobox>
<v-combobox
outlined
v-model="form.tags"
:items="possibleTags"
:delimiters="delimiters"
label="Tags"
multiple
chips
deletable-chips
></v-combobox>
</v-card-text>
</v-card-text>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn
color="success"
depressed
>
Create
</v-btn>
</v-card-actions>
<v-card-actions>
<v-spacer></v-spacer>
<v-btn
color="success"
depressed
@click="createNote"
>
Create
</v-btn>
</v-card-actions>
</v-form>
</v-card>
</template>
@ -51,9 +52,38 @@
name: "create",
data: () => ({
delimiters: [" ", ","],
tags: [],
possibleTags: ["Dev", "Ephec", "Java"]
})
form: {
title: '',
tags: []
},
possibleTags: [],
conflict: false
}),
methods: {
createNote() {
this.conflict = false
this.$axios.post(`/notes/${this.form.title}`, {
tags: this.form.tags
}).then(_ => {
this.$router.push("/notes")
}
).catch(e => {
if (e.response && e.response.status === 409) {
this.conflict = true
} else {
console.log("??")
}
})
}
},
mounted() {
this.$axios.get("/tags")
.then(e => this.possibleTags = e.data)
.catch(e => {
console.log(e)
})
}
}
</script>