From 0cc5b60b51c77538163ee73602ed1966185bc1fb Mon Sep 17 00:00:00 2001 From: eve00 <64850924+eve00@users.noreply.github.com> Date: Tue, 30 Jan 2024 01:51:38 +0900 Subject: [PATCH 1/4] =?UTF-8?q?=E3=82=AF=E3=83=A9=E3=82=B9=E5=9B=B3?= =?UTF-8?q?=E3=81=AE=E5=AE=9F=E8=A3=85?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/main/kotlin/latestModel/Application.kt | 33 +++++++++++ src/main/kotlin/latestModel/Course.kt | 9 +++ src/main/kotlin/latestModel/CourseManager.kt | 18 ++++++ src/main/kotlin/latestModel/CourseSchedule.kt | 56 +++++++++++++++++++ src/main/kotlin/latestModel/Student.kt | 5 ++ 5 files changed, 121 insertions(+) create mode 100644 src/main/kotlin/latestModel/Application.kt create mode 100644 src/main/kotlin/latestModel/Course.kt create mode 100644 src/main/kotlin/latestModel/CourseManager.kt create mode 100644 src/main/kotlin/latestModel/CourseSchedule.kt create mode 100644 src/main/kotlin/latestModel/Student.kt diff --git a/src/main/kotlin/latestModel/Application.kt b/src/main/kotlin/latestModel/Application.kt new file mode 100644 index 0000000..f1527dc --- /dev/null +++ b/src/main/kotlin/latestModel/Application.kt @@ -0,0 +1,33 @@ +package latestModel + + +/*システムで扱うクラス*/ +class Application( + val id: String, + val student: Student, + val course: Course, + private var status: Status, +) { + fun getStatus() = status + fun markAsRegistered() { + status = Status.REGISTERED + } + + fun markAsRejected() { + status = Status.REJECTED + } +} + +enum class Status { + NOT_REGISTERED, + REGISTERED, + REJECTED +} + +/*永続化するデータのクラス*/ +class ApplicationData( + val id: String, + val studentId: String, + val courseId: String, + private var status: Status, +) \ No newline at end of file diff --git a/src/main/kotlin/latestModel/Course.kt b/src/main/kotlin/latestModel/Course.kt new file mode 100644 index 0000000..c18699d --- /dev/null +++ b/src/main/kotlin/latestModel/Course.kt @@ -0,0 +1,9 @@ +package latestModel + +class Course( + val id: String, + val credit: Int, + val capacity: Int, + val time:List +) { +} \ No newline at end of file diff --git a/src/main/kotlin/latestModel/CourseManager.kt b/src/main/kotlin/latestModel/CourseManager.kt new file mode 100644 index 0000000..4d53ac9 --- /dev/null +++ b/src/main/kotlin/latestModel/CourseManager.kt @@ -0,0 +1,18 @@ +package latestModel + +class CourseManager( + val course: Course, + val applications:List +) { + fun canApplyAsFirstserve():Boolean = true + + fun selectApplications(){ + /*落選したApplicationをRejected状態にする*/ + applications.subList(0,3).forEach { it.markAsRejected() } + } + + fun registerMembers(){ + /*登録するApplicationをRegistered状態にする*/ + applications.filterNot { it.getStatus() == Status.REJECTED }.forEach { it.markAsRegistered() } + } +} \ No newline at end of file diff --git a/src/main/kotlin/latestModel/CourseSchedule.kt b/src/main/kotlin/latestModel/CourseSchedule.kt new file mode 100644 index 0000000..2985897 --- /dev/null +++ b/src/main/kotlin/latestModel/CourseSchedule.kt @@ -0,0 +1,56 @@ +package latestModel + +import domain.entity.CourseId + +class CourseSchedule( + val courseManager: CourseManager, + private val applications: List +) { + private val MAX_CREDITS = 24 + + private fun totalCredit(): Int = applications.filterNot { it.getStatus() == Status.REJECTED }.size + + private fun checkNotOver(): Boolean = totalCredit() <= MAX_CREDITS + fun applyAsFirstService(student: Student, course: Course): Result { + if (courseManager.canApplyAsFirstserve()) { + apply(student, course) + } + return Result.failure(Exception("満員")) + } + + fun apply(student: Student, course: Course): Result { + val newApplication = createApplication(student, course) + applications + newApplication + + if (checkNotOver()) { + return Result.success(Unit) + } else { + return Result.failure(Exception("最大取得単位数を超過")) + } + } + + fun cancel(applicationId: String): Result { + val application = applications.find { it.id == applicationId } + ?: return Result.failure(Exception("存在しないid")) + + if (application.getStatus() == Status.NOT_REGISTERED) { + return Result.success(Unit) + } else { + return Result.failure(Exception("キャンセル不可")) + } + } +} + + +fun createApplication(student: Student, course: Course): Application { + return Application("applicationId", student, course, Status.NOT_REGISTERED) +} + +data class DowAndPeriod( + val dow: Dow, + val period: String +) + +enum class Dow { + Monday, Tuesday, Wednesday, Thursday, Friday +} \ No newline at end of file diff --git a/src/main/kotlin/latestModel/Student.kt b/src/main/kotlin/latestModel/Student.kt new file mode 100644 index 0000000..d93e638 --- /dev/null +++ b/src/main/kotlin/latestModel/Student.kt @@ -0,0 +1,5 @@ +package latestModel + +class Student( + val id: String +) \ No newline at end of file From 1d6a3ce0576ca1e9152f6dc4313d995038550626 Mon Sep 17 00:00:00 2001 From: eve00 <64850924+eve00@users.noreply.github.com> Date: Tue, 30 Jan 2024 04:15:58 +0900 Subject: [PATCH 2/4] =?UTF-8?q?usecase,=20datastore=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataStore/ApplicationsDataStore.kt | 14 +++++++++++++ .../dataStore/CourseMembersDataStore.kt | 8 +++++++ .../latestModel/dataStore/StudentDataStore.kt | 4 ++++ src/main/kotlin/latestModel/useCase/apply.kt | 21 +++++++++++++++++++ .../latestModel/useCase/cancelApplication.kt | 16 ++++++++++++++ .../kotlin/latestModel/useCase/register.kt | 21 +++++++++++++++++++ .../latestModel/useCase/selectAndRegister.kt | 21 +++++++++++++++++++ 7 files changed, 105 insertions(+) create mode 100644 src/main/kotlin/latestModel/dataStore/ApplicationsDataStore.kt create mode 100644 src/main/kotlin/latestModel/dataStore/CourseMembersDataStore.kt create mode 100644 src/main/kotlin/latestModel/dataStore/StudentDataStore.kt create mode 100644 src/main/kotlin/latestModel/useCase/apply.kt create mode 100644 src/main/kotlin/latestModel/useCase/cancelApplication.kt create mode 100644 src/main/kotlin/latestModel/useCase/register.kt create mode 100644 src/main/kotlin/latestModel/useCase/selectAndRegister.kt diff --git a/src/main/kotlin/latestModel/dataStore/ApplicationsDataStore.kt b/src/main/kotlin/latestModel/dataStore/ApplicationsDataStore.kt new file mode 100644 index 0000000..65857b7 --- /dev/null +++ b/src/main/kotlin/latestModel/dataStore/ApplicationsDataStore.kt @@ -0,0 +1,14 @@ +package latestModel.dataStore + +import latestModel.dataClass.Application +import latestModel.dataClass.NotRegisteredApplication + +interface ApplicationsDataStore { + fun findById(applicationId:String):Application + fun findByCourseId(courseId:String):List + fun findByStudentId(studentId:String):List + + fun save(application: Application) + fun save(applications: List) + fun delete(applicationId: String) +} \ No newline at end of file diff --git a/src/main/kotlin/latestModel/dataStore/CourseMembersDataStore.kt b/src/main/kotlin/latestModel/dataStore/CourseMembersDataStore.kt new file mode 100644 index 0000000..9288890 --- /dev/null +++ b/src/main/kotlin/latestModel/dataStore/CourseMembersDataStore.kt @@ -0,0 +1,8 @@ +package latestModel.dataStore + +import latestModel.dataClass.Student + +interface CourseMembersDataStore { + + fun save(members:List) +} \ No newline at end of file diff --git a/src/main/kotlin/latestModel/dataStore/StudentDataStore.kt b/src/main/kotlin/latestModel/dataStore/StudentDataStore.kt new file mode 100644 index 0000000..b5521d0 --- /dev/null +++ b/src/main/kotlin/latestModel/dataStore/StudentDataStore.kt @@ -0,0 +1,4 @@ +package latestModel.dataStore + +interface StudentDataStore { +} \ No newline at end of file diff --git a/src/main/kotlin/latestModel/useCase/apply.kt b/src/main/kotlin/latestModel/useCase/apply.kt new file mode 100644 index 0000000..b248787 --- /dev/null +++ b/src/main/kotlin/latestModel/useCase/apply.kt @@ -0,0 +1,21 @@ +package latestModel.useCase + +import latestModel.Course +import latestModel.Student +import latestModel.createApplication +import latestModel.dataStore.ApplicationsDataStore + + +fun apply( + student: Student, + course: Course, + dataStore: ApplicationsDataStore +){ + /*IO*/ + val applications = dataStore.findByStudentId(student.id) + + + /*IO*/ + //dataStore.save(newApplication) +} + diff --git a/src/main/kotlin/latestModel/useCase/cancelApplication.kt b/src/main/kotlin/latestModel/useCase/cancelApplication.kt new file mode 100644 index 0000000..b5a7d21 --- /dev/null +++ b/src/main/kotlin/latestModel/useCase/cancelApplication.kt @@ -0,0 +1,16 @@ +package latestModel.useCase + +import latestModel.dataStore.ApplicationsDataStore + +fun cancelApplication( + applicationId: String, + applicationsDataStore: ApplicationsDataStore +){ + /*IO*/ + val application = applicationsDataStore.findById(applicationId) + + if(true){ + /*IO*/ + applicationsDataStore.delete(application.id) + } +} \ No newline at end of file diff --git a/src/main/kotlin/latestModel/useCase/register.kt b/src/main/kotlin/latestModel/useCase/register.kt new file mode 100644 index 0000000..f3a2847 --- /dev/null +++ b/src/main/kotlin/latestModel/useCase/register.kt @@ -0,0 +1,21 @@ +package latestModel.useCase + +import latestModel.dataStore.ApplicationsDataStore +import latestModel.dataStore.CourseMembersDataStore +import latestModel.workflow.registerApplication + + +fun register( + courseId: String, + capacity: Int, + applicationsDataStore: ApplicationsDataStore, + courseMembersDataStore: CourseMembersDataStore +){ + /*IO*/ + val notRegisteredApplication = applicationsDataStore.findByCourseId(courseId) + + + /*IO*/ + //applicationsDataStore.save(registeredApplication) + //courseMembersDataStore.save(members) +} \ No newline at end of file diff --git a/src/main/kotlin/latestModel/useCase/selectAndRegister.kt b/src/main/kotlin/latestModel/useCase/selectAndRegister.kt new file mode 100644 index 0000000..9546cb8 --- /dev/null +++ b/src/main/kotlin/latestModel/useCase/selectAndRegister.kt @@ -0,0 +1,21 @@ +package latestModel.useCase + +import latestModel.dataStore.ApplicationsDataStore +import latestModel.dataStore.CourseMembersDataStore + + +fun selectAndRegister( + courseId: String, + capacity: Int, + applicationsDataStore: ApplicationsDataStore, + courseMembersDataStore: CourseMembersDataStore + +){ + /*IO*/ + val notRegisteredApplication = applicationsDataStore.findByCourseId(courseId) + + + /*IO*/ + //applicationsDataStore.save(registeredApplication + rejectedApplication) + //courseMembersDataStore.save(members) +} \ No newline at end of file From 904c063b928c43b627dc7c90ea3b06c4cf3ca688 Mon Sep 17 00:00:00 2001 From: eve00 <64850924+eve00@users.noreply.github.com> Date: Tue, 30 Jan 2024 04:15:58 +0900 Subject: [PATCH 3/4] =?UTF-8?q?usecase,=20datastore=E4=BD=9C=E6=88=90?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dataStore/ApplicationsDataStore.kt | 14 +++++++++++++ .../dataStore/CourseMembersDataStore.kt | 8 +++++++ .../latestModel/dataStore/StudentDataStore.kt | 4 ++++ src/main/kotlin/latestModel/useCase/apply.kt | 21 +++++++++++++++++++ .../latestModel/useCase/applyAsFirstserve.kt | 21 +++++++++++++++++++ .../latestModel/useCase/cancelApplication.kt | 16 ++++++++++++++ .../kotlin/latestModel/useCase/register.kt | 21 +++++++++++++++++++ .../latestModel/useCase/selectAndRegister.kt | 21 +++++++++++++++++++ 8 files changed, 126 insertions(+) create mode 100644 src/main/kotlin/latestModel/dataStore/ApplicationsDataStore.kt create mode 100644 src/main/kotlin/latestModel/dataStore/CourseMembersDataStore.kt create mode 100644 src/main/kotlin/latestModel/dataStore/StudentDataStore.kt create mode 100644 src/main/kotlin/latestModel/useCase/apply.kt create mode 100644 src/main/kotlin/latestModel/useCase/applyAsFirstserve.kt create mode 100644 src/main/kotlin/latestModel/useCase/cancelApplication.kt create mode 100644 src/main/kotlin/latestModel/useCase/register.kt create mode 100644 src/main/kotlin/latestModel/useCase/selectAndRegister.kt diff --git a/src/main/kotlin/latestModel/dataStore/ApplicationsDataStore.kt b/src/main/kotlin/latestModel/dataStore/ApplicationsDataStore.kt new file mode 100644 index 0000000..65857b7 --- /dev/null +++ b/src/main/kotlin/latestModel/dataStore/ApplicationsDataStore.kt @@ -0,0 +1,14 @@ +package latestModel.dataStore + +import latestModel.dataClass.Application +import latestModel.dataClass.NotRegisteredApplication + +interface ApplicationsDataStore { + fun findById(applicationId:String):Application + fun findByCourseId(courseId:String):List + fun findByStudentId(studentId:String):List + + fun save(application: Application) + fun save(applications: List) + fun delete(applicationId: String) +} \ No newline at end of file diff --git a/src/main/kotlin/latestModel/dataStore/CourseMembersDataStore.kt b/src/main/kotlin/latestModel/dataStore/CourseMembersDataStore.kt new file mode 100644 index 0000000..9288890 --- /dev/null +++ b/src/main/kotlin/latestModel/dataStore/CourseMembersDataStore.kt @@ -0,0 +1,8 @@ +package latestModel.dataStore + +import latestModel.dataClass.Student + +interface CourseMembersDataStore { + + fun save(members:List) +} \ No newline at end of file diff --git a/src/main/kotlin/latestModel/dataStore/StudentDataStore.kt b/src/main/kotlin/latestModel/dataStore/StudentDataStore.kt new file mode 100644 index 0000000..b5521d0 --- /dev/null +++ b/src/main/kotlin/latestModel/dataStore/StudentDataStore.kt @@ -0,0 +1,4 @@ +package latestModel.dataStore + +interface StudentDataStore { +} \ No newline at end of file diff --git a/src/main/kotlin/latestModel/useCase/apply.kt b/src/main/kotlin/latestModel/useCase/apply.kt new file mode 100644 index 0000000..b248787 --- /dev/null +++ b/src/main/kotlin/latestModel/useCase/apply.kt @@ -0,0 +1,21 @@ +package latestModel.useCase + +import latestModel.Course +import latestModel.Student +import latestModel.createApplication +import latestModel.dataStore.ApplicationsDataStore + + +fun apply( + student: Student, + course: Course, + dataStore: ApplicationsDataStore +){ + /*IO*/ + val applications = dataStore.findByStudentId(student.id) + + + /*IO*/ + //dataStore.save(newApplication) +} + diff --git a/src/main/kotlin/latestModel/useCase/applyAsFirstserve.kt b/src/main/kotlin/latestModel/useCase/applyAsFirstserve.kt new file mode 100644 index 0000000..184e4bf --- /dev/null +++ b/src/main/kotlin/latestModel/useCase/applyAsFirstserve.kt @@ -0,0 +1,21 @@ +package latestModel.useCase + +import latestModel.Course +import latestModel.Student +import latestModel.dataStore.ApplicationsDataStore + + +fun applyAsFirstServe( + student: Student, + course: Course, + dataStore: ApplicationsDataStore +) { + /*IO*/ + val applicationsOfCourse = dataStore.findByCourseId(course.id) + val applicationsOfStudent = dataStore.findByStudentId(student.id) + + + + /*IO*/ + //dataStore.save(newApplication) +} \ No newline at end of file diff --git a/src/main/kotlin/latestModel/useCase/cancelApplication.kt b/src/main/kotlin/latestModel/useCase/cancelApplication.kt new file mode 100644 index 0000000..b5a7d21 --- /dev/null +++ b/src/main/kotlin/latestModel/useCase/cancelApplication.kt @@ -0,0 +1,16 @@ +package latestModel.useCase + +import latestModel.dataStore.ApplicationsDataStore + +fun cancelApplication( + applicationId: String, + applicationsDataStore: ApplicationsDataStore +){ + /*IO*/ + val application = applicationsDataStore.findById(applicationId) + + if(true){ + /*IO*/ + applicationsDataStore.delete(application.id) + } +} \ No newline at end of file diff --git a/src/main/kotlin/latestModel/useCase/register.kt b/src/main/kotlin/latestModel/useCase/register.kt new file mode 100644 index 0000000..f3a2847 --- /dev/null +++ b/src/main/kotlin/latestModel/useCase/register.kt @@ -0,0 +1,21 @@ +package latestModel.useCase + +import latestModel.dataStore.ApplicationsDataStore +import latestModel.dataStore.CourseMembersDataStore +import latestModel.workflow.registerApplication + + +fun register( + courseId: String, + capacity: Int, + applicationsDataStore: ApplicationsDataStore, + courseMembersDataStore: CourseMembersDataStore +){ + /*IO*/ + val notRegisteredApplication = applicationsDataStore.findByCourseId(courseId) + + + /*IO*/ + //applicationsDataStore.save(registeredApplication) + //courseMembersDataStore.save(members) +} \ No newline at end of file diff --git a/src/main/kotlin/latestModel/useCase/selectAndRegister.kt b/src/main/kotlin/latestModel/useCase/selectAndRegister.kt new file mode 100644 index 0000000..9546cb8 --- /dev/null +++ b/src/main/kotlin/latestModel/useCase/selectAndRegister.kt @@ -0,0 +1,21 @@ +package latestModel.useCase + +import latestModel.dataStore.ApplicationsDataStore +import latestModel.dataStore.CourseMembersDataStore + + +fun selectAndRegister( + courseId: String, + capacity: Int, + applicationsDataStore: ApplicationsDataStore, + courseMembersDataStore: CourseMembersDataStore + +){ + /*IO*/ + val notRegisteredApplication = applicationsDataStore.findByCourseId(courseId) + + + /*IO*/ + //applicationsDataStore.save(registeredApplication + rejectedApplication) + //courseMembersDataStore.save(members) +} \ No newline at end of file From 7b4eb24ec5317acd78d1d2c0c485c9a9a5ad575d Mon Sep 17 00:00:00 2001 From: eve00 <64850924+eve00@users.noreply.github.com> Date: Tue, 13 Feb 2024 01:35:41 +0900 Subject: [PATCH 4/4] last commit --- src/main/kotlin/domain/CourseManager.kt | 6 +++ .../CourseTakingApplicationList.kt | 21 +++++----- src/main/kotlin/domain/entity/Course.kt | 10 +++-- .../domain/entity/CourseTakingApplication.kt | 34 ++++++++++++++++- .../service/CourseTakingApplicationService.kt | 3 +- .../CourseTakingApplicationServiceImpl.kt | 19 ++++++---- src/main/kotlin/latestModel/Application.kt | 18 +++------ src/main/kotlin/latestModel/Course.kt | 10 ++--- src/main/kotlin/latestModel/CourseManager.kt | 6 +-- src/main/kotlin/latestModel/CourseSchedule.kt | 26 ++----------- src/main/kotlin/latestModel/Student.kt | 2 +- .../dataStore/ApplicationsDataStore.kt | 6 +-- .../dataStore/CourseMembersDataStore.kt | 3 +- src/main/kotlin/latestModel/useCase/apply.kt | 19 ++++++---- .../latestModel/useCase/applyAsFirstserve.kt | 20 ++++++---- .../latestModel/useCase/cancelApplication.kt | 21 +++++++--- .../kotlin/latestModel/useCase/register.kt | 13 ++++--- .../latestModel/useCase/selectAndRegister.kt | 12 +++++- src/main/kotlin/webServer/Routes.kt | 38 ++++++++++--------- 19 files changed, 168 insertions(+), 119 deletions(-) create mode 100644 src/main/kotlin/domain/CourseManager.kt rename src/main/kotlin/domain/{entity => }/CourseTakingApplicationList.kt (61%) diff --git a/src/main/kotlin/domain/CourseManager.kt b/src/main/kotlin/domain/CourseManager.kt new file mode 100644 index 0000000..e3b65e0 --- /dev/null +++ b/src/main/kotlin/domain/CourseManager.kt @@ -0,0 +1,6 @@ +package domain + +import domain.entity.Application +import domain.entity.Course +import domain.entity.Status + diff --git a/src/main/kotlin/domain/entity/CourseTakingApplicationList.kt b/src/main/kotlin/domain/CourseTakingApplicationList.kt similarity index 61% rename from src/main/kotlin/domain/entity/CourseTakingApplicationList.kt rename to src/main/kotlin/domain/CourseTakingApplicationList.kt index 57b5617..d97dcc1 100644 --- a/src/main/kotlin/domain/entity/CourseTakingApplicationList.kt +++ b/src/main/kotlin/domain/CourseTakingApplicationList.kt @@ -1,4 +1,6 @@ -package domain.entity +package domain + +import domain.entity.* class CourseTakingApplicationList( private val id: StudentId, @@ -15,20 +17,17 @@ class CourseTakingApplicationList( } fun addCourseTakingApplication(courseTakingApplication: CourseTakingApplication) { - if (checkCanAdd(courseTakingApplication)){ - courseTakingApplications.add(courseTakingApplication) - updateCredits() - }else { - throw IllegalStateException("取得可能な単位数を超過しています。") - } + courseTakingApplications.add(courseTakingApplication) + updateCredits() } + fun removeCourseTakingApplication(courseTakingApplicationId: CourseTakingApplicationId) { - courseTakingApplications.remove(getCourseTakingApplicationOfId(courseTakingApplicationId)) - updateCredits() + courseTakingApplications.remove(getCourseTakingApplicationOfId(courseTakingApplicationId)) + updateCredits() } - private fun checkCanAdd(courseTakingApplication: CourseTakingApplication): Boolean { - return maxCredits >= credits + courseTakingApplication.getCourse().getCredit() + fun isWithinLimit(): Boolean { + return maxCredits >= credits } private fun updateCredits() { diff --git a/src/main/kotlin/domain/entity/Course.kt b/src/main/kotlin/domain/entity/Course.kt index f1ba6aa..c6ff70c 100644 --- a/src/main/kotlin/domain/entity/Course.kt +++ b/src/main/kotlin/domain/entity/Course.kt @@ -34,12 +34,16 @@ class Course( return max } - fun getCredit():Int { + fun getCredit(): Int { return credit } } data class DowAndPeriod( - val dow: String, + val dow: Dow, val period: String -) \ No newline at end of file +) + +enum class Dow { + Monday, Tuesday, Wednesday, Thursday, Friday +} \ No newline at end of file diff --git a/src/main/kotlin/domain/entity/CourseTakingApplication.kt b/src/main/kotlin/domain/entity/CourseTakingApplication.kt index 83caa86..e3ad115 100644 --- a/src/main/kotlin/domain/entity/CourseTakingApplication.kt +++ b/src/main/kotlin/domain/entity/CourseTakingApplication.kt @@ -28,7 +28,6 @@ class CourseTakingApplication( } /*抽選で当選する*/ - fun confirm() { if (state == State.UNCONFIRMED) state = State.CONFIRMED @@ -45,4 +44,35 @@ class CourseTakingApplication( enum class State { UNCONFIRMED, CONFIRMED, INVALIDATED -} \ No newline at end of file +} + +/*システムで扱うクラス*/ +class Application( + val id: String, + val student: Student, + val course: Course, + private var status: Status, +) { + fun getStatus() = status + fun markAsRegistered() { + status = Status.REGISTERED + } + + fun markAsRejected() { + status = Status.REJECTED + } +} + +enum class Status { + NOT_REGISTERED, + REGISTERED, + REJECTED +} + +/*永続化するデータのクラス*/ +class ApplicationData( + val id: String, + val studentId: String, + val courseId: String, + private var status: Status, +) \ No newline at end of file diff --git a/src/main/kotlin/domain/service/CourseTakingApplicationService.kt b/src/main/kotlin/domain/service/CourseTakingApplicationService.kt index 61e5463..fcff300 100644 --- a/src/main/kotlin/domain/service/CourseTakingApplicationService.kt +++ b/src/main/kotlin/domain/service/CourseTakingApplicationService.kt @@ -1,12 +1,13 @@ package domain.service +import domain.CourseTakingApplicationList import domain.entity.* interface CourseTakingApplicationService { suspend fun applyCourseTaking( courseTakingApplicationId: CourseTakingApplicationId, studentId: StudentId, courseId: CourseId - ) : CourseTakingApplicationList + ) : CourseTakingApplicationList? suspend fun cancelCourseTaking(studentId: StudentId, courseTakingApplicationId: CourseTakingApplicationId) : CourseTakingApplicationList suspend fun getCourseTakingApplications(studentId: StudentId): CourseTakingApplicationList } diff --git a/src/main/kotlin/domain/service/impl/CourseTakingApplicationServiceImpl.kt b/src/main/kotlin/domain/service/impl/CourseTakingApplicationServiceImpl.kt index e1f77b8..5a29798 100644 --- a/src/main/kotlin/domain/service/impl/CourseTakingApplicationServiceImpl.kt +++ b/src/main/kotlin/domain/service/impl/CourseTakingApplicationServiceImpl.kt @@ -3,7 +3,9 @@ package domain.service.impl import data.repository.CourseTakingApplicationsRepository import data.repository.CoursesRepository +import domain.CourseTakingApplicationList import domain.entity.* + import domain.service.CourseTakingApplicationService /* @@ -11,7 +13,7 @@ import domain.service.CourseTakingApplicationService * * */ class CourseTakingApplicationServiceImpl( - private val courseTakingApplicationRepository: CourseTakingApplicationsRepository, + private val courseTakingApplicationsRepository: CourseTakingApplicationsRepository, private val coursesRepository: CoursesRepository ) : CourseTakingApplicationService { @@ -21,14 +23,17 @@ class CourseTakingApplicationServiceImpl( courseTakingApplicationId: CourseTakingApplicationId, studentId: StudentId, courseId: CourseId - ): CourseTakingApplicationList { + ): CourseTakingApplicationList? { val courseTakingApplicationList = getCourseTakingApplicationList(studentId) val newCourseTakingApplication = createCourseTakingApplication(courseTakingApplicationId,studentId,courseId) courseTakingApplicationList.addCourseTakingApplication(newCourseTakingApplication) - courseTakingApplicationRepository.save(newCourseTakingApplication) - - return courseTakingApplicationList + if(courseTakingApplicationList.isWithinLimit()){ + courseTakingApplicationsRepository.save(newCourseTakingApplication) + return courseTakingApplicationList + }else{ + throw Exception("取得可能な単位数を超過しています。") + } } override suspend fun cancelCourseTaking( @@ -38,7 +43,7 @@ class CourseTakingApplicationServiceImpl( val courseTakingApplicationList = getCourseTakingApplicationList(studentId) courseTakingApplicationList.removeCourseTakingApplication(courseTakingApplicationId) - courseTakingApplicationRepository.delete(courseTakingApplicationId) + courseTakingApplicationsRepository.delete(courseTakingApplicationId) return courseTakingApplicationList } @@ -49,7 +54,7 @@ class CourseTakingApplicationServiceImpl( /*CourseTakingApplicationListの生成*/ private suspend fun getCourseTakingApplicationList(studentId: StudentId): CourseTakingApplicationList { - val courseTakingApplications = courseTakingApplicationRepository.findByStudentId(studentId) + val courseTakingApplications = courseTakingApplicationsRepository.findByStudentId(studentId) return CourseTakingApplicationList( studentId, courseTakingApplications.toMutableList(), diff --git a/src/main/kotlin/latestModel/Application.kt b/src/main/kotlin/latestModel/Application.kt index f1527dc..2f5ec2b 100644 --- a/src/main/kotlin/latestModel/Application.kt +++ b/src/main/kotlin/latestModel/Application.kt @@ -3,10 +3,10 @@ package latestModel /*システムで扱うクラス*/ class Application( - val id: String, - val student: Student, - val course: Course, - private var status: Status, + val id: String = "", + val student: Student = Student(), + val course: Course = Course(), + private var status: Status = Status.CREATED, ) { fun getStatus() = status fun markAsRegistered() { @@ -19,15 +19,7 @@ class Application( } enum class Status { - NOT_REGISTERED, + CREATED, REGISTERED, REJECTED } - -/*永続化するデータのクラス*/ -class ApplicationData( - val id: String, - val studentId: String, - val courseId: String, - private var status: Status, -) \ No newline at end of file diff --git a/src/main/kotlin/latestModel/Course.kt b/src/main/kotlin/latestModel/Course.kt index c18699d..0a9ffb7 100644 --- a/src/main/kotlin/latestModel/Course.kt +++ b/src/main/kotlin/latestModel/Course.kt @@ -1,9 +1,7 @@ package latestModel class Course( - val id: String, - val credit: Int, - val capacity: Int, - val time:List -) { -} \ No newline at end of file + val id: String = "", + val credit: Int = 0, + val capacity: Int = 0, +) \ No newline at end of file diff --git a/src/main/kotlin/latestModel/CourseManager.kt b/src/main/kotlin/latestModel/CourseManager.kt index 4d53ac9..6233db6 100644 --- a/src/main/kotlin/latestModel/CourseManager.kt +++ b/src/main/kotlin/latestModel/CourseManager.kt @@ -1,10 +1,10 @@ package latestModel class CourseManager( - val course: Course, - val applications:List + private val course: Course, + private val applications:List ) { - fun canApplyAsFirstserve():Boolean = true + fun canApplyWithFirstArrival():Boolean = applications.size <= course.capacity fun selectApplications(){ /*落選したApplicationをRejected状態にする*/ diff --git a/src/main/kotlin/latestModel/CourseSchedule.kt b/src/main/kotlin/latestModel/CourseSchedule.kt index 2985897..245ec2d 100644 --- a/src/main/kotlin/latestModel/CourseSchedule.kt +++ b/src/main/kotlin/latestModel/CourseSchedule.kt @@ -1,9 +1,7 @@ package latestModel -import domain.entity.CourseId class CourseSchedule( - val courseManager: CourseManager, private val applications: List ) { private val MAX_CREDITS = 24 @@ -11,12 +9,6 @@ class CourseSchedule( private fun totalCredit(): Int = applications.filterNot { it.getStatus() == Status.REJECTED }.size private fun checkNotOver(): Boolean = totalCredit() <= MAX_CREDITS - fun applyAsFirstService(student: Student, course: Course): Result { - if (courseManager.canApplyAsFirstserve()) { - apply(student, course) - } - return Result.failure(Exception("満員")) - } fun apply(student: Student, course: Course): Result { val newApplication = createApplication(student, course) @@ -33,24 +25,14 @@ class CourseSchedule( val application = applications.find { it.id == applicationId } ?: return Result.failure(Exception("存在しないid")) - if (application.getStatus() == Status.NOT_REGISTERED) { + if (application.getStatus() == Status.CREATED) { return Result.success(Unit) } else { return Result.failure(Exception("キャンセル不可")) } } -} - -fun createApplication(student: Student, course: Course): Application { - return Application("applicationId", student, course, Status.NOT_REGISTERED) + private fun createApplication(student: Student, course: Course): Application { + return Application("applicationId", student, course, Status.CREATED) + } } - -data class DowAndPeriod( - val dow: Dow, - val period: String -) - -enum class Dow { - Monday, Tuesday, Wednesday, Thursday, Friday -} \ No newline at end of file diff --git a/src/main/kotlin/latestModel/Student.kt b/src/main/kotlin/latestModel/Student.kt index d93e638..c454b31 100644 --- a/src/main/kotlin/latestModel/Student.kt +++ b/src/main/kotlin/latestModel/Student.kt @@ -1,5 +1,5 @@ package latestModel class Student( - val id: String + val id: String = "" ) \ No newline at end of file diff --git a/src/main/kotlin/latestModel/dataStore/ApplicationsDataStore.kt b/src/main/kotlin/latestModel/dataStore/ApplicationsDataStore.kt index 65857b7..7d96637 100644 --- a/src/main/kotlin/latestModel/dataStore/ApplicationsDataStore.kt +++ b/src/main/kotlin/latestModel/dataStore/ApplicationsDataStore.kt @@ -1,11 +1,11 @@ package latestModel.dataStore -import latestModel.dataClass.Application -import latestModel.dataClass.NotRegisteredApplication +import latestModel.Application + interface ApplicationsDataStore { fun findById(applicationId:String):Application - fun findByCourseId(courseId:String):List + fun findByCourseId(courseId:String):List fun findByStudentId(studentId:String):List fun save(application: Application) diff --git a/src/main/kotlin/latestModel/dataStore/CourseMembersDataStore.kt b/src/main/kotlin/latestModel/dataStore/CourseMembersDataStore.kt index 9288890..604af23 100644 --- a/src/main/kotlin/latestModel/dataStore/CourseMembersDataStore.kt +++ b/src/main/kotlin/latestModel/dataStore/CourseMembersDataStore.kt @@ -1,6 +1,7 @@ package latestModel.dataStore -import latestModel.dataClass.Student +import latestModel.Student + interface CourseMembersDataStore { diff --git a/src/main/kotlin/latestModel/useCase/apply.kt b/src/main/kotlin/latestModel/useCase/apply.kt index b248787..096a48c 100644 --- a/src/main/kotlin/latestModel/useCase/apply.kt +++ b/src/main/kotlin/latestModel/useCase/apply.kt @@ -1,19 +1,22 @@ package latestModel.useCase -import latestModel.Course -import latestModel.Student -import latestModel.createApplication +import latestModel.* import latestModel.dataStore.ApplicationsDataStore fun apply( - student: Student, - course: Course, - dataStore: ApplicationsDataStore -){ + studentId: String, + courseId: String, +) { /*IO*/ - val applications = dataStore.findByStudentId(student.id) + val applications = listOf() + val myApplications = listOf() + val course = Course(courseId) + val student = Student(studentId) + /*aggregate*/ + val courseSchedule = CourseSchedule(myApplications) + courseSchedule.apply(student, course) /*IO*/ //dataStore.save(newApplication) diff --git a/src/main/kotlin/latestModel/useCase/applyAsFirstserve.kt b/src/main/kotlin/latestModel/useCase/applyAsFirstserve.kt index 184e4bf..7d318d3 100644 --- a/src/main/kotlin/latestModel/useCase/applyAsFirstserve.kt +++ b/src/main/kotlin/latestModel/useCase/applyAsFirstserve.kt @@ -1,20 +1,26 @@ package latestModel.useCase -import latestModel.Course -import latestModel.Student +import latestModel.* import latestModel.dataStore.ApplicationsDataStore fun applyAsFirstServe( - student: Student, - course: Course, + studentId: String, + courseId: String, dataStore: ApplicationsDataStore ) { /*IO*/ - val applicationsOfCourse = dataStore.findByCourseId(course.id) - val applicationsOfStudent = dataStore.findByStudentId(student.id) - + val applications = listOf() + val myApplications = listOf() + val student = Student(studentId) + val course = Course(courseId) + /*aggregate*/ + val courseManager = CourseManager(course, applications) + val courseSchedule = CourseSchedule(myApplications) + if (courseManager.canApplyAsFirstserve()) { + courseSchedule.apply(student, course) + } /*IO*/ //dataStore.save(newApplication) diff --git a/src/main/kotlin/latestModel/useCase/cancelApplication.kt b/src/main/kotlin/latestModel/useCase/cancelApplication.kt index b5a7d21..bee64bd 100644 --- a/src/main/kotlin/latestModel/useCase/cancelApplication.kt +++ b/src/main/kotlin/latestModel/useCase/cancelApplication.kt @@ -1,16 +1,25 @@ package latestModel.useCase +import latestModel.Application +import latestModel.Course +import latestModel.CourseManager +import latestModel.CourseSchedule import latestModel.dataStore.ApplicationsDataStore fun cancelApplication( applicationId: String, applicationsDataStore: ApplicationsDataStore -){ +) { /*IO*/ - val application = applicationsDataStore.findById(applicationId) + val application = Application() + val applications = listOf() + val myApplications = listOf() + + /*aggregate*/ + val courseSchedule = CourseSchedule(CourseManager(application.course,applications),myApplications) + courseSchedule.cancel(applicationId) + + /*IO*/ + applicationsDataStore.delete(application.id) - if(true){ - /*IO*/ - applicationsDataStore.delete(application.id) - } } \ No newline at end of file diff --git a/src/main/kotlin/latestModel/useCase/register.kt b/src/main/kotlin/latestModel/useCase/register.kt index f3a2847..b71084e 100644 --- a/src/main/kotlin/latestModel/useCase/register.kt +++ b/src/main/kotlin/latestModel/useCase/register.kt @@ -1,19 +1,22 @@ package latestModel.useCase +import latestModel.Application +import latestModel.Course +import latestModel.CourseManager import latestModel.dataStore.ApplicationsDataStore import latestModel.dataStore.CourseMembersDataStore -import latestModel.workflow.registerApplication fun register( courseId: String, - capacity: Int, - applicationsDataStore: ApplicationsDataStore, - courseMembersDataStore: CourseMembersDataStore ){ /*IO*/ - val notRegisteredApplication = applicationsDataStore.findByCourseId(courseId) + val applications = listOf() + val course = Course(courseId) + /*aggregate*/ + val courseManager = CourseManager(course,applications) + courseManager.registerMembers() /*IO*/ //applicationsDataStore.save(registeredApplication) diff --git a/src/main/kotlin/latestModel/useCase/selectAndRegister.kt b/src/main/kotlin/latestModel/useCase/selectAndRegister.kt index 9546cb8..2370a44 100644 --- a/src/main/kotlin/latestModel/useCase/selectAndRegister.kt +++ b/src/main/kotlin/latestModel/useCase/selectAndRegister.kt @@ -1,19 +1,27 @@ package latestModel.useCase +import latestModel.Application +import latestModel.Course +import latestModel.CourseManager +import latestModel.CourseSchedule import latestModel.dataStore.ApplicationsDataStore import latestModel.dataStore.CourseMembersDataStore fun selectAndRegister( courseId: String, - capacity: Int, applicationsDataStore: ApplicationsDataStore, courseMembersDataStore: CourseMembersDataStore ){ /*IO*/ - val notRegisteredApplication = applicationsDataStore.findByCourseId(courseId) + val applications = listOf() + val course = Course(courseId) + /*aggregate*/ + val courseManager = CourseManager(course,applications) + courseManager.selectApplications() + courseManager.registerMembers() /*IO*/ //applicationsDataStore.save(registeredApplication + rejectedApplication) diff --git a/src/main/kotlin/webServer/Routes.kt b/src/main/kotlin/webServer/Routes.kt index d5b3f7b..0573d6d 100644 --- a/src/main/kotlin/webServer/Routes.kt +++ b/src/main/kotlin/webServer/Routes.kt @@ -75,11 +75,11 @@ class CourseTakingAndRegistration( * {studentId} * */ private fun getApplications(request: Request): Response { + /*requestからstudentIdを取得*/ + val studentId: StudentId = StudentId("someStudentId") + val result = CoroutineScope(Dispatchers.IO).async { runCatching { - /*requestからstudentIdを取得*/ - val studentId: StudentId = StudentId("someStudentId") - courseTakingApplicationService.getCourseTakingApplications(studentId) } } @@ -96,12 +96,13 @@ class CourseTakingAndRegistration( * {studentId, courseId} * */ private fun applyCourseTaking(request: Request): Response { + /*requestからuser, applicationを取得*/ + val studentId: StudentId = StudentId("someStudentId") + val courseId: CourseId = CourseId("someCourseId") + val format: String = "first-served" + val result = CoroutineScope(Dispatchers.IO).async { runCatching { - /*requestからuser, applicationを取得*/ - val studentId: StudentId = StudentId("someStudentId") - val courseId: CourseId = CourseId("someCourseId") - val format: String = "first-served" /*先着管理*/ if (firstServedManagementService.checkCanTake(courseId)) { /*申請*/ @@ -128,14 +129,14 @@ class CourseTakingAndRegistration( * {courseTakingApplicationId} * */ private fun cancelCourseTaking(request: Request): Response { + /*requestからapplicationIdを取得*/ + val courseTakingApplicationId: CourseTakingApplicationId = + CourseTakingApplicationId("someCourseTakingApplicationId") + val studentId: StudentId = + StudentId("someStudentId") + val result = CoroutineScope(Dispatchers.IO).async { runCatching { - /*requestからapplicationIdを取得*/ - val courseTakingApplicationId: CourseTakingApplicationId = - CourseTakingApplicationId("someCourseTakingApplicationId") - val studentId: StudentId = - StudentId("someStudentId") - /*申請のキャンセル*/ courseTakingApplicationService.cancelCourseTaking( studentId, @@ -153,10 +154,11 @@ class CourseTakingAndRegistration( } private fun drawAndRegisterCourseMembers(request: Request): Response { + /*requestからcourseIdを取得*/ + val courseId: CourseId = CourseId("someCourseId") + val result = CoroutineScope(Dispatchers.IO).async { runCatching { - /*requestからcourseIdを取得*/ - val courseId: CourseId = CourseId("someCourseId") /*抽選する*/ courseRegistrationService.drawingAndRegisterMembers(courseId) } @@ -172,16 +174,16 @@ class CourseTakingAndRegistration( } private fun registerCourseMembers(request: Request): Response { + /*requestからcourseIdを取得*/ + val courseId: CourseId = CourseId("someCourseId") + val result = CoroutineScope(Dispatchers.IO).async { runCatching { - /*requestからcourseIdを取得*/ - val courseId: CourseId = CourseId("someCourseId") /*抽選する*/ courseRegistrationService.registerMembers(courseId) } } - /*結果を返す*/ return if (result.getCompleted().isSuccess) { Response(OK)