Skip to content

Commit

Permalink
service実装(WIP)
Browse files Browse the repository at this point in the history
  • Loading branch information
eve00 committed Dec 20, 2023
1 parent 1cb5909 commit 7488787
Show file tree
Hide file tree
Showing 31 changed files with 347 additions and 74 deletions.
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@

# 構成

**DDD-based Hexagonal Architecture**
- Primary Port... HttpHandler
- Hub... Domain, UseCase, Service
- Secondary Port... DataSource/DataStore

## ユースケース

- 認証
- 科目を閲覧する


- 申請履歴を閲覧する
- 申請する
- 事前申請と先着申請
- キャンセルする


- 抽選する
- 登録する
1 change: 1 addition & 0 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@ dependencies {
implementation ("org.http4k:http4k-core")
implementation( "org.http4k:http4k-server-jetty:4.48.0.0")
implementation("org.jetbrains.kotlinx:kotlinx-serialization-json:1.6.1")
implementation("org.jetbrains.kotlinx:kotlinx-coroutines-core:1.7.3")


testImplementation ("org.http4k:http4k-client-jetty:4.48.0.0")
Expand Down
File renamed without changes.
Empty file.
4 changes: 0 additions & 4 deletions src/main/kotlin/data/database/Database.kt

This file was deleted.

5 changes: 5 additions & 0 deletions src/main/kotlin/data/repository/CourseMembersRepository.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package data.repository

interface CourseMembersRepository {
fun save()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package data.repository

import domain.entity.CourseTakingApplication
import domain.entity.CourseTakingApplicationId
import domain.entity.CourseTakingApplicationList
import domain.entity.StudentId

interface CourseTakingApplicationListsRepository {

/*TODO: ApplicationList生成生成責務はここが持っている*/
suspend fun findByStudentId(studentId: StudentId): CourseTakingApplicationList
suspend fun save(courseTakingApplicationList: CourseTakingApplicationList)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package data.repository

interface CourseTakingApplicationsHistoryRepository {
suspend fun findAll()
suspend fun delete()
suspend fun save()
}
5 changes: 5 additions & 0 deletions src/main/kotlin/data/repository/CoursesRepository.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package data.repository

interface CoursesRepository {
suspend fun findAll()
}
5 changes: 5 additions & 0 deletions src/main/kotlin/data/repository/StudentsRepository.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package data.repository

interface StudentsRepository {
suspend fun findById()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package data.repository.impl

import data.repository.CourseMembersRepository

class FakeCourseMembersRepository : CourseMembersRepository {
override fun save() {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package data.repository.impl

import data.repository.CourseTakingApplicationsHistoryRepository

class FakeCourseTakingApplicationsHistoryRepository : CourseTakingApplicationsHistoryRepository {
override suspend fun findAll() {
TODO("Not yet implemented")
}

override suspend fun delete() {
TODO("Not yet implemented")
}

override suspend fun save() {
TODO("Not yet implemented")
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package data.repository.impl

import data.repository.CourseTakingApplicationListsRepository
import domain.entity.CourseTakingApplicationList
import domain.entity.StudentId

class FakeCourseTakingApplicationsRepository : CourseTakingApplicationListsRepository {
override suspend fun findByStudentId(studentId: StudentId): CourseTakingApplicationList {
TODO("Not yet implemented")
}

override suspend fun save(courseTakingApplicationList: CourseTakingApplicationList) {
TODO("Not yet implemented")
}
}
9 changes: 9 additions & 0 deletions src/main/kotlin/data/repository/impl/FakeCoursesRepository.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package data.repository.impl

import data.repository.CoursesRepository

class FakeCoursesRepository : CoursesRepository {
override suspend fun findAll() {
TODO("Not yet implemented")
}
}
9 changes: 9 additions & 0 deletions src/main/kotlin/data/repository/impl/StudentsRepository.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package data.repository.impl

import data.repository.StudentsRepository

class FakeStudentsRepository : StudentsRepository {
override suspend fun findById() {
TODO("Not yet implemented")
}
}
13 changes: 0 additions & 13 deletions src/main/kotlin/domain/CourseTakingApplication.kt

This file was deleted.

7 changes: 0 additions & 7 deletions src/main/kotlin/domain/CourseTakingApplicationList.kt

This file was deleted.

11 changes: 0 additions & 11 deletions src/main/kotlin/domain/CourseTakingManager.kt

This file was deleted.

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

interface IHub {

}

class Hub: IHub {

}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package domain
package domain.entity

import domain.entity.common.Identifier

typealias CourseId = Identifier<Course, String>
class Course(
Expand All @@ -7,7 +9,7 @@ class Course(
val capacity: Int

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

fun getCapacity():Int{return capacity}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package domain
package domain.entity

class CourseList() {
fun getCourseList(): List<Course> = TODO()
Expand Down
44 changes: 44 additions & 0 deletions src/main/kotlin/domain/entity/CourseTakingApplication.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package domain.entity

import domain.entity.common.Identifier
import java.util.UUID

typealias CourseTakingApplicationId = Identifier<CourseTakingApplication, String>

class CourseTakingApplication(
id: CourseTakingApplicationId,
courseId: CourseId,
status: Status
) {
private val _id = id
private val _courseId = courseId
private var _status = status

fun getId(): CourseTakingApplicationId {
return _id
}

fun getCourseId(): CourseId {
return _courseId
}

fun getStatus(): Status {
return _status
}

/*登録される*/
fun confirm(){
_status = Status.UNCONFIRMED
}

/*抽選で落選する*/
fun invalidate(){
_status = Status.INVALIDATED
}


}

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

import java.util.*

class CourseTakingApplicationList(
studentId: StudentId
) {
private var _courseTakingApplicationList = mutableListOf<CourseTakingApplication>()
fun createCourseTakingApplication(courseTakingApplicationId: CourseTakingApplicationId, courseId: CourseId){
val newApplication = CourseTakingApplication(courseTakingApplicationId, courseId, Status.UNCONFIRMED)
_courseTakingApplicationList.add(newApplication)
}
fun deleteCourseTakingApplication(courseTakingApplicationId: CourseTakingApplicationId){
_courseTakingApplicationList.removeIf { courseTakingApplication ->
courseTakingApplication.getId() == courseTakingApplicationId
}
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
package domain
package domain.entity

import domain.entity.common.Identifier

typealias StudentId = Identifier<Student, String>

Expand All @@ -9,8 +11,8 @@ class Student(
val id: StudentId,
val name: String
): User() {
fun getId(): StudentId{
fun getId(): StudentId {
return id
}
}
class Teacher():User()
class Teacher(): User()
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package domain
package domain.entity.common


data class Identifier<EntityT, RawT>(val raw: RawT)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package domain
package domain.entity

interface CourseTakingHub{

Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package domain
package domain.service

class CourseRegistrationManager {
import domain.entity.CourseTakingApplication

interface CourseRegistrationService {

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

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

import domain.entity.CourseId
import domain.entity.CourseTakingApplicationId
import domain.entity.StudentId
import org.http4k.core.Request
interface CourseTakingApplicationService {
val firstServedState :Boolean
suspend fun applyCourseTaking(courseTakingApplicationId: CourseTakingApplicationId, studentId:StudentId, courseId: CourseId)

suspend fun cancelCourseTaking(studentId:StudentId,courseTakingApplicationId: CourseTakingApplicationId)

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
package domain.service.impl

import data.repository.CourseTakingApplicationListsRepository
import domain.entity.*
import domain.service.CourseTakingApplicationService
import org.http4k.core.Request

/*
* 履修の申請に関する機能を提供するクラス
*
* */
class CourseTakingApplicationServiceImpl(
val repository: CourseTakingApplicationListsRepository
) : CourseTakingApplicationService {

override val firstServedState: Boolean
get() = TODO("Not yet implemented")

override suspend fun applyCourseTaking(
courseTakingApplicationId: CourseTakingApplicationId,
studentId: StudentId,
courseId: CourseId
) {
val courseTakingApplicationList = getCourseTakingApplicationList(studentId)
courseTakingApplicationList.createCourseTakingApplication(courseTakingApplicationId, courseId)
repository.save(courseTakingApplicationList)
}

override suspend fun cancelCourseTaking(
studentId: StudentId,
courseTakingApplicationId: CourseTakingApplicationId
) {
val courseTakingApplicationList = getCourseTakingApplicationList(studentId)
courseTakingApplicationList.deleteCourseTakingApplication(courseTakingApplicationId)
repository.save(courseTakingApplicationList)
}

private suspend fun getCourseTakingApplicationList(studentId: StudentId): CourseTakingApplicationList {
return repository.findByStudentId(studentId)
}
}
Loading

0 comments on commit 7488787

Please sign in to comment.