Merge branch 'feature/create-note'
This commit is contained in:
commit
acda25d410
@ -9,4 +9,5 @@ fun Routing.registerRoutes(kodein: Kodein) {
|
|||||||
notes(kodein)
|
notes(kodein)
|
||||||
title(kodein)
|
title(kodein)
|
||||||
chapters(kodein)
|
chapters(kodein)
|
||||||
|
tags(kodein)
|
||||||
}
|
}
|
||||||
20
api/src/routing/TagController.kt
Normal file
20
api/src/routing/TagController.kt
Normal 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()))
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -111,6 +111,12 @@ class NotesService(override val kodein: Kodein) : KodeinAware {
|
|||||||
db.useTransaction {
|
db.useTransaction {
|
||||||
db.delete(Notes) { it.id eq noteId }
|
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)
|
data class ChaptersDTO(val title: String, val content: String)
|
||||||
|
|||||||
@ -9,40 +9,41 @@
|
|||||||
<v-toolbar-title>Create a note</v-toolbar-title>
|
<v-toolbar-title>Create a note</v-toolbar-title>
|
||||||
</v-toolbar>
|
</v-toolbar>
|
||||||
|
|
||||||
<v-card-text>
|
<v-alert v-if="conflict" type="error">
|
||||||
<v-text-field label="Title" outlined value="My new note"></v-text-field>
|
A note with the same title already exists
|
||||||
|
</v-alert>
|
||||||
|
|
||||||
<v-textarea
|
<v-form
|
||||||
label="Text"
|
ref="form"
|
||||||
outlined
|
lazy-validation
|
||||||
counter
|
>
|
||||||
loader-height="5"
|
<v-card-text>
|
||||||
spellcheck="false"
|
<v-text-field label="Title" v-model="form.title" outlined value="My new note"></v-text-field>
|
||||||
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-combobox
|
<v-combobox
|
||||||
outlined
|
outlined
|
||||||
v-model="tags"
|
v-model="form.tags"
|
||||||
:items="possibleTags"
|
:items="possibleTags"
|
||||||
:delimiters="delimiters"
|
:delimiters="delimiters"
|
||||||
label="Tags"
|
label="Tags"
|
||||||
multiple
|
multiple
|
||||||
chips
|
chips
|
||||||
deletable-chips
|
deletable-chips
|
||||||
></v-combobox>
|
></v-combobox>
|
||||||
|
|
||||||
</v-card-text>
|
</v-card-text>
|
||||||
|
|
||||||
<v-card-actions>
|
<v-card-actions>
|
||||||
<v-spacer></v-spacer>
|
<v-spacer></v-spacer>
|
||||||
<v-btn
|
<v-btn
|
||||||
color="success"
|
color="success"
|
||||||
depressed
|
depressed
|
||||||
>
|
@click="createNote"
|
||||||
Create
|
>
|
||||||
</v-btn>
|
Create
|
||||||
</v-card-actions>
|
</v-btn>
|
||||||
|
</v-card-actions>
|
||||||
|
</v-form>
|
||||||
</v-card>
|
</v-card>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -51,9 +52,38 @@
|
|||||||
name: "create",
|
name: "create",
|
||||||
data: () => ({
|
data: () => ({
|
||||||
delimiters: [" ", ","],
|
delimiters: [" ", ","],
|
||||||
tags: [],
|
form: {
|
||||||
possibleTags: ["Dev", "Ephec", "Java"]
|
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>
|
</script>
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user