Merge branch 'feature/chapters'

This commit is contained in:
Hubert Van De Walle 2020-04-19 17:44:18 +02:00
commit a60fc317f3
6 changed files with 36 additions and 8 deletions

View File

@ -1,9 +1,13 @@
CREATE TABLE `Tags`
CREATE TABLE `Chapters`
(
`id` int PRIMARY KEY AUTO_INCREMENT,
`name` varchar(50) NOT NULL,
`note_id` int NOT NULL
`number` int NOT NULL,
`content` text NOT NULL,
`note_id` int NOT NULL
);
ALTER TABLE `Tags`
ADD FOREIGN KEY (`note_id`) REFERENCES `Notes` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `Chapters`
ADD FOREIGN KEY (`note_id`) REFERENCES `Notes` (`id`) ON DELETE RESTRICT ON UPDATE RESTRICT;
ALTER TABLE `Notes`
DROP COLUMN `content`;

View File

@ -43,7 +43,6 @@ class NoteController(kodein: Kodein) : KodeinController(kodein) {
val note = Note {
this.title = body.title
this.content = body.content
this.user = user
}

View File

@ -0,0 +1,12 @@
package be.vandewalleh.entities
import me.liuwj.ktorm.entity.Entity
interface Chapter : Entity<Chapter> {
companion object : Entity.Factory<Chapter>()
val id: Int
var number: Int
var content: String
var note: Note
}

View File

@ -8,7 +8,6 @@ interface Note : Entity<Note> {
val id: Int
var title: String
var content: String
var user: User
var lastViewed: LocalDateTime?
}

View File

@ -0,0 +1,15 @@
package be.vandewalleh.tables
import be.vandewalleh.entities.Chapter
import be.vandewalleh.entities.Tag
import me.liuwj.ktorm.schema.Table
import me.liuwj.ktorm.schema.int
import me.liuwj.ktorm.schema.text
import me.liuwj.ktorm.schema.varchar
object Chapters : Table<Chapter>("Chapters") {
val id by int("id").primaryKey().bindTo { it.id }
val number by int("number").bindTo { it.number }
val content by text("content").bindTo { it.content }
val noteId by int("note_id").references(Notes) { it.note }
}

View File

@ -6,7 +6,6 @@ import me.liuwj.ktorm.schema.*
object Notes : Table<Note>("Notes") {
val id by int("id").primaryKey().bindTo { it.id }
val title by varchar("title").bindTo { it.title }
val content by text("content").bindTo { it.content }
val user by int("user_id").references(Users) { it.user }
val lastViewed by datetime("last_viewed").bindTo { it.lastViewed }
}