From c7b0bcde49eb7558b459b0b6c421b816c7140f46 Mon Sep 17 00:00:00 2001 From: aminecmi Date: Sat, 1 Oct 2022 14:19:28 +0200 Subject: [PATCH] Working api. --- build.gradle.kts | 2 + .../controller/EducationYearController.kt | 37 ++++----- .../kotlin/controller/InterestController.kt | 32 ++++---- src/main/kotlin/controller/JobController.kt | 32 ++++---- .../kotlin/controller/LanguageController.kt | 32 ++++---- src/main/kotlin/controller/MeController.kt | 24 +++++- .../kotlin/controller/ProfileController.kt | 46 +++++++---- .../controller/SideProjectController.kt | 35 ++++---- src/main/kotlin/controller/TagController.kt | 35 ++++---- src/main/kotlin/server.kt | 81 ++++++++++++++----- src/main/kotlin/view/EducationYear.kt | 16 ++++ src/main/kotlin/view/Interest.kt | 17 ++++ src/main/kotlin/view/Job.kt | 34 ++++++++ src/main/kotlin/view/Language.kt | 14 ++++ src/main/kotlin/view/Me.kt | 3 + src/main/kotlin/view/Profile.kt | 49 +++++++++++ src/main/kotlin/view/SideProject.kt | 21 +++++ src/main/kotlin/view/Tag.kt | 19 +++++ .../louveauAmine/cvApi/dao/EducationYear.sq | 7 +- .../fr/louveauAmine/cvApi/dao/Interests.sq | 7 +- .../fr/louveauAmine/cvApi/dao/Jobs.sq | 7 +- .../fr/louveauAmine/cvApi/dao/Languages.sq | 7 +- .../fr/louveauAmine/cvApi/dao/Migrations.sq | 16 ---- .../fr/louveauAmine/cvApi/dao/Profile.sq | 11 ++- .../fr/louveauAmine/cvApi/dao/SideProjects.sq | 12 ++- .../fr/louveauAmine/cvApi/dao/Tags.sq | 9 ++- 26 files changed, 418 insertions(+), 187 deletions(-) create mode 100644 src/main/kotlin/view/EducationYear.kt create mode 100644 src/main/kotlin/view/Interest.kt create mode 100644 src/main/kotlin/view/Job.kt create mode 100644 src/main/kotlin/view/Language.kt create mode 100644 src/main/kotlin/view/Me.kt create mode 100644 src/main/kotlin/view/Profile.kt create mode 100644 src/main/kotlin/view/SideProject.kt create mode 100644 src/main/kotlin/view/Tag.kt delete mode 100644 src/main/sqldelight/fr/louveauAmine/cvApi/dao/Migrations.sq diff --git a/build.gradle.kts b/build.gradle.kts index f6a6dc4..ad51072 100644 --- a/build.gradle.kts +++ b/build.gradle.kts @@ -18,6 +18,8 @@ dependencies { implementation("io.javalin:javalin:4.6.4") implementation("org.slf4j:slf4j-simple:2.0.1") implementation("com.squareup.sqldelight:sqlite-driver:1.5.3") + implementation("com.fasterxml.jackson.core:jackson-databind:2.13.4") + implementation("com.fasterxml.jackson.module:jackson-module-kotlin:2.13.4") } tasks.test { diff --git a/src/main/kotlin/controller/EducationYearController.kt b/src/main/kotlin/controller/EducationYearController.kt index e1a17cf..35a623e 100644 --- a/src/main/kotlin/controller/EducationYearController.kt +++ b/src/main/kotlin/controller/EducationYearController.kt @@ -1,27 +1,24 @@ package controller -import io.javalin.apibuilder.CrudHandler +import fr.louveauAmine.cvApi.dao.CVApiDB import io.javalin.http.Context +import view.EducationYear +import view.toEntity +import view.toView -class EducationYearController : CrudHandler { - override fun create(ctx: Context) { - TODO("Not yet implemented") +class EducationYearController(private val database: CVApiDB) { + fun create(ctx: Context) { + database.transaction { + val bodyAsClass = ctx.bodyAsClass(EducationYear::class.java) + database.educationYearQueries.insertEducationYear(bodyAsClass.toEntity()) + val executeAsOne = + database.educationYearQueries.oneEducationYear(bodyAsClass.endDate, bodyAsClass.school).executeAsOne() + ctx.json(executeAsOne.toView()) + } } - - override fun delete(ctx: Context, resourceId: String) { - TODO("Not yet implemented") + + fun delete(ctx: Context) { + val bodyAsClass = ctx.bodyAsClass(EducationYear::class.java) + database.educationYearQueries.deleteEducationYear(bodyAsClass.endDate, bodyAsClass.school) } - - override fun getAll(ctx: Context) { - TODO("Not yet implemented") - } - - override fun getOne(ctx: Context, resourceId: String) { - TODO("Not yet implemented") - } - - override fun update(ctx: Context, resourceId: String) { - TODO("Not yet implemented") - } - } diff --git a/src/main/kotlin/controller/InterestController.kt b/src/main/kotlin/controller/InterestController.kt index d37aa8f..865fb15 100644 --- a/src/main/kotlin/controller/InterestController.kt +++ b/src/main/kotlin/controller/InterestController.kt @@ -1,27 +1,23 @@ package controller +import fr.louveauAmine.cvApi.dao.CVApiDB import io.javalin.apibuilder.CrudHandler import io.javalin.http.Context +import view.* -class InterestController : CrudHandler { - override fun create(ctx: Context) { - TODO("Not yet implemented") +class InterestController(val database: CVApiDB) { + fun create(ctx: Context) { + database.transaction { + val bodyAsClass = ctx.bodyAsClass(Interest::class.java) + database.interestsQueries.insertInterest(bodyAsClass.toEntity()) + val executeAsOne = + database.interestsQueries.oneInterest(bodyAsClass.theme).executeAsOne() + ctx.json(executeAsOne.toView()) + } } - override fun delete(ctx: Context, resourceId: String) { - TODO("Not yet implemented") + fun delete(ctx: Context) { + val bodyAsClass = ctx.bodyAsClass(DeleteInterest::class.java) + database.interestsQueries.deleteInterest(bodyAsClass.theme) } - - override fun getAll(ctx: Context) { - TODO("Not yet implemented") - } - - override fun getOne(ctx: Context, resourceId: String) { - TODO("Not yet implemented") - } - - override fun update(ctx: Context, resourceId: String) { - TODO("Not yet implemented") - } - } diff --git a/src/main/kotlin/controller/JobController.kt b/src/main/kotlin/controller/JobController.kt index 3551571..20b588a 100644 --- a/src/main/kotlin/controller/JobController.kt +++ b/src/main/kotlin/controller/JobController.kt @@ -1,27 +1,23 @@ package controller +import fr.louveauAmine.cvApi.dao.CVApiDB import io.javalin.apibuilder.CrudHandler import io.javalin.http.Context +import view.* -class JobController : CrudHandler { - override fun create(ctx: Context) { - TODO("Not yet implemented") +class JobController(val database: CVApiDB) { + fun create(ctx: Context) { + database.transaction { + val bodyAsClass = ctx.bodyAsClass(Job::class.java) + database.jobsQueries.insertJob(bodyAsClass.toEntity()) + val executeAsOne = + database.jobsQueries.oneJob(bodyAsClass.start, bodyAsClass.end, bodyAsClass.company).executeAsOne() + ctx.json(executeAsOne.toView()) + } } - override fun delete(ctx: Context, resourceId: String) { - TODO("Not yet implemented") + fun delete(ctx: Context) { + val bodyAsClass = ctx.bodyAsClass(DeleteJob::class.java) + database.jobsQueries.deleteJob(bodyAsClass.start, bodyAsClass.end, bodyAsClass.company) } - - override fun getAll(ctx: Context) { - TODO("Not yet implemented") - } - - override fun getOne(ctx: Context, resourceId: String) { - TODO("Not yet implemented") - } - - override fun update(ctx: Context, resourceId: String) { - TODO("Not yet implemented") - } - } diff --git a/src/main/kotlin/controller/LanguageController.kt b/src/main/kotlin/controller/LanguageController.kt index 7dada31..d4e53eb 100644 --- a/src/main/kotlin/controller/LanguageController.kt +++ b/src/main/kotlin/controller/LanguageController.kt @@ -1,27 +1,23 @@ package controller +import fr.louveauAmine.cvApi.dao.CVApiDB import io.javalin.apibuilder.CrudHandler import io.javalin.http.Context +import view.* -class LanguageController : CrudHandler { - override fun create(ctx: Context) { - TODO("Not yet implemented") +class LanguageController(val database: CVApiDB) { + fun create(ctx: Context) { + database.transaction { + val bodyAsClass = ctx.bodyAsClass(Language::class.java) + database.languagesQueries.insertLang(bodyAsClass.toEntity()) + val executeAsOne = + database.languagesQueries.oneLang(bodyAsClass.lang).executeAsOne() + ctx.json(executeAsOne.toView()) + } } - override fun delete(ctx: Context, resourceId: String) { - TODO("Not yet implemented") + fun delete(ctx: Context) { + val bodyAsClass = ctx.bodyAsClass(DeleteLanguage::class.java) + database.languagesQueries.deleteLang(bodyAsClass.lang) } - - override fun getAll(ctx: Context) { - TODO("Not yet implemented") - } - - override fun getOne(ctx: Context, resourceId: String) { - TODO("Not yet implemented") - } - - override fun update(ctx: Context, resourceId: String) { - TODO("Not yet implemented") - } - } diff --git a/src/main/kotlin/controller/MeController.kt b/src/main/kotlin/controller/MeController.kt index 8a6a615..d249c24 100644 --- a/src/main/kotlin/controller/MeController.kt +++ b/src/main/kotlin/controller/MeController.kt @@ -1,7 +1,23 @@ package controller -class MeController { - fun getMe() { - TODO("Not yet implemented") +import fr.louveauAmine.cvApi.dao.* +import io.javalin.http.Context +import view.* + +class MeController(private val database: CVApiDB) { + fun getMe(ctx: Context) { + + ctx.json( + Me( + profile = database.profileQueries.profiles().executeAsOne().toView(), + interests = database.interestsQueries.interests().executeAsList().map { it.toView() }, + jobs = database.jobsQueries.jobs().executeAsList().map { it.toView() }, + sideProjects = database.sideProjectsQueries.sideProjects().executeAsList().map { it.toView() }.groupBy { it.category }, + educationYears = database.educationYearQueries.educationYears().executeAsList().map { it.toView() }, + languages = database.languagesQueries.langs().executeAsList().map { it.toView() }, + tags = database.tagsQueries.tags().executeAsList().map { it.toView() } + ) + ) } -} \ No newline at end of file +} + diff --git a/src/main/kotlin/controller/ProfileController.kt b/src/main/kotlin/controller/ProfileController.kt index 575667c..a9f5ffd 100644 --- a/src/main/kotlin/controller/ProfileController.kt +++ b/src/main/kotlin/controller/ProfileController.kt @@ -1,27 +1,39 @@ package controller +import fr.louveauAmine.cvApi.dao.CVApiDB import io.javalin.apibuilder.CrudHandler import io.javalin.http.Context +import view.* -class ProfileController : CrudHandler { - override fun create(ctx: Context) { - TODO("Not yet implemented") +class ProfileController(val database: CVApiDB) { + + fun create(ctx: Context) { + database.transaction { + val bodyAsClass = ctx.bodyAsClass(Profile::class.java) + database.profileQueries.insertProfile(bodyAsClass.toEntity()) + val executeAsOne = + database.profileQueries.oneProfile(bodyAsClass.name).executeAsOne() + ctx.json(executeAsOne.toView()) + } } - override fun delete(ctx: Context, resourceId: String) { - TODO("Not yet implemented") - } - - override fun getAll(ctx: Context) { - TODO("Not yet implemented") - } - - override fun getOne(ctx: Context, resourceId: String) { - TODO("Not yet implemented") - } - - override fun update(ctx: Context, resourceId: String) { - TODO("Not yet implemented") + fun update(ctx: Context) { + val bodyAsClass = ctx.bodyAsClass(UpdateProfile::class.java) + val existing = database.profileQueries.oneProfile(bodyAsClass.name).executeAsOne() + database.profileQueries.updateProfile( + bodyAsClass.newName ?: existing.name, + bodyAsClass.title ?: existing.title, + bodyAsClass.quote ?: existing.quote, + bodyAsClass.picture ?: existing.picture, + bodyAsClass.email ?: existing.email, + bodyAsClass.phone ?: existing.phone, + bodyAsClass.linkedin ?: existing.linkedin, + bodyAsClass.source ?: existing.source, + bodyAsClass.name + ) + val executeAsOne = + database.profileQueries.oneProfile(bodyAsClass.newName ?: existing.name).executeAsOne() + ctx.json(executeAsOne.toView()) } } diff --git a/src/main/kotlin/controller/SideProjectController.kt b/src/main/kotlin/controller/SideProjectController.kt index c86ecdf..c79f329 100644 --- a/src/main/kotlin/controller/SideProjectController.kt +++ b/src/main/kotlin/controller/SideProjectController.kt @@ -1,27 +1,26 @@ package controller +import fr.louveauAmine.cvApi.dao.CVApiDB import io.javalin.apibuilder.CrudHandler import io.javalin.http.Context +import view.DeleteSideProject +import view.SideProject +import view.toEntity +import view.toView -class SideProjectController : CrudHandler { - override fun create(ctx: Context) { - TODO("Not yet implemented") +class SideProjectController(val database: CVApiDB) { + fun create(ctx: Context) { + database.transaction { + val bodyAsClass = ctx.bodyAsClass(SideProject::class.java) + database.sideProjectsQueries.insertSideProject(bodyAsClass.toEntity()) + val executeAsOne = + database.sideProjectsQueries.oneSideProject(bodyAsClass.description, bodyAsClass.category).executeAsOne() + ctx.json(executeAsOne.toView()) + } } - override fun delete(ctx: Context, resourceId: String) { - TODO("Not yet implemented") + fun delete(ctx: Context) { + val bodyAsClass = ctx.bodyAsClass(DeleteSideProject::class.java) + database.sideProjectsQueries.deleteSideProject(bodyAsClass.description, bodyAsClass.category) } - - override fun getAll(ctx: Context) { - TODO("Not yet implemented") - } - - override fun getOne(ctx: Context, resourceId: String) { - TODO("Not yet implemented") - } - - override fun update(ctx: Context, resourceId: String) { - TODO("Not yet implemented") - } - } diff --git a/src/main/kotlin/controller/TagController.kt b/src/main/kotlin/controller/TagController.kt index 1fe8e3b..f748c1b 100644 --- a/src/main/kotlin/controller/TagController.kt +++ b/src/main/kotlin/controller/TagController.kt @@ -1,27 +1,26 @@ package controller +import fr.louveauAmine.cvApi.dao.CVApiDB import io.javalin.apibuilder.CrudHandler import io.javalin.http.Context +import view.DeleteTag +import view.Tag +import view.toEntity +import view.toView -class TagController : CrudHandler { - override fun create(ctx: Context) { - TODO("Not yet implemented") +class TagController(val database: CVApiDB) { + fun create(ctx: Context) { + database.transaction { + val bodyAsClass = ctx.bodyAsClass(Tag::class.java) + database.tagsQueries.insertTag(bodyAsClass.toEntity()) + val executeAsOne = + database.tagsQueries.oneTag(bodyAsClass.name, bodyAsClass.category).executeAsOne() + ctx.json(executeAsOne.toView()) + } } - override fun delete(ctx: Context, resourceId: String) { - TODO("Not yet implemented") + fun delete(ctx: Context) { + val bodyAsClass = ctx.bodyAsClass(DeleteTag::class.java) + database.tagsQueries.deleteTag(bodyAsClass.name, bodyAsClass.category) } - - override fun getAll(ctx: Context) { - TODO("Not yet implemented") - } - - override fun getOne(ctx: Context, resourceId: String) { - TODO("Not yet implemented") - } - - override fun update(ctx: Context, resourceId: String) { - TODO("Not yet implemented") - } - } diff --git a/src/main/kotlin/server.kt b/src/main/kotlin/server.kt index e041faf..486b9fc 100644 --- a/src/main/kotlin/server.kt +++ b/src/main/kotlin/server.kt @@ -10,12 +10,7 @@ import io.javalin.core.security.RouteRole enum class ApiRole : RouteRole { PUBLIC, BASIC_AUTHED } fun main() { - val driver: SqlDriver = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY) - CVApiDB.Schema.create(driver) - val database = CVApiDB(driver) - - database.profileQueries.insertProfile(PROFILE("Amine Louveau", "truc", "tata", "prout", null, null, null, null)) - + val app = Javalin.create{ it.accessManager { handler, ctx, permittedRoles -> val auth = ctx.header("Authorization").orEmpty() @@ -29,22 +24,72 @@ fun main() { }.start(7070) - - - + val driver: SqlDriver = JdbcSqliteDriver(JdbcSqliteDriver.IN_MEMORY + "cvapi.db") + CVApiDB.Schema.create(driver) + val database = CVApiDB(driver) + + val meController = MeController(database) + val educationController = EducationYearController(database) + val interestController = InterestController(database) + val jobController = JobController(database) + val languageController = LanguageController(database) + val profileController = ProfileController(database) + val sideProjectController = SideProjectController(database) + val tagController = TagController(database) app.routes { ApiBuilder.path("api") { - ApiBuilder.get("me", { - MeController().getMe() + ApiBuilder.get("me", { ctx -> + meController.getMe(ctx) + }, ApiRole.PUBLIC) + + ApiBuilder.post("education", { ctx -> + educationController.create(ctx) + }, ApiRole.BASIC_AUTHED) + ApiBuilder.delete("education", { ctx -> + educationController.delete(ctx) }, ApiRole.BASIC_AUTHED) - ApiBuilder.crud("education/{education-id}", EducationYearController(), ApiRole.BASIC_AUTHED) - ApiBuilder.crud("interest/{interest-id}", InterestController(), ApiRole.BASIC_AUTHED) - ApiBuilder.crud("job/{job-id}", JobController(), ApiRole.BASIC_AUTHED) - ApiBuilder.crud("language/{lang-id}", LanguageController(), ApiRole.BASIC_AUTHED) - ApiBuilder.crud("profile/{profile-id}", ProfileController(), ApiRole.BASIC_AUTHED) - ApiBuilder.crud("side-project/{side-id}", SideProjectController(), ApiRole.BASIC_AUTHED) - ApiBuilder.crud("tag/{tag-id}", TagController(), ApiRole.BASIC_AUTHED) + ApiBuilder.post("interest", { ctx -> + interestController.create(ctx) + }, ApiRole.BASIC_AUTHED) + ApiBuilder.delete("interest", { ctx -> + interestController.delete(ctx) + }, ApiRole.BASIC_AUTHED) + + ApiBuilder.post("job", { ctx -> + jobController.create(ctx) + }, ApiRole.BASIC_AUTHED) + ApiBuilder.delete("job", { ctx -> + jobController.delete(ctx) + }, ApiRole.BASIC_AUTHED) + + ApiBuilder.post("language", { ctx -> + languageController.create(ctx) + }, ApiRole.BASIC_AUTHED) + ApiBuilder.delete("language", { ctx -> + languageController.delete(ctx) + }, ApiRole.BASIC_AUTHED) + + ApiBuilder.post("side-project", { ctx -> + sideProjectController.create(ctx) + }, ApiRole.BASIC_AUTHED) + ApiBuilder.delete("side-project", { ctx -> + sideProjectController.delete(ctx) + }, ApiRole.BASIC_AUTHED) + + ApiBuilder.post("tag", { ctx -> + tagController.create(ctx) + }, ApiRole.BASIC_AUTHED) + ApiBuilder.delete("tag", { ctx -> + tagController.delete(ctx) + }, ApiRole.BASIC_AUTHED) + + ApiBuilder.post("profile", { ctx -> + profileController.create(ctx) + }, ApiRole.BASIC_AUTHED) + ApiBuilder.patch("profile", { ctx -> + profileController.update(ctx) + }, ApiRole.BASIC_AUTHED) } } } \ No newline at end of file diff --git a/src/main/kotlin/view/EducationYear.kt b/src/main/kotlin/view/EducationYear.kt new file mode 100644 index 0000000..d308234 --- /dev/null +++ b/src/main/kotlin/view/EducationYear.kt @@ -0,0 +1,16 @@ +package view + +import fr.louveauAmine.cvApi.dao.EDUCATIONYEAR + +data class EducationYear( + val endDate: String, val school: String, val name: String +) + + +fun EDUCATIONYEAR.toView(): EducationYear = EducationYear( + endDate = this.endDate, school = this.school, name = this.name +) + +fun EducationYear.toEntity(): EDUCATIONYEAR = EDUCATIONYEAR( + endDate = this.endDate, school = this.school, name = this.name +) diff --git a/src/main/kotlin/view/Interest.kt b/src/main/kotlin/view/Interest.kt new file mode 100644 index 0000000..b5116e2 --- /dev/null +++ b/src/main/kotlin/view/Interest.kt @@ -0,0 +1,17 @@ +package view + +import fr.louveauAmine.cvApi.dao.INTEREST + +data class Interest( + val theme: String, + val description: String +) + +data class DeleteInterest( + val theme: String +) + + +fun INTEREST.toView(): Interest = Interest(theme = this.theme, description = this.description) + +fun Interest.toEntity(): INTEREST = INTEREST(theme = this.theme, description = this.description) \ No newline at end of file diff --git a/src/main/kotlin/view/Job.kt b/src/main/kotlin/view/Job.kt new file mode 100644 index 0000000..87c8e33 --- /dev/null +++ b/src/main/kotlin/view/Job.kt @@ -0,0 +1,34 @@ +package view + +import fr.louveauAmine.cvApi.dao.JOB + +data class Job( + val jobTitle: String, + val start: String, + val end: String, + val company: String, + val tasks: String +) + +data class DeleteJob( + val start: String, + val end: String, + val company: String +) + + +fun JOB.toView(): Job = Job( + jobTitle = this.jobTitle, + start = this.start, + end = this.end, + company = this.company, + tasks = this.tasks +) + +fun Job.toEntity(): JOB = JOB( + jobTitle = this.jobTitle, + start = this.start, + end = this.end, + company = this.company, + tasks = this.tasks +) \ No newline at end of file diff --git a/src/main/kotlin/view/Language.kt b/src/main/kotlin/view/Language.kt new file mode 100644 index 0000000..528d297 --- /dev/null +++ b/src/main/kotlin/view/Language.kt @@ -0,0 +1,14 @@ +package view + +import fr.louveauAmine.cvApi.dao.LANGUAGE + +data class Language( + val lang: String, + val level: String +) + +data class DeleteLanguage(val lang: String) + +fun LANGUAGE.toView(): Language = Language(lang = this.lang, level = this.level) + +fun Language.toEntity(): LANGUAGE = LANGUAGE(lang = this.lang, level = this.level) \ No newline at end of file diff --git a/src/main/kotlin/view/Me.kt b/src/main/kotlin/view/Me.kt new file mode 100644 index 0000000..8b966da --- /dev/null +++ b/src/main/kotlin/view/Me.kt @@ -0,0 +1,3 @@ +package view + +data class Me(val profile: Profile, val interests: List, val jobs: List, val sideProjects: Map>, val educationYears: List, val languages: List, val tags: List) diff --git a/src/main/kotlin/view/Profile.kt b/src/main/kotlin/view/Profile.kt new file mode 100644 index 0000000..23f2465 --- /dev/null +++ b/src/main/kotlin/view/Profile.kt @@ -0,0 +1,49 @@ +package view + +import fr.louveauAmine.cvApi.dao.PROFILE + +data class Profile( + val name: String, + val title: String, + val quote: String, + val picture: String, + val email: String?, + val phone: String?, + val linkedin: String?, + val source: String? +) + +data class UpdateProfile( + val name: String, + val newName: String?, + val title: String?, + val quote: String?, + val picture: String?, + val email: String?, + val phone: String?, + val linkedin: String?, + val source: String? +) + + +fun PROFILE.toView(): Profile = Profile( + name = this.name, + title = this.title, + quote = this.quote, + picture = this.picture, + email = this.email, + phone = this.phone, + linkedin = this.linkedin, + source = this.source +) + +fun Profile.toEntity(): PROFILE = PROFILE( + name = this.name, + title = this.title, + quote = this.quote, + picture = this.picture, + email = this.email, + phone = this.phone, + linkedin = this.linkedin, + source = this.source +) \ No newline at end of file diff --git a/src/main/kotlin/view/SideProject.kt b/src/main/kotlin/view/SideProject.kt new file mode 100644 index 0000000..11d51fe --- /dev/null +++ b/src/main/kotlin/view/SideProject.kt @@ -0,0 +1,21 @@ +package view + +import fr.louveauAmine.cvApi.dao.SIDEPROJECT + +data class SideProject( + val description: String, + val title: String?, + val url: String?, + val category: String +) + +data class DeleteSideProject( + val description: String, + val category: String +) + + +fun SIDEPROJECT.toView(): SideProject = + SideProject(description = this.description, title = this.title, url = this.url, category = this.category) + +fun SideProject.toEntity(): SIDEPROJECT = SIDEPROJECT(description = this.description, title = this.title, url = this.url, category = this.category) \ No newline at end of file diff --git a/src/main/kotlin/view/Tag.kt b/src/main/kotlin/view/Tag.kt new file mode 100644 index 0000000..49c7c93 --- /dev/null +++ b/src/main/kotlin/view/Tag.kt @@ -0,0 +1,19 @@ +package view + +import fr.louveauAmine.cvApi.dao.TAG + +data class Tag( + val name: String, + val workThing: Boolean, + val category: String +) + +data class DeleteTag( + val name: String, + val category: String +) + +fun TAG.toView(): Tag = Tag(name = this.name, workThing = this.workThing, category = this.category) + + +fun Tag.toEntity(): TAG = TAG(name = this.name, workThing = this.workThing, category = this.category) \ No newline at end of file diff --git a/src/main/sqldelight/fr/louveauAmine/cvApi/dao/EducationYear.sq b/src/main/sqldelight/fr/louveauAmine/cvApi/dao/EducationYear.sq index 3be66e6..b4aa458 100644 --- a/src/main/sqldelight/fr/louveauAmine/cvApi/dao/EducationYear.sq +++ b/src/main/sqldelight/fr/louveauAmine/cvApi/dao/EducationYear.sq @@ -1,15 +1,18 @@ -CREATE TABLE EDUCATIONYEAR ( +CREATE TABLE IF NOT EXISTS EDUCATIONYEAR ( `endDate` TEXT NOT NULL, `school` TEXT NOT NULL, `name` TEXT NOT NULL, PRIMARY KEY(`endDate`, `school`) ); -CREATE INDEX educationyear_date_school ON EDUCATIONYEAR(`endDate`, `school`); +CREATE INDEX IF NOT EXISTS educationyear_date_school ON EDUCATIONYEAR(`endDate`, `school`); educationYears: SELECT * FROM EDUCATIONYEAR; +oneEducationYear: +SELECT * FROM EDUCATIONYEAR WHERE `endDate` = ? AND `school` = ?; + insertEducationYear: INSERT OR REPLACE INTO EDUCATIONYEAR VALUES ?; diff --git a/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Interests.sq b/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Interests.sq index 4c9d3f0..a4c5748 100644 --- a/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Interests.sq +++ b/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Interests.sq @@ -1,14 +1,17 @@ -CREATE TABLE INTEREST ( +CREATE TABLE IF NOT EXISTS INTEREST ( `theme` TEXT NOT NULL, `description` TEXT NOT NULL, PRIMARY KEY (`theme`) ); -CREATE INDEX interest_key ON INTEREST(`theme`); +CREATE INDEX IF NOT EXISTS interest_key ON INTEREST(`theme`); interests: SELECT * FROM INTEREST; +oneInterest: +SELECT * FROM INTEREST WHERE `theme` = ?; + insertInterest: INSERT OR REPLACE INTO INTEREST VALUES ?; diff --git a/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Jobs.sq b/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Jobs.sq index aa15496..e7fd8c6 100644 --- a/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Jobs.sq +++ b/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Jobs.sq @@ -1,4 +1,4 @@ -CREATE TABLE JOB ( +CREATE TABLE IF NOT EXISTS JOB ( `jobTitle` TEXT NOT NULL, `start` TEXT NOT NULL, `end` TEXT NOT NULL, @@ -7,11 +7,14 @@ CREATE TABLE JOB ( PRIMARY KEY (`start`, `end`, `company`) ); -CREATE INDEX job_index ON JOB(`start`, `end`, `company`); +CREATE INDEX IF NOT EXISTS job_index ON JOB(`start`, `end`, `company`); jobs: SELECT * FROM JOB; +oneJob: +SELECT * FROM JOB WHERE `start` = ? AND `end` = ? AND `company` = ?; + insertJob: INSERT OR REPLACE INTO JOB VALUES ?; diff --git a/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Languages.sq b/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Languages.sq index 8928e3b..dc7703a 100644 --- a/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Languages.sq +++ b/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Languages.sq @@ -1,14 +1,17 @@ -CREATE TABLE LANGUAGE ( +CREATE TABLE IF NOT EXISTS LANGUAGE ( `lang` TEXT NOT NULL, `level` TEXT NOT NULL, PRIMARY KEY(`lang`) ); -CREATE INDEX lang_lang ON LANGUAGE(`lang`); +CREATE INDEX IF NOT EXISTS lang_lang ON LANGUAGE(`lang`); langs: SELECT * FROM LANGUAGE; +oneLang: +SELECT * FROM LANGUAGE WHERE `lang` = ?; + insertLang: INSERT OR REPLACE INTO LANGUAGE VALUES ?; diff --git a/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Migrations.sq b/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Migrations.sq deleted file mode 100644 index 1425e0d..0000000 --- a/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Migrations.sq +++ /dev/null @@ -1,16 +0,0 @@ -CREATE TABLE MIGRATION ( - `identifier` TEXT NOT NULL, - `done` INTEGER AS Boolean DEFAULT 0 NOT NULL, - PRIMARY KEY (`identifier`) -); - -CREATE INDEX migration_index ON MIGRATION(`identifier`); - -migrations: -SELECT * FROM MIGRATION; - -insertMigration: -INSERT OR REPLACE INTO MIGRATION VALUES ?; - -deleteMigration: -DELETE FROM MIGRATION WHERE `identifier` = ?; \ No newline at end of file diff --git a/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Profile.sq b/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Profile.sq index 6c66816..09086c6 100644 --- a/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Profile.sq +++ b/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Profile.sq @@ -1,4 +1,4 @@ -CREATE TABLE PROFILE ( +CREATE TABLE IF NOT EXISTS PROFILE ( `name` TEXT NOT NULL, `title` TEXT NOT NULL, `quote` TEXT NOT NULL, @@ -10,13 +10,16 @@ CREATE TABLE PROFILE ( PRIMARY KEY (`name`) ); -CREATE INDEX profile_name ON PROFILE(`name`); +CREATE INDEX IF NOT EXISTS profile_name ON PROFILE(`name`); profiles: SELECT * FROM PROFILE; +oneProfile: +SELECT * FROM PROFILE WHERE `name` = ?; + insertProfile: INSERT OR REPLACE INTO PROFILE VALUES ?; -deleteProfile: -DELETE FROM PROFILE WHERE `name` = ?; \ No newline at end of file +updateProfile: +UPDATE PROFILE SET `name` = ?, `title` = ?, `quote` = ?, `picture` = ?, `email` = ?, `phone` = ?, `linkedin` = ?, `source` = ? WHERE `name` = ?; \ No newline at end of file diff --git a/src/main/sqldelight/fr/louveauAmine/cvApi/dao/SideProjects.sq b/src/main/sqldelight/fr/louveauAmine/cvApi/dao/SideProjects.sq index 1dff7b6..bd4f506 100644 --- a/src/main/sqldelight/fr/louveauAmine/cvApi/dao/SideProjects.sq +++ b/src/main/sqldelight/fr/louveauAmine/cvApi/dao/SideProjects.sq @@ -1,20 +1,18 @@ -CREATE TABLE SIDEPROJECT ( +CREATE TABLE IF NOT EXISTS SIDEPROJECT ( `description` TEXT NOT NULL, `title` TEXT, `url` TEXT, `category` TEXT NOT NULL , - PRIMARY KEY (`description`, `title`, `url`, `category`) + PRIMARY KEY (`description`, `category`) ); -CREATE INDEX sideproject_index ON SIDEPROJECT(`description`, `title`, `url`, `category`); +CREATE INDEX IF NOT EXISTS sideproject_index ON SIDEPROJECT(`description`, `category`); sideProjects: SELECT * FROM SIDEPROJECT; -sideProjectsByCategory: -SELECT * FROM SIDEPROJECT -GROUP BY `category` -ORDER BY COUNT(`category`) DESC; +oneSideProject: +SELECT * FROM SIDEPROJECT WHERE `description` = ? AND `category` = ?; insertSideProject: INSERT OR REPLACE INTO SIDEPROJECT VALUES ?; diff --git a/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Tags.sq b/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Tags.sq index ab69b81..78394e6 100644 --- a/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Tags.sq +++ b/src/main/sqldelight/fr/louveauAmine/cvApi/dao/Tags.sq @@ -1,15 +1,18 @@ -CREATE TABLE TAG ( +CREATE TABLE IF NOT EXISTS TAG ( `name` TEXT NOT NULL, `workThing` INTEGER AS Boolean DEFAULT 1 NOT NULL, `category` TEXT NOT NULL, - PRIMARY KEY (`name`) + PRIMARY KEY (`name`, `category`) ); -CREATE INDEX tag_name ON TAG(`name`); +CREATE INDEX IF NOT EXISTS tag_name ON TAG(`name`, `category`); tags: SELECT * FROM TAG; +oneTag: +SELECT * FROM TAG WHERE `name` = ? AND `category` = ?; + insertTag: INSERT OR REPLACE INTO TAG VALUES ?;