Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ class CreateMealLogEntryCT {
{
"type": "meal-log-entry",
"attributes": {
"time": 123345534,
"time": "2018-01-02 13:14:15+01",
"description": "Yogurt with strawberries",
"amount": 100,
"unit": "percentage"
Expand All @@ -75,7 +75,7 @@ class CreateMealLogEntryCT {
"id": "$uuid",
"type": "meal-log-entry",
"attributes": {
"time": 123345534,
"time": "2018-01-02 13:14:15+01",
"description": "Yogurt with strawberries",
"amount": 100,
"unit": "percentage"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.boot.web.server.LocalServerPort
import org.springframework.test.annotation.DirtiesContext
import java.time.ZoneOffset

@SpringBootTest(
classes = [Katydid::class],
Expand Down Expand Up @@ -64,7 +65,7 @@ class SearchLogEntriesCT {

private val time = ZonedDateTime
.of(2021, 6, 23, 20, 30, 50, 4, ZoneId.of("UTC"))
.toEpochSecond()

private const val description = "Spaghetti bolognese"
private const val amount = 4

Expand Down Expand Up @@ -103,7 +104,7 @@ class SearchLogEntriesCT {
"type": "meal",
"attributes": {
"childId": "${childId.value}",
"time": $time,
"time": "$time",
"description": "$description",
"amount": $amount,
"unit": "$unit"
Expand All @@ -127,7 +128,7 @@ class SearchLogEntriesCT {
"type": "nap",
"attributes": {
"childId": "${childId.value}",
"time": $time,
"time": "$time",
"duration": $duration
},
links: {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package com.quipalup.katydid.logentry.application

import java.time.ZonedDateTime

data class FilterLogEntryByDateQuery(val from: ZonedDateTime, val to: ZonedDateTime)
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.quipalup.katydid.logentry.application

import com.quipalup.katydid.logentry.domain.LogEntryRepositoryPC
import com.quipalup.katydid.logentry.domain.LogEntry_

class FilterLogEntryByDateQueryHandler(private val logEntryRepository: LogEntryRepositoryPC) {
fun execute(
query:
FilterLogEntryByDateQuery
): List<LogEntry_> {
return logEntryRepository.filterLogEntryByDate(query.from, query.to)
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.quipalup.katydid.logentry.domain

import com.quipalup.katydid.common.id.Id
import java.time.ZonedDateTime
import java.util.UUID

data class LogEntry(
Expand All @@ -18,7 +19,7 @@ sealed class LogEntry_ {
class Meal(
val id: Id,
override val childId: ChildId,
val time: Long,
val time: ZonedDateTime,
val description: String,
val amount: Int,
val unit: String
Expand All @@ -27,7 +28,7 @@ sealed class LogEntry_ {
class Nap(
val id: Id,
override val childId: ChildId,
val time: Long,
val time: ZonedDateTime,
val duration: Long
) : LogEntry_()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.quipalup.katydid.logentry.domain

import arrow.core.Either
import com.quipalup.katydid.common.id.Id
import java.time.ZonedDateTime

interface LogEntryRepository {
fun findById(id: Id): Either<FindLogEntryError, LogEntry>
Expand All @@ -14,4 +15,5 @@ interface LogEntryRepository {
interface LogEntryRepositoryPC {
fun searchAllByChildId(childId: ChildId): List<LogEntry_>
fun save(logEntry: LogEntry_)
fun filterLogEntryByDate(from: ZonedDateTime, to: ZonedDateTime): List<LogEntry_>
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package com.quipalup.katydid.logentry.primaryadapter.api

import java.time.ZonedDateTime

data class SearchLogEntriesDocument(
val data: List<SearchLogEntryDocument> = listOf(),
val included: List<IncludedChildDocument> = listOf()
Expand Down Expand Up @@ -45,15 +47,15 @@ sealed class IncludedChildDocument {

data class MealLogEntryDocumentAttributes(
val childId: String,
val time: Long,
val time: ZonedDateTime,
val description: String,
val amount: Int,
val unit: String
)

data class NapLogEntryDocumentAttributes(
val childId: String,
val time: Long,
val time: ZonedDateTime,
val duration: Long
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import com.quipalup.katydid.logentry.domain.LogEntry_
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController
import java.time.ZoneId
import java.time.ZonedDateTime

@RestController
class SearchLogEntriesEndpoint(
Expand Down Expand Up @@ -52,7 +54,7 @@ fun Pair<Either<FindChildByIdError, ChildResult>, List<LogEntry_>>.toSearchLogEn
id = it.id.value.toString(),
attributes = MealLogEntryDocumentAttributes(
childId = it.childId.value().toString(),
time = it.time,
time = ZonedDateTime.of(it.time.toLocalDateTime(), ZoneId.of("UTC")),
description = it.description,
amount = it.amount,
unit = it.unit
Expand All @@ -67,7 +69,7 @@ fun Pair<Either<FindChildByIdError, ChildResult>, List<LogEntry_>>.toSearchLogEn
id = it.id.value.toString(),
attributes = NapLogEntryDocumentAttributes(
childId = it.childId.value().toString(),
time = it.time,
time = ZonedDateTime.of(it.time.toLocalDateTime(), ZoneId.of("UTC")),
duration = it.duration
),
relationships = LogEntryChildRelationship(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ import com.quipalup.katydid.logentry.domain.FindLogEntryError
import com.quipalup.katydid.logentry.domain.LogEntry
import com.quipalup.katydid.logentry.domain.LogEntryMappingError
import com.quipalup.katydid.logentry.domain.LogEntry_
import java.time.ZonedDateTime
import java.util.UUID
import javax.inject.Named
import javax.persistence.Column
Expand All @@ -24,6 +25,7 @@ interface JpaLogEntryRepository : JpaRepository<JpaLogEntry, UUID>

interface JpaLogEntryRepositoryPC : JpaRepository<JpaLogEntryPC_, UUID> {
fun findAllByChildId(childId: String): List<JpaLogEntryPC_>
fun findByTimeBetween(from: ZonedDateTime, to: ZonedDateTime): List<JpaLogEntryPC_>
}

@Entity
Expand Down Expand Up @@ -56,7 +58,7 @@ open class JpaLogEntryPC_(
@Column(name = "child_id")
open var childId: String,
@Column(name = "occurred_on")
open var time: Long
open var time: ZonedDateTime
) {
fun toLogEntry_(): Either<LogEntryMappingError.UnrecognisableType, LogEntry_> =
when (this) {
Expand All @@ -71,7 +73,7 @@ open class JpaLogEntryPC_(
class JpaMealLogEntryPC(
id: String,
childId: String,
time: Long,
time: ZonedDateTime,
val description: String,
val amount: Int,
val unit: String
Expand All @@ -91,7 +93,7 @@ class JpaMealLogEntryPC(
class JpaNapLogEntryPC(
id: String,
childId: String,
time: Long,
time: ZonedDateTime,
private val duration: Long
) : JpaLogEntryPC_(id, childId, time) {
fun toNapLogEntry(): LogEntry_ = LogEntry_.Nap(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import arrow.core.Either
import com.quipalup.katydid.logentry.domain.ChildId
import com.quipalup.katydid.logentry.domain.LogEntryRepositoryPC
import com.quipalup.katydid.logentry.domain.LogEntry_
import java.time.ZonedDateTime
import javax.inject.Named

@Named
Expand All @@ -18,6 +19,12 @@ class LogEntryDatabasePC(private val jpaLogEntryRepository: JpaLogEntryRepositor
jpaLogEntryRepository.save(logEntry.toJpa())
}

override fun filterLogEntryByDate(from: ZonedDateTime, to: ZonedDateTime): List<LogEntry_> =
jpaLogEntryRepository.findByTimeBetween(from, to)
.map { it.toLogEntry_() }
.filter { it.isRight() }
.map { (it as Either.Right<LogEntry_>).value }

private fun LogEntry_.toJpa(): JpaLogEntryPC_ =
when (this) {
is LogEntry_.Meal -> JpaMealLogEntryPC(
Expand Down
20 changes: 10 additions & 10 deletions src/main/resources/data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ INSERT INTO log_entry
VALUES(
'93acd93f-cc03-49ab-b761-b2b2810ad505',
'5ee62461-adb8-4618-a110-06290a787223',
1625814857
'2018-01-02 13:14:15+01'
);

INSERT INTO meal_log_entry
Expand All @@ -19,7 +19,7 @@ INSERT INTO log_entry
VALUES(
'd2ff5b08-572b-4559-bb1f-0b5cdf01480e',
'86a93463-e7e1-4fc0-b12c-981f1eea16e8',
1625829017
'2018-01-02 13:14:15+01'
);

INSERT INTO meal_log_entry
Expand All @@ -35,7 +35,7 @@ INSERT INTO log_entry
VALUES(
'2da2e8c9-e698-4e02-8185-99972f858cf1',
'b9c2380f-0b4c-4871-aefc-a6ed2c3a2408',
1625828417
'2018-01-02 13:14:15+01'
);

INSERT INTO meal_log_entry
Expand All @@ -50,7 +50,7 @@ INSERT INTO log_entry
VALUES(
'6f64212b-333a-4c27-a166-e2d9403c6bc9',
'a5edf2fa-30b1-45e4-a39b-96243fa60caa',
1625817617
'2018-01-02 13:14:15+01'
);

INSERT INTO meal_log_entry
Expand All @@ -65,7 +65,7 @@ INSERT INTO log_entry
VALUES(
'a43dcdca-1840-4a11-b17c-d33ba0bdec4b',
'666cf327-09da-46ad-a01c-d3ae6e8ebc9d',
1625811677
'2018-01-02 13:14:15+01'
);

INSERT INTO meal_log_entry
Expand All @@ -81,7 +81,7 @@ INSERT INTO log_entry
VALUES(
'7a49cfd6-6a8a-404c-ad97-c51763341fe1',
'5ee62461-adb8-4618-a110-06290a787223',
1625819117
'2018-01-02 13:14:15+01'
);

INSERT INTO nap_log_entry
Expand All @@ -94,7 +94,7 @@ INSERT INTO log_entry
VALUES(
'd952c8d7-900f-46df-820c-a95910d8b2ee',
'86a93463-e7e1-4fc0-b12c-981f1eea16e8',
1625822837
'2018-01-02 13:14:15+01'
);


Expand All @@ -108,7 +108,7 @@ INSERT INTO log_entry
VALUES(
'9ca4af5c-6fe5-4d86-b553-38e0917a22a2',
'b9c2380f-0b4c-4871-aefc-a6ed2c3a2408',
1625829017
'2018-01-02 13:14:15+01'
);


Expand All @@ -122,7 +122,7 @@ INSERT INTO log_entry
VALUES(
'fb6ead93-7a69-4341-837d-e020845f1983',
'a5edf2fa-30b1-45e4-a39b-96243fa60caa',
1625836517
'2018-01-02 13:14:15+01'
);


Expand All @@ -136,7 +136,7 @@ INSERT INTO log_entry
VALUES(
'69d6da73-c8fb-4496-ae9b-ad70a4244df3',
'666cf327-09da-46ad-a01c-d3ae6e8ebc9d',
1625836517
'2018-01-02 13:14:15+01'
);


Expand Down
Loading