Skip to content

Commit

Permalink
ベースを実装(WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
eve00 committed Dec 11, 2023
1 parent 5c305b3 commit 1cb5909
Show file tree
Hide file tree
Showing 18 changed files with 172 additions and 103 deletions.
8 changes: 8 additions & 0 deletions src/main/kotlin/auth/Authenticator.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package auth

interface Authenticator {

fun authenticateAs(): Boolean

fun authorize():Boolean
}
18 changes: 0 additions & 18 deletions src/main/kotlin/commands/CourseTakingApplicationCommand.kt

This file was deleted.

This file was deleted.

37 changes: 37 additions & 0 deletions src/main/kotlin/data/Repository/course.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
{
"コース": [
{
"ID": "C001",
"名前": "コンピュータサイエンス入門",
"講師": "山田太郎",
"曜日": "月曜日",
"時限": "1",
"学期": "前期",
"説明": "このコースは、コンピュータサイエンスの基本概念を紹介します。プログラミング言語の基本から始め、アルゴリズム、データ構造、ソフトウェア開発の基礎を網羅します。",
"学年": "1年",
"専攻": "コンピュータサイエンス"
},
{
"ID": "C002",
"名前": "データベース設計",
"講師": "田中花子",
"曜日": "水曜日",
"時限": "3",
"学期": "後期",
"説明": "このコースでは、データベース設計の基本を学びます。正規化、データモデリング、SQLクエリの実行などが含まれます。",
"学年": "3年",
"専攻": "情報システム"
},
{
"ID": "C003",
"名前": "ソフトウェアエンジニアリング",
"講師": "鈴木次郎",
"曜日": "金曜日",
"時限": "5",
"学期": "前期",
"説明": "このコースでは、ソフトウェアエンジニアリングの原則と実践をカバーします。ソフトウェア設計、テスト、プロジェクト管理などを理解します。",
"学年": "2年",
"専攻": "ソフトウェアエンジニアリング"
}
]
}
4 changes: 4 additions & 0 deletions src/main/kotlin/data/database/Database.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
package data.database

class Database {
}
10 changes: 0 additions & 10 deletions src/main/kotlin/domain/Application.kt

This file was deleted.

18 changes: 18 additions & 0 deletions src/main/kotlin/domain/Course.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package domain

typealias CourseId = Identifier<Course, String>
class Course(
val id: CourseId,
val name: String,
val capacity: Int

) {
fun getId():CourseId {return id}
fun getName():String {return name}

fun getCapacity():Int{return capacity}

fun updateCapacity():Nothing = TODO("Async")

suspend fun getDetail(): Nothing = TODO("Async")
}
7 changes: 7 additions & 0 deletions src/main/kotlin/domain/CourseList.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package domain

class CourseList() {
fun getCourseList(): List<Course> = TODO()


}
10 changes: 10 additions & 0 deletions src/main/kotlin/domain/CourseRegistrationManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package domain

class CourseRegistrationManager {

fun drawing(courseTakingApplicationList: List<CourseTakingApplication>): List<CourseTakingApplication>
= TODO("抽選")

fun registerMembers(courseTakingApplicationList: List<CourseTakingApplication>):Nothing =
TODO("登録する")
}
13 changes: 13 additions & 0 deletions src/main/kotlin/domain/CourseTakingApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package domain

typealias CourseTakingApplicationId = Identifier<CourseTakingApplication, String>

data class CourseTakingApplication(
val id: CourseTakingApplicationId,
val courseId: String,
val Status: Status
)

enum class Status{
UNCONFIRMED,CONFIRMED
}
7 changes: 7 additions & 0 deletions src/main/kotlin/domain/CourseTakingApplicationList.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package domain

class CourseTakingApplicationList() {
fun getCourseTakingApplicationList(userId: String): List<CourseTakingApplication> = TODO()
fun createCourseTakingApplication(application: CourseTakingApplication): Nothing = TODO()
fun deleteCourseTakingApplication(applicationId: String): Nothing = TODO()
}
11 changes: 11 additions & 0 deletions src/main/kotlin/domain/CourseTakingManager.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package domain

class CourseTakingManager {
private val FirstServedState :Boolean = TODO("先着申請に空きがあるのかどうか")

suspend fun applyCourseTaking(course:CourseId):Nothing = TODO("Async " +
"userからidを取ってくる" +
"CourseTakingApplicationを作成する(DBとの通信はListがする?)")

fun cancenCourseTaking(courseTakingApplicationId: CourseTakingApplicationId):Nothing = TODO()
}
6 changes: 6 additions & 0 deletions src/main/kotlin/domain/Identifier.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package domain


data class Identifier<EntityT, RawT>(val raw: RawT)


15 changes: 13 additions & 2 deletions src/main/kotlin/domain/User.kt
Original file line number Diff line number Diff line change
@@ -1,5 +1,16 @@
package domain

data class User (val id: String) {
typealias StudentId = Identifier<Student, String>

}


sealed class User()
class Student(
val id: StudentId,
val name: String
): User() {
fun getId(): StudentId{
return id
}
}
class Teacher():User()
12 changes: 5 additions & 7 deletions src/main/kotlin/domain/courseTakingHub.kt
Original file line number Diff line number Diff line change
@@ -1,22 +1,20 @@
package domain

import commands.CourseTakingApplicationCommand
import commands.CourseTakingApplicationCommandHandler
interface CourseTakingHub{

interface CourseTakingHub {
fun getApplicationList(user: User): List<Application>?
fun handle(command: CourseTakingApplicationCommand): CourseTakingApplicationCommand?
}

/*
実装クラス
class CourseTakingApplicationHub(
val commandHandler: CourseTakingApplicationCommandHandler
):CourseTakingHub {
override fun getApplicationList(user: User): List<Application>? {
return null
return null
}
override fun handle(command: CourseTakingApplicationCommand): CourseTakingApplicationCommand? {
return null
}
}
}*/
6 changes: 0 additions & 6 deletions src/main/kotlin/events/CourseTakingApplicationEvent.kt

This file was deleted.

24 changes: 0 additions & 24 deletions src/main/kotlin/fp/EntityEvent.kt

This file was deleted.

64 changes: 33 additions & 31 deletions src/main/kotlin/webServer/Routes.kt
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package webServer

import commands.CancelCourseTakingApplication
import commands.CreateCourseTakingApplication
import domain.Application
import domain.CourseTakingApplication
import domain.CourseTakingHub
import domain.User
import kotlinx.serialization.json.Json
import org.http4k.core.*
import org.http4k.core.body.form
import org.http4k.routing.bind
Expand All @@ -21,42 +18,53 @@ class CourseTaking(val hub: CourseTakingHub): HttpHandler {

val httpHandler = routes(
"/ping" bind Method.GET to { Response(Status.OK) },
"/application/{user}" bind Method.GET to ::getApplicationList,
"/application/{user}" bind Method.GET to ::getApplications,
"/application/{user}" bind Method.POST to ::applyCourseTaking,
"/application/{user}" bind Method.DELETE to ::cancelCourseTaking
"/application/{user}" bind Method.DELETE to ::cancelCourseTaking,
"/course" bind Method.GET to ::getCourses,
"/course/{courseId}" bind Method.GET to ::drawing,
"/course/{courseId}" bind Method.PATCH to ::updateCourseCapacity,
"/course/{courseId}" bind Method.POST to ::registerCourseMembers,
)

private fun getCourses(request: Request): Response{
TODO("履修可能な科目を返す")
}

//Request -> User -> Result -> Response
private fun getApplicationList(request: Request): Response {
return request.extractUser()
?.let { hub.getApplicationList(it) }
?.let(::convertApplicationListToJson) //TODO("convert to Json")
?.let(::toResponse)
?: Response(Status.NOT_FOUND)
private fun getApplications(request: Request): Response {
TODO()
}

//Request -> User,Application -> Result -> Response
private fun applyCourseTaking(request: Request): Response {
val user = request.extractUser()
return request.extractApplication()
?.let { CreateCourseTakingApplication(user, it) }
?.let(hub::handle)//Result噛ませたい
?.let { Response(Status.OK) }
?: Response(Status.BAD_REQUEST)
TODO()

}

//Request -> User,Application -> Result -> Response
private fun cancelCourseTaking(request: Request): Response {
val user = request.extractUser()
return request.extractApplication()
?.let { CancelCourseTakingApplication(user, it) }
?.let(hub::handle)//Result噛ませたい
?.let { Response(Status.OK) }
?: Response(Status.BAD_REQUEST)
TODO()

}

private fun drawing(request: Request): Response {
TODO()

}

private fun updateCourseCapacity(request: Request): Response {
TODO()
}

private fun registerCourseMembers(request: Request): Response {
TODO()
}



data class JsonData(val raw:String)
fun convertApplicationListToJson(list: List<Application>): JsonData {
fun convertApplicationListToJson(list: List<CourseTakingApplication>): JsonData {
/*TODO: serialize list*/
return JsonData("nothing")
}
Expand All @@ -66,11 +74,5 @@ class CourseTaking(val hub: CourseTakingHub): HttpHandler {



private fun Request.extractUser(): User = path("user").orEmpty().let(::User)
private fun Request.extractApplication(): Application? {
val id = form("applicationId") ?:return null
val course = form("course") ?: return null
return Application(id, course)
}
}

0 comments on commit 1cb5909

Please sign in to comment.