Skip to content

Commit

Permalink
#21 Use OffsetDateTime at database
Browse files Browse the repository at this point in the history
  • Loading branch information
vityaman committed Mar 28, 2024
1 parent c9a2df9 commit 088f720
Show file tree
Hide file tree
Showing 5 changed files with 13 additions and 25 deletions.
7 changes: 0 additions & 7 deletions botalka/src/main/kotlin/ru/itmo/lms/botalka/config/Config.kt

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class JooqHomeworkStorage(
homework.title.text,
homework.description.text,
homework.maxScore.value,
homework.publicationMoment.toLocalDateTime(),
homework.publicationMoment,
)
.returningResult(HOMEWORK.fields().asList())
.coerce(HOMEWORK)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package ru.itmo.lms.botalka.storage.jooq.entity

import ru.itmo.lms.botalka.config.Config
import ru.itmo.lms.botalka.domain.model.Homework
import ru.itmo.lms.botalka.storage.jooq.tables.records.HomeworkRecord

Expand All @@ -10,6 +9,6 @@ fun HomeworkRecord.toModel(): Homework =
title = Homework.Title(this.title),
description = Homework.Description(this.description),
maxScore = Homework.Score(this.maxScore),
publicationMoment = this.publicationMoment.atOffset(Config.zoneOffset),
creationMoment = this.creationMoment!!.atOffset(Config.zoneOffset),
publicationMoment = this.publicationMoment,
creationMoment = this.creationMoment!!,
)
10 changes: 5 additions & 5 deletions botalka/src/main/resources/database/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ CHECK (VALUE ~ '[a-zA-Z''-]{3,31}');
CREATE TABLE lms.user (
id serial PRIMARY KEY,
alias lms.alias UNIQUE NOT NULL,
creation_moment timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
creation_moment timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE lms.teacher (
Expand All @@ -30,16 +30,16 @@ CREATE TABLE lms.homework (
title varchar(64) NOT NULL,
description text NOT NULL,
max_score lms.score NOT NULL,
publication_moment timestamp NOT NULL,
creation_moment timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
publication_moment timestamptz NOT NULL,
creation_moment timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE lms.homework_submission (
id serial PRIMARY KEY,
homework_id integer NOT NULL REFERENCES lms.homework(id),
student_id integer NOT NULL REFERENCES lms.student(user_id),
comment text NOT NULL,
creation_moment timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
creation_moment timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
);

CREATE TABLE lms.homework_feedback (
Expand All @@ -49,5 +49,5 @@ CREATE TABLE lms.homework_feedback (
teacher_id integer NOT NULL REFERENCES lms.teacher(user_id),
comment text NOT NULL,
score lms.score, -- NULLABLE
creation_moment timestamp NOT NULL DEFAULT CURRENT_TIMESTAMP
creation_moment timestamptz NOT NULL DEFAULT CURRENT_TIMESTAMP
);
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ import org.springframework.test.context.ContextConfiguration
import ru.itmo.lms.botalka.TestContainerInitializer
import ru.itmo.lms.botalka.api.http.apis.HomeworkApi
import ru.itmo.lms.botalka.api.http.message.toMessage
import ru.itmo.lms.botalka.config.Config
import ru.itmo.lms.botalka.domain.model.Homework
import java.time.OffsetDateTime

Expand All @@ -26,31 +25,31 @@ class HomeworkApiTest(
Homework.Title("Test Homework 1"),
Homework.Description("Test Homework 1 Description"),
Homework.Score(100),
datetime("2024-04-01T10:15:30"),
OffsetDateTime.parse("2024-04-01T10:15:30+03:00"),
),
Homework.Draft(
Homework.Title("Test Homework 2"),
Homework.Description("Test Homework 2 Description"),
Homework.Score(250),
datetime("2024-05-01T12:00:30"),
OffsetDateTime.parse("2024-05-01T12:00:30+03:00"),
),
Homework.Draft(
Homework.Title("Test Homework 3"),
Homework.Description("Test Homework 3 Description"),
Homework.Score(100),
datetime("2024-05-02T12:00:30"),
OffsetDateTime.parse("2024-05-02T12:00:30+03:00"),
),
Homework.Draft(
Homework.Title("Test Homework 4"),
Homework.Description("Test Homework 4 Description"),
Homework.Score(300),
datetime("2024-05-02T12:00:30"),
OffsetDateTime.parse("2024-05-02T12:00:30+03:00"),
),
)

@Test
fun createHomework() {
val startingPoint = OffsetDateTime.now(Config.zoneOffset)
val startingPoint = OffsetDateTime.now()

val draftToResultList = runBlocking {
drafts.map { draft ->
Expand All @@ -77,7 +76,4 @@ class HomeworkApiTest(
val ids = results.map { it.id }
ids.shouldBeUnique()
}

private fun datetime(code: String) =
OffsetDateTime.parse("$code${Config.zoneOffset}")
}

0 comments on commit 088f720

Please sign in to comment.