Skip to content
Snippets Groups Projects
Commit 00f2601a authored by ichung14's avatar ichung14
Browse files

service implementations

parent 06a98a92
No related branches found
No related tags found
No related merge requests found
......@@ -5,7 +5,6 @@ plugins {
id("io.spring.dependency-management") version "1.0.11.RELEASE"
kotlin("jvm") version "1.6.10"
kotlin("plugin.spring") version "1.6.10"
kotlin("plugin.jpa") version "1.6.10"
}
group = "com.cs398"
......@@ -17,12 +16,12 @@ repositories {
}
dependencies {
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
implementation("org.springframework.boot:spring-boot-starter-jdbc")
implementation("org.springframework.boot:spring-boot-starter-data-jdbc")
implementation("org.springframework.boot:spring-boot-starter-web")
implementation("com.fasterxml.jackson.module:jackson-module-kotlin")
implementation("org.jetbrains.kotlin:kotlin-reflect")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8")
runtimeOnly("com.h2database:h2")
testImplementation("org.springframework.boot:spring-boot-starter-test")
}
......
File added
2022-03-20 17:05:50 jdbc[3]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "([*]"; expected "(, WITH, SELECT, TABLE, VALUES"; SQL statement:
( [42001-200]
2022-03-20 17:05:59 jdbc[3]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "([*]"; expected "(, WITH, SELECT, TABLE, VALUES"; SQL statement:
( [42001-200]
2022-03-20 17:08:15 jdbc[3]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "FOLDER" not found; SQL statement:
CREATE TABLE IF NOT EXISTS `Note` ( `title` TEXT NOT NULL, `content` TEXT NOT NULL, `notify` INTEGER NOT NULL, `folderId` INTEGER, `createdTime` DATE NOT NULL, `updatedTime` DATE NOT NULL, `id` INTEGER NOT NULL, FOREIGN KEY(`folderId`) REFERENCES `Folder`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL ) [42102-200]
2022-03-20 17:09:02 jdbc[3]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "CREATE TABLE IF NOT EXISTS `FOLDER` ( `NAME` TEXT NOT NULL, `PARENT` INTEGER, `ID` INTEGER PRIMARY KEY AUTOINCREMENT[*] NOT NULL, `CREATEDTIME` DATE NOT NULL, `UPDATEDTIME` DATE NOT NULL, FOREIGN KEY(`PARENT`) REFERENCES `FOLDER`(`ID`) ON UPDATE NO ACTION ON DELETE CASCADE )"; expected "HASH, AUTO_INCREMENT, NOT, NULL, COMMENT, CHECK, REFERENCES, ,, )"; SQL statement:
CREATE TABLE IF NOT EXISTS `Folder` ( `name` TEXT NOT NULL, `parent` INTEGER, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `createdTime` DATE NOT NULL, `updatedTime` DATE NOT NULL, FOREIGN KEY(`parent`) REFERENCES `Folder`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE ) [42001-200]
2022-03-20 17:10:34 jdbc[3]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "CREATE TABLE IF NOT EXISTS `NOTES` ( `TITLE` TEXT NOT NULL, `CONTENT` TEXT NOT NULL, `NOTIFY` INTEGER NOT NULL, `FOLDERID` INTEGER, `CREATEDTIME` DATE NOT NULL, `UPDATEDTIME` DATE NOT NULL, `ID` INTEGER INTEGER[*] NOT NULL, FOREIGN KEY(`FOLDERID`) REFERENCES `FOLDER`(`ID`) ON UPDATE NO ACTION ON DELETE SET NULL )"; expected "(, FOR, UNSIGNED, INVISIBLE, VISIBLE, NOT, NULL, AS, DEFAULT, GENERATED, ON, NOT, NULL, AUTO_INCREMENT, BIGSERIAL, SERIAL, IDENTITY, NULL_TO_DEFAULT, SEQUENCE, SELECTIVITY, COMMENT, CONSTRAINT, PRIMARY, UNIQUE, NOT, NULL, COMMENT, CHECK, REFERENCES, ,, )"; SQL statement:
CREATE TABLE IF NOT EXISTS `notes` ( `title` TEXT NOT NULL, `content` TEXT NOT NULL, `notify` INTEGER NOT NULL, `folderId` INTEGER, `createdTime` DATE NOT NULL, `updatedTime` DATE NOT NULL, `id` INTEGER INTEGER NOT NULL, FOREIGN KEY(`folderId`) REFERENCES `Folder`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL ) [42001-200]
2022-03-20 17:10:51 jdbc[3]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "CREATE TABLE IF NOT EXISTS `NOTES` ( `TITLE` TEXT NOT NULL, `CONTENT` TEXT NOT NULL, `NOTIFY` INTEGER NOT NULL, `FOLDERID` INTEGER, `CREATEDTIME` DATE NOT NULL, `UPDATEDTIME` DATE NOT NULL, `ID` INTEGER PRIMARY NOT[*] NULL, FOREIGN KEY(`FOLDERID`) REFERENCES `FOLDER`(`ID`) ON UPDATE NO ACTION ON DELETE SET NULL )"; expected "KEY"; SQL statement:
CREATE TABLE IF NOT EXISTS `notes` ( `title` TEXT NOT NULL, `content` TEXT NOT NULL, `notify` INTEGER NOT NULL, `folderId` INTEGER, `createdTime` DATE NOT NULL, `updatedTime` DATE NOT NULL, `id` INTEGER PRIMARY NOT NULL, FOREIGN KEY(`folderId`) REFERENCES `Folder`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL ) [42001-200]
2022-03-20 17:11:40 jdbc[3]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Syntax error in SQL statement "CREATE TABLE IF NOT EXISTS `TAG` ( `NAME` TEXT NOT NULL, `CREATEDTIME` DATE NOT NULL, `UPDATEDTIME` DATE NOT NULL, `ID` INTEGER PRIMARY KEY AUTOINCREMENT[*] NOT NULL )"; expected "HASH, AUTO_INCREMENT, NOT, NULL, COMMENT, CHECK, REFERENCES, ,, )"; SQL statement:
CREATE TABLE IF NOT EXISTS `Tag` ( `name` TEXT NOT NULL, `createdTime` DATE NOT NULL, `updatedTime` DATE NOT NULL, `id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL ) [42001-200]
2022-03-20 17:11:57 jdbc[3]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "NOTE" not found; SQL statement:
CREATE TABLE IF NOT EXISTS `TagNoteCrossRef` ( `tagId` INTEGER NOT NULL, `noteId` INTEGER NOT NULL, `createdTime` DATE NOT NULL, `updatedTime` DATE NOT NULL, PRIMARY KEY(`tagId`, `noteId`), FOREIGN KEY(`tagId`) REFERENCES `Tag`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE, FOREIGN KEY(`noteId`) REFERENCES `Note`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE ) [42102-200]
2022-03-20 17:18:00 jdbc[3]: exception
org.h2.jdbc.JdbcSQLSyntaxErrorException: Table "note" not found; SQL statement:
INSERT INTO "note" ("ID", "TITLE") VALUES (?, ?) [42102-200]
This diff is collapsed.
package com.cs398.NoteCloudService
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
import org.springframework.boot.runApplication
import org.springframework.data.jdbc.repository.query.Query
import org.springframework.data.relational.core.mapping.Table
import org.springframework.data.repository.CrudRepository
import org.springframework.stereotype.Service
import org.springframework.web.bind.annotation.*
@SpringBootApplication
@SpringBootApplication()
class NoteCloudServiceApplication
fun main(args: Array<String>) {
runApplication<NoteCloudServiceApplication>(*args)
}
@RestController
class NoteResource(val service: NoteService){
@GetMapping
fun index(): List <Note> = service.findNotes()
@PostMapping
fun post(@RequestBody note: Note){
service.post(note)
}
}
@Service
class NoteService(val dao: NoteRepository){
fun findNotes() = dao.findNotes()
fun post(note: Note){
dao.save(note)
}
}
@Table("Note")
data class Note(
val id: Long?,
val title: String,
val content: String,
val notify: Boolean,
val
)
//`title` TEXT NOT NULL,
//`content` TEXT NOT NULL,
//`notify` INTEGER NOT NULL,
//`folderId` INTEGER,
//`createdTime` DATE NOT NULL,
//`updatedTime` DATE NOT NULL,
//`id` INTEGER PRIMARY KEY NOT NULL,
//FOREIGN KEY(`folderId`) REFERENCES `Folder`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL
//`Folder`
//`name` TEXT NOT NULL,
//`parent` INTEGER,
//`id` INTEGER PRIMARY KEY NOT NULL,
//`createdTime` DATE NOT NULL,
//`updatedTime` DATE NOT NULL,
//FOREIGN KEY(`parent`) REFERENCES `Folder`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE
//tag
//`name` TEXT NOT NULL,
//`createdTime` DATE NOT NULL,
//`updatedTime` DATE NOT NULL,
//`id` INTEGER PRIMARY KEY NOT NULL
//CREATE TABLE IF NOT EXISTS `TagNoteCrossRef`
//(
//`tagId` INTEGER NOT NULL,
//`noteId` INTEGER NOT NULL,
//`createdTime` DATE NOT NULL,
//`updatedTime` DATE NOT NULL,
interface NoteRepository: CrudRepository<Note, String>{
@Query("select id, title from Note")
fun findNotes(): List<Note>
}
\ No newline at end of file
spring.datasource.driver-class-name=org.h2.Driver
spring.datasource.url=jdbc:h2:file:./data/testdb
spring.datasource.username=sa
spring.datasource.password=password
spring.datasource.schema=classpath:sql/schema.sql
spring.datasource.initialization-mode=always
server.port=8080
logging.file.name = myapp.log
\ No newline at end of file
......@@ -6,25 +6,25 @@ CREATE TABLE IF NOT EXISTS `Note`
`folderId` INTEGER,
`createdTime` DATE NOT NULL,
`updatedTime` DATE NOT NULL,
`id` INTEGER NOT NULL,
`id` INTEGER PRIMARY KEY NOT NULL,
FOREIGN KEY(`folderId`) REFERENCES `Folder`(`id`) ON UPDATE NO ACTION ON DELETE SET NULL
)
);
CREATE TABLE IF NOT EXISTS `Folder`
(
`name` TEXT NOT NULL,
`parent` INTEGER,
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
`id` INTEGER PRIMARY KEY NOT NULL,
`createdTime` DATE NOT NULL,
`updatedTime` DATE NOT NULL,
FOREIGN KEY(`parent`) REFERENCES `Folder`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE
)
);
CREATE TABLE IF NOT EXISTS `Tag`
(
`name` TEXT NOT NULL,
`createdTime` DATE NOT NULL,
`updatedTime` DATE NOT NULL,
`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL
)
`id` INTEGER PRIMARY KEY NOT NULL
);
CREATE TABLE IF NOT EXISTS `TagNoteCrossRef`
(
`tagId` INTEGER NOT NULL,
......@@ -34,4 +34,4 @@ CREATE TABLE IF NOT EXISTS `TagNoteCrossRef`
PRIMARY KEY(`tagId`, `noteId`),
FOREIGN KEY(`tagId`) REFERENCES `Tag`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE,
FOREIGN KEY(`noteId`) REFERENCES `Note`(`id`) ON UPDATE NO ACTION ON DELETE CASCADE
)
\ No newline at end of file
);
\ No newline at end of file
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