Skip to content

Commit

Permalink
#63 Added deadline field
Browse files Browse the repository at this point in the history
  • Loading branch information
vityaman committed Apr 20, 2024
1 parent 66f1396 commit 00f7be5
Show file tree
Hide file tree
Showing 9 changed files with 35 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ fun Homework.toMessage(): HomeworkMessage =
maxScore = this.maxScore.value.toInt(),
publicationMoment = this.publicationMoment,
creationMoment = this.creationMoment,
deadlineMoment = this.deadlineMoment,
)

fun Homework.Draft.toMessage(): HomeworkDraftMessage =
Expand All @@ -20,6 +21,7 @@ fun Homework.Draft.toMessage(): HomeworkDraftMessage =
description = this.description.text,
maxScore = this.maxScore.value.toInt(),
publicationMoment = this.publicationMoment,
deadlineMoment = this.deadlineMoment,
)

fun HomeworkDraftMessage.toModel(): Homework.Draft =
Expand All @@ -28,4 +30,5 @@ fun HomeworkDraftMessage.toModel(): Homework.Draft =
description = Homework.Description(this.description),
maxScore = Homework.Score(this.maxScore.toShort()),
publicationMoment = this.publicationMoment,
deadlineMoment = this.deadlineMoment,
)
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ data class Homework(
val description: Description,
val maxScore: Score,
val publicationMoment: OffsetDateTime,
val deadlineMoment: OffsetDateTime,
val creationMoment: OffsetDateTime,
) {
@JvmInline
Expand Down Expand Up @@ -66,5 +67,12 @@ data class Homework(
val description: Description,
val maxScore: Score,
val publicationMoment: OffsetDateTime,
)
val deadlineMoment: OffsetDateTime,
) {
init {
expect(publicationMoment < deadlineMoment) {
append("Homework must be published before deadline")
}
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,14 @@ class JooqHomeworkStorage(
HOMEWORK.DESCRIPTION,
HOMEWORK.MAX_SCORE,
HOMEWORK.PUBLICATION_MOMENT,
HOMEWORK.DEADLINE_MOMENT,
)
.values(
homework.title.text,
homework.description.text,
homework.maxScore.value,
homework.publicationMoment,
homework.deadlineMoment,
)
.returningResult(HOMEWORK.fields().asList())
.coerce(HOMEWORK)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,5 @@ fun HomeworkRecord.toModel(): Homework =
maxScore = Homework.Score(this.maxScore),
publicationMoment = this.publicationMoment,
creationMoment = this.creationMoment!!,
deadlineMoment = this.deadlineMoment,
)
1 change: 1 addition & 0 deletions botalka/src/main/resources/database/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ CREATE TABLE lms.homework (
description text NOT NULL,
max_score lms.score NOT NULL,
publication_moment timestamptz NOT NULL,
deadline_moment timestamptz NOT NULL,
creation_moment timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
);

Expand Down
8 changes: 8 additions & 0 deletions botalka/src/main/resources/static/openapi/api.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,11 @@ components:
format: date-time
description: A moment when this homework must be published
example: 2024-03-11T12:00:00Z
HomeworkDeadlineMoment:
type: string
format: date-time
description: A moment when is a deadline for this homework
example: 2024-03-11T12:00:00Z
CreationMoment:
type: string
format: date-time
Expand All @@ -312,11 +317,14 @@ components:
$ref: '#/components/schemas/HomeworkScore'
publication_moment:
$ref: '#/components/schemas/HomeworkPublicationMoment'
deadline_moment:
$ref: '#/components/schemas/HomeworkDeadlineMoment'
required:
- title
- description
- max_score
- publication_moment
- deadline_moment
Homework:
allOf:
- $ref: '#/components/schemas/HomeworkDraft'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package ru.vityaman.lms.botalka.api.http.endpoint

import io.kotest.matchers.collections.shouldBeUnique
import io.kotest.matchers.date.shouldBeAfter
import io.kotest.matchers.date.shouldBeBefore
import io.kotest.matchers.date.shouldHaveSameInstantAs
import io.kotest.matchers.shouldBe
import kotlinx.coroutines.async
Expand All @@ -23,24 +24,28 @@ class HomeworkApiTest(
description = "Test Homework 1 Description",
maxScore = 100,
publicationMoment = time("2024-04-01T10:15:30+03:00"),
deadlineMoment = time("2024-05-02T10:11:33+03:00"),
),
HomeworkDraftMessage(
title = "Test Homework 2",
description = "Test Homework 2 Description",
maxScore = 250,
publicationMoment = time("2024-05-01T12:00:30+03:00"),
deadlineMoment = time("2024-07-01T12:11:30+03:00")
),
HomeworkDraftMessage(
title = "Test Homework 3",
description = "Test Homework 3 Description",
maxScore = 100,
publicationMoment = time("2024-05-02T12:00:30+03:00"),
deadlineMoment = time("2024-05-03T06:11:30+03:00")
),
HomeworkDraftMessage(
title = "Test Homework 4",
description = "Test Homework 4 Description",
maxScore = 300,
publicationMoment = time("2024-05-02T12:00:30+03:00"),
deadlineMoment = time("2024-05-05T06:10:30+03:00")
),
)

Expand All @@ -59,11 +64,15 @@ class HomeworkApiTest(
l.description shouldBe r.description
l.maxScore shouldBe r.maxScore
l.publicationMoment shouldHaveSameInstantAs r.publicationMoment
l.deadlineMoment shouldHaveSameInstantAs r.deadlineMoment
}

val endingPoint = OffsetDateTime.now()

val results = draftToResultList.map { it.second }
results.forEach {
it.creationMoment shouldBeAfter startingPoint
it.creationMoment shouldBeBefore endingPoint
}

val ids = results.map { it.id }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ class RatingApiTest(
description = "Description Any",
maxScore = 200,
publicationMoment = OffsetDateTime.now(),
deadlineMoment = OffsetDateTime.now().plusDays(1)
)

private val dummySubmit =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ class WorkspaceApiTest(
description = "Description Any",
maxScore = 200,
publicationMoment = OffsetDateTime.now(),
deadlineMoment = OffsetDateTime.now().plusDays(1)
),
).awaitSingle().id
}
Expand Down

0 comments on commit 00f7be5

Please sign in to comment.