Things are stable enought to start.

This commit is contained in:
aminecmi 2022-09-30 15:57:03 +02:00
parent 0e1d0ca588
commit 1b8e514476
20 changed files with 418 additions and 4 deletions

1
.idea/.name Normal file
View File

@ -0,0 +1 @@
cvApi

View File

@ -1,10 +1,12 @@
import org.jetbrains.kotlin.gradle.tasks.KotlinCompile
plugins {
id("com.squareup.sqldelight")
kotlin("jvm") version "1.7.10"
}
group = "fr.louveau-amine"
group = "fr.louveauAmine"
version = "1.0-SNAPSHOT"
repositories {
@ -15,6 +17,7 @@ dependencies {
testImplementation(kotlin("test"))
implementation("io.javalin:javalin:4.6.4")
implementation("org.slf4j:slf4j-simple:2.0.1")
implementation("com.squareup.sqldelight:sqlite-driver:1.5.3")
}
tasks.test {
@ -23,4 +26,11 @@ tasks.test {
tasks.withType<KotlinCompile> {
kotlinOptions.jvmTarget = "1.8"
}
sqldelight {
database("CVApiDB") {
packageName = "fr.louveauAmine.cvApi.dao"
sourceFolders = listOf("sqldelight")
}
}

View File

@ -1,3 +1,20 @@
pluginManagement {
repositories {
mavenLocal()
mavenCentral()
jcenter()
google()
gradlePluginPortal()
}
rootProject.name = "cv-api"
resolutionStrategy {
eachPlugin {
if (requested.id.id == "com.squareup.sqldelight") {
useModule("com.squareup.sqldelight:gradle-plugin:1.5.3")
}
}
}
}
rootProject.name = "cvApi"

View File

@ -0,0 +1,27 @@
package controller
import io.javalin.apibuilder.CrudHandler
import io.javalin.http.Context
class EducationYearController : CrudHandler {
override fun create(ctx: Context) {
TODO("Not yet implemented")
}
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")
}
}

View File

@ -0,0 +1,27 @@
package controller
import io.javalin.apibuilder.CrudHandler
import io.javalin.http.Context
class InterestController : CrudHandler {
override fun create(ctx: Context) {
TODO("Not yet implemented")
}
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")
}
}

View File

@ -0,0 +1,27 @@
package controller
import io.javalin.apibuilder.CrudHandler
import io.javalin.http.Context
class JobController : CrudHandler {
override fun create(ctx: Context) {
TODO("Not yet implemented")
}
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")
}
}

View File

@ -0,0 +1,27 @@
package controller
import io.javalin.apibuilder.CrudHandler
import io.javalin.http.Context
class LanguageController : CrudHandler {
override fun create(ctx: Context) {
TODO("Not yet implemented")
}
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")
}
}

View File

@ -0,0 +1,7 @@
package controller
class MeController {
fun getMe() {
TODO("Not yet implemented")
}
}

View File

@ -0,0 +1,27 @@
package controller
import io.javalin.apibuilder.CrudHandler
import io.javalin.http.Context
class ProfileController : CrudHandler {
override fun create(ctx: Context) {
TODO("Not yet implemented")
}
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")
}
}

View File

@ -0,0 +1,27 @@
package controller
import io.javalin.apibuilder.CrudHandler
import io.javalin.http.Context
class SideProjectController : CrudHandler {
override fun create(ctx: Context) {
TODO("Not yet implemented")
}
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")
}
}

View File

@ -0,0 +1,27 @@
package controller
import io.javalin.apibuilder.CrudHandler
import io.javalin.http.Context
class TagController : CrudHandler {
override fun create(ctx: Context) {
TODO("Not yet implemented")
}
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")
}
}

View File

@ -1,6 +1,50 @@
import com.squareup.sqldelight.db.SqlDriver
import com.squareup.sqldelight.sqlite.driver.JdbcSqliteDriver
import controller.*
import fr.louveauAmine.cvApi.dao.CVApiDB
import fr.louveauAmine.cvApi.dao.PROFILE
import io.javalin.Javalin
import io.javalin.apibuilder.ApiBuilder
import io.javalin.core.security.RouteRole
enum class ApiRole : RouteRole { PUBLIC, BASIC_AUTHED }
fun main() {
val app = Javalin.create().start(7070)
app.get("/") { ctx -> ctx.result("Hello World") }
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()
val isBasicAuthed = auth == System.getenv("LDC_AUTH")
when {
permittedRoles.contains(ApiRole.PUBLIC) -> handler.handle(ctx)
permittedRoles.contains(ApiRole.BASIC_AUTHED) && isBasicAuthed -> handler.handle(ctx)
else -> ctx.status(401).json("Unauthorized")
}
}
}.start(7070)
app.routes {
ApiBuilder.path("api") {
ApiBuilder.get("me", {
MeController().getMe()
}, 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)
}
}
}

