-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7c8c8da
commit 1cd5b89
Showing
37 changed files
with
1,205 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
7 changes: 7 additions & 0 deletions
7
...monMain/kotlin/me/nathanfallet/groupeminaste/controllers/dashboard/DashboardController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package me.nathanfallet.groupeminaste.controllers.dashboard | ||
|
||
class DashboardController : IDashboardController { | ||
|
||
override suspend fun dashboard() {} | ||
|
||
} |
19 changes: 19 additions & 0 deletions
19
.../commonMain/kotlin/me/nathanfallet/groupeminaste/controllers/dashboard/DashboardRouter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package me.nathanfallet.groupeminaste.controllers.dashboard | ||
|
||
import me.nathanfallet.groupeminaste.controllers.models.AdminUnitRouter | ||
import me.nathanfallet.groupeminaste.usecases.web.IGetAdminMenuForCallUseCase | ||
import me.nathanfallet.ktorx.usecases.localization.IGetLocaleForCallUseCase | ||
import me.nathanfallet.usecases.localization.ITranslateUseCase | ||
|
||
class DashboardRouter( | ||
controller: IDashboardController, | ||
getLocaleForCallUseCase: IGetLocaleForCallUseCase, | ||
translateUseCase: ITranslateUseCase, | ||
getAdminMenuForCallUseCase: IGetAdminMenuForCallUseCase, | ||
) : AdminUnitRouter( | ||
controller, | ||
IDashboardController::class, | ||
getLocaleForCallUseCase, | ||
translateUseCase, | ||
getAdminMenuForCallUseCase | ||
) |
13 changes: 13 additions & 0 deletions
13
...onMain/kotlin/me/nathanfallet/groupeminaste/controllers/dashboard/IDashboardController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package me.nathanfallet.groupeminaste.controllers.dashboard | ||
|
||
import me.nathanfallet.ktorx.controllers.IUnitController | ||
import me.nathanfallet.ktorx.models.annotations.AdminTemplateMapping | ||
import me.nathanfallet.ktorx.models.annotations.Path | ||
|
||
interface IDashboardController : IUnitController { | ||
|
||
@AdminTemplateMapping("admin/dashboard.ftl") | ||
@Path("GET", "/") | ||
suspend fun dashboard() | ||
|
||
} |
57 changes: 57 additions & 0 deletions
57
...mmonMain/kotlin/me/nathanfallet/groupeminaste/controllers/models/AdminChildModelRouter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,57 @@ | ||
package me.nathanfallet.groupeminaste.controllers.models | ||
|
||
import io.ktor.server.freemarker.* | ||
import io.ktor.util.reflect.* | ||
import me.nathanfallet.groupeminaste.usecases.web.IGetAdminMenuForCallUseCase | ||
import me.nathanfallet.ktorx.controllers.IChildModelController | ||
import me.nathanfallet.ktorx.routers.IChildModelRouter | ||
import me.nathanfallet.ktorx.routers.admin.LocalizedAdminChildModelRouter | ||
import me.nathanfallet.ktorx.usecases.localization.IGetLocaleForCallUseCase | ||
import me.nathanfallet.usecases.localization.ITranslateUseCase | ||
import me.nathanfallet.usecases.models.IChildModel | ||
import me.nathanfallet.usecases.models.annotations.PayloadKey | ||
import kotlin.reflect.KClass | ||
|
||
open class AdminChildModelRouter<Model : IChildModel<Id, CreatePayload, UpdatePayload, ParentId>, Id, CreatePayload : Any, UpdatePayload : Any, ParentModel : IChildModel<ParentId, *, *, *>, ParentId>( | ||
modelTypeInfo: TypeInfo, | ||
createPayloadTypeInfo: TypeInfo, | ||
updatePayloadTypeInfo: TypeInfo, | ||
controller: IChildModelController<Model, Id, CreatePayload, UpdatePayload, ParentModel, ParentId>, | ||
controllerClass: KClass<out IChildModelController<Model, Id, CreatePayload, UpdatePayload, ParentModel, ParentId>>, | ||
parentRouter: IChildModelRouter<ParentModel, ParentId, *, *, *, *>?, | ||
getLocaleForCallUseCase: IGetLocaleForCallUseCase, | ||
translateUseCase: ITranslateUseCase, | ||
getAdminMenuForCallUseCase: IGetAdminMenuForCallUseCase, | ||
route: String? = null, | ||
id: String? = null, | ||
) : LocalizedAdminChildModelRouter<Model, Id, CreatePayload, UpdatePayload, ParentModel, ParentId>( | ||
modelTypeInfo, | ||
createPayloadTypeInfo, | ||
updatePayloadTypeInfo, | ||
controller, | ||
controllerClass, | ||
parentRouter, | ||
{ template, model -> | ||
if (template == "root/error.ftl") respondTemplate(template, model) | ||
else respondTemplate( | ||
template, model + mapOf( | ||
"title" to translateUseCase( | ||
getLocaleForCallUseCase(this), | ||
((model["route"] as String).takeIf { it.isNotEmpty() } ?: "dashboard").let { "admin_menu_$it" } | ||
), | ||
"menu" to getAdminMenuForCallUseCase(this), | ||
"flatpickr" to ((model["keys"] as? List<*>)?.any { (it as? PayloadKey)?.type == "date" } == true), | ||
) | ||
) | ||
}, | ||
getLocaleForCallUseCase, | ||
"root/error.ftl", | ||
"/auth/login?redirect={path}", | ||
"admin/models/list.ftl", | ||
null, | ||
"admin/models/form.ftl", | ||
"admin/models/form.ftl", | ||
"admin/models/delete.ftl", | ||
route, | ||
id, | ||
) |
36 changes: 36 additions & 0 deletions
36
...rc/commonMain/kotlin/me/nathanfallet/groupeminaste/controllers/models/AdminModelRouter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
package me.nathanfallet.groupeminaste.controllers.models | ||
|
||
import io.ktor.util.reflect.* | ||
import me.nathanfallet.groupeminaste.usecases.web.IGetAdminMenuForCallUseCase | ||
import me.nathanfallet.ktorx.controllers.IModelController | ||
import me.nathanfallet.ktorx.routers.IModelRouter | ||
import me.nathanfallet.ktorx.usecases.localization.IGetLocaleForCallUseCase | ||
import me.nathanfallet.usecases.localization.ITranslateUseCase | ||
import me.nathanfallet.usecases.models.IModel | ||
import me.nathanfallet.usecases.models.UnitModel | ||
import kotlin.reflect.KClass | ||
|
||
open class AdminModelRouter<Model : IModel<Id, CreatePayload, UpdatePayload>, Id, CreatePayload : Any, UpdatePayload : Any>( | ||
modelTypeInfo: TypeInfo, | ||
createPayloadTypeInfo: TypeInfo, | ||
updatePayloadTypeInfo: TypeInfo, | ||
controller: IModelController<Model, Id, CreatePayload, UpdatePayload>, | ||
controllerClass: KClass<out IModelController<Model, Id, CreatePayload, UpdatePayload>>, | ||
getLocaleForCallUseCase: IGetLocaleForCallUseCase, | ||
translateUseCase: ITranslateUseCase, | ||
getAdminMenuForCallUseCase: IGetAdminMenuForCallUseCase, | ||
route: String? = null, | ||
id: String? = null, | ||
) : AdminChildModelRouter<Model, Id, CreatePayload, UpdatePayload, UnitModel, Unit>( | ||
modelTypeInfo, | ||
createPayloadTypeInfo, | ||
updatePayloadTypeInfo, | ||
controller, | ||
controllerClass, | ||
null, | ||
getLocaleForCallUseCase, | ||
translateUseCase, | ||
getAdminMenuForCallUseCase, | ||
route, | ||
id, | ||
), IModelRouter<Model, Id, CreatePayload, UpdatePayload> |
29 changes: 29 additions & 0 deletions
29
...src/commonMain/kotlin/me/nathanfallet/groupeminaste/controllers/models/AdminUnitRouter.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package me.nathanfallet.groupeminaste.controllers.models | ||
|
||
import io.ktor.util.reflect.* | ||
import me.nathanfallet.groupeminaste.usecases.web.IGetAdminMenuForCallUseCase | ||
import me.nathanfallet.ktorx.controllers.IUnitController | ||
import me.nathanfallet.ktorx.routers.IUnitRouter | ||
import me.nathanfallet.ktorx.usecases.localization.IGetLocaleForCallUseCase | ||
import me.nathanfallet.usecases.localization.ITranslateUseCase | ||
import me.nathanfallet.usecases.models.UnitModel | ||
import kotlin.reflect.KClass | ||
|
||
open class AdminUnitRouter( | ||
controller: IUnitController, | ||
controllerClass: KClass<out IUnitController>, | ||
getLocaleForCallUseCase: IGetLocaleForCallUseCase, | ||
translateUseCase: ITranslateUseCase, | ||
getAdminMenuForCallUseCase: IGetAdminMenuForCallUseCase, | ||
route: String? = null, | ||
) : AdminModelRouter<UnitModel, Unit, Unit, Unit>( | ||
typeInfo<UnitModel>(), | ||
typeInfo<Unit>(), | ||
typeInfo<Unit>(), | ||
controller, | ||
controllerClass, | ||
getLocaleForCallUseCase, | ||
translateUseCase, | ||
getAdminMenuForCallUseCase, | ||
route ?: "", | ||
), IUnitRouter |
40 changes: 36 additions & 4 deletions
40
...mmonMain/kotlin/me/nathanfallet/groupeminaste/controllers/projects/IProjectsController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,53 @@ | ||
package me.nathanfallet.groupeminaste.controllers.projects | ||
|
||
import io.ktor.server.application.* | ||
import me.nathanfallet.groupeminaste.models.projects.Project | ||
import me.nathanfallet.groupeminaste.models.projects.ProjectPayload | ||
import me.nathanfallet.ktorx.controllers.IModelController | ||
import me.nathanfallet.ktorx.models.annotations.APIMapping | ||
import me.nathanfallet.ktorx.models.annotations.ListModelPath | ||
import me.nathanfallet.ktorx.models.annotations.Path | ||
import me.nathanfallet.ktorx.models.annotations.TemplateMapping | ||
import me.nathanfallet.ktorx.models.annotations.* | ||
|
||
interface IProjectsController : IModelController<Project, String, ProjectPayload, ProjectPayload> { | ||
|
||
@APIMapping | ||
@AdminTemplateMapping | ||
@ListModelPath | ||
suspend fun list(): List<Project> | ||
|
||
@TemplateMapping("public/projects/list.ftl") | ||
@Path("GET", "/") | ||
suspend fun listTemplate(): Map<String, Any> | ||
|
||
@APIMapping | ||
@GetModelPath | ||
@DocumentedError(404, "projects_not_found") | ||
suspend fun get(call: ApplicationCall, @Id id: String): Project | ||
|
||
@TemplateMapping("public/projects/details.ftl") | ||
@Path("GET", "/{projectId}") | ||
suspend fun details(call: ApplicationCall, @Id id: String): Map<String, Any> | ||
|
||
@APIMapping | ||
@CreateModelPath | ||
@AdminTemplateMapping | ||
@DocumentedError(401, "auth_invalid_credentials") | ||
@DocumentedError(500, "error_internal") | ||
suspend fun create(call: ApplicationCall, @Payload payload: ProjectPayload): Project | ||
|
||
@APIMapping | ||
@UpdateModelPath | ||
@AdminTemplateMapping | ||
@DocumentedError(401, "auth_invalid_credentials") | ||
@DocumentedError(404, "projects_not_found") | ||
@DocumentedError(500, "error_internal") | ||
suspend fun update(call: ApplicationCall, @Id id: String, @Payload payload: ProjectPayload): Project | ||
|
||
@APIMapping | ||
@DeleteModelPath | ||
@AdminTemplateMapping | ||
@DocumentedType(Project::class) | ||
@DocumentedError(401, "auth_invalid_credentials") | ||
@DocumentedError(404, "projects_not_found") | ||
@DocumentedError(500, "error_internal") | ||
suspend fun delete(call: ApplicationCall, @Id id: String) | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
...end/src/commonMain/kotlin/me/nathanfallet/groupeminaste/database/projects/ProjectLinks.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package me.nathanfallet.groupeminaste.database.projects | ||
|
||
import me.nathanfallet.groupeminaste.database.users.Users | ||
import me.nathanfallet.groupeminaste.extensions.generateId | ||
import me.nathanfallet.groupeminaste.models.projects.ProjectLink | ||
import org.jetbrains.exposed.sql.ResultRow | ||
import org.jetbrains.exposed.sql.Table | ||
import org.jetbrains.exposed.sql.selectAll | ||
|
||
object ProjectLinks : Table() { | ||
|
||
val id = varchar("id", 32) | ||
val projectId = varchar("project_id", 32).index() | ||
val name = varchar("name", 255) | ||
val url = text("url") | ||
|
||
override val primaryKey = PrimaryKey(Users.id) | ||
|
||
fun generateId(): String { | ||
val candidate = String.generateId() | ||
return if (selectAll().where { id eq candidate }.count() > 0) generateId() else candidate | ||
} | ||
|
||
fun toProjectLink( | ||
row: ResultRow, | ||
) = ProjectLink( | ||
row[id], | ||
row[projectId], | ||
row[name], | ||
row[url] | ||
) | ||
|
||
} |
Oops, something went wrong.