View File

@ -0,0 +1,17 @@
CREATE TABLE 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`);
educationYears:
SELECT * FROM EDUCATIONYEAR;
insertEducationYear:
INSERT OR REPLACE INTO EDUCATIONYEAR VALUES ?;
deleteEducationYear:
DELETE FROM EDUCATIONYEAR WHERE `endDate` = ? AND `school` = ?;

View File

@ -0,0 +1,16 @@
CREATE TABLE INTEREST (
`theme` TEXT NOT NULL,
`description` TEXT NOT NULL,
PRIMARY KEY (`theme`)
);
CREATE INDEX interest_key ON INTEREST(`theme`);
interests:
SELECT * FROM INTEREST;
insertInterest:
INSERT OR REPLACE INTO INTEREST VALUES ?;
deleteInterest:
DELETE FROM INTEREST WHERE `theme` = ?;

View File

@ -0,0 +1,19 @@
CREATE TABLE JOB (
`jobTitle` TEXT NOT NULL,
`start` TEXT NOT NULL,
`end` TEXT NOT NULL,
`company` TEXT NOT NULL,
`tasks` TEXT NOT NULL,
PRIMARY KEY (`start`, `end`, `company`)
);
CREATE INDEX job_index ON JOB(`start`, `end`, `company`);
jobs:
SELECT * FROM JOB;
insertJob:
INSERT OR REPLACE INTO JOB VALUES ?;
deleteJob:
DELETE FROM JOB WHERE `start` = ? AND `end` = ? AND `company` = ?;

View File

@ -0,0 +1,16 @@
CREATE TABLE LANGUAGE (
`lang` TEXT NOT NULL,
`level` TEXT NOT NULL,
PRIMARY KEY(`lang`)
);
CREATE INDEX lang_lang ON LANGUAGE(`lang`);
langs:
SELECT * FROM LANGUAGE;
insertLang:
INSERT OR REPLACE INTO LANGUAGE VALUES ?;
deleteLang:
DELETE FROM LANGUAGE WHERE `lang` = ?;

View File

@ -0,0 +1,16 @@
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` = ?;

View File

@ -0,0 +1,22 @@
CREATE TABLE PROFILE (
`name` TEXT NOT NULL,
`title` TEXT NOT NULL,
`quote` TEXT NOT NULL,
`picture` TEXT NOT NULL,
`email` TEXT,
`phone` TEXT,
`linkedin` TEXT,
`source` TEXT,
PRIMARY KEY (`name`)
);
CREATE INDEX profile_name ON PROFILE(`name`);
profiles:
SELECT * FROM PROFILE;
insertProfile:
INSERT OR REPLACE INTO PROFILE VALUES ?;
deleteProfile:
DELETE FROM PROFILE WHERE `name` = ?;

View File

@ -0,0 +1,23 @@
CREATE TABLE SIDEPROJECT (
`description` TEXT NOT NULL,
`title` TEXT,
`url` TEXT,
`category` TEXT NOT NULL ,
PRIMARY KEY (`description`, `title`, `url`, `category`)
);
CREATE INDEX sideproject_index ON SIDEPROJECT(`description`, `title`, `url`, `category`);
sideProjects:
SELECT * FROM SIDEPROJECT;
sideProjectsByCategory:
SELECT * FROM SIDEPROJECT
GROUP BY `category`
ORDER BY COUNT(`category`) DESC;
insertSideProject:
INSERT OR REPLACE INTO SIDEPROJECT VALUES ?;
deleteSideProject:
DELETE FROM SIDEPROJECT WHERE `description` = ? AND `category` = ?;

View File

@ -0,0 +1,17 @@
CREATE TABLE TAG (
`name` TEXT NOT NULL,
`workThing` INTEGER AS Boolean DEFAULT 1 NOT NULL,
`category` TEXT NOT NULL,
PRIMARY KEY (`name`)
);
CREATE INDEX tag_name ON TAG(`name`);
tags:
SELECT * FROM TAG;
insertTag:
INSERT OR REPLACE INTO TAG VALUES ?;
deleteTag:
DELETE FROM TAG WHERE `name` = ? AND `category` = ?;