Skip to content

Commit

Permalink
replaced LocalDateTime with LocalDate to simplify date caluclation (#10)
Browse files Browse the repository at this point in the history
* replaced LocalDateTime with LocalDate to simplify date caluclation

* fixed tests, update dependencies + example ics

Co-authored-by: paulbrejla <[email protected]>
  • Loading branch information
fmuecke and paulbrejla authored Sep 11, 2022
1 parent f75a129 commit bc4ecae
Show file tree
Hide file tree
Showing 12 changed files with 123 additions and 34 deletions.
39 changes: 22 additions & 17 deletions build.gradle
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
buildscript {
ext {
kotlinVersion = '1.4.0'
springBootVersion = '2.3.3.RELEASE'
kotlinVersion = '1.7.10'
springBootVersion = '2.7.3'
}
repositories {
mavenCentral()
Expand Down Expand Up @@ -35,25 +35,30 @@ repositories {
mavenCentral()
}

test {
useJUnitPlatform()
}


dependencies {
compile("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
compile("org.springframework.boot:spring-boot-starter-jetty:${springBootVersion}")
compile("org.springframework.boot:spring-boot-starter-thymeleaf:${springBootVersion}")
compile("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
compile("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
compile 'net.sf.biweekly:biweekly:0.6.1'
compile group: 'commons-io', name: 'commons-io', version: '2.4'
compile("org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}")
compile("com.h2database:h2:1.4.200")
compile group: 'org.hibernate', name: 'hibernate-java8', version: '5.1.0.Final'
compile("org.springframework.boot:spring-boot-devtools:${springBootVersion}")
compile("io.springfox:springfox-boot-starter:3.0.0")
compile("io.springfox:springfox-swagger-ui:2.9.2")
implementation("org.springframework.boot:spring-boot-starter-web:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-jetty:${springBootVersion}")
implementation("org.springframework.boot:spring-boot-starter-thymeleaf:${springBootVersion}")
implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8:${kotlinVersion}")
implementation("org.jetbrains.kotlin:kotlin-reflect:${kotlinVersion}")
implementation 'net.sf.biweekly:biweekly:0.6.1'
implementation group: 'commons-io', name: 'commons-io', version: '2.4'
implementation("org.springframework.boot:spring-boot-starter-data-jpa:${springBootVersion}")
implementation("com.h2database:h2:1.4.200")
implementation group: 'org.hibernate', name: 'hibernate-java8', version: '5.1.0.Final'
implementation("org.springframework.boot:spring-boot-devtools:${springBootVersion}")
implementation("io.springfox:springfox-boot-starter:3.0.0")
implementation("io.springfox:springfox-swagger-ui:2.9.2")

// Foundation
compile 'org.webjars:foundation:6.3.1'
implementation('org.webjars:foundation:6.3.1')

testCompile("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
testImplementation("org.springframework.boot:spring-boot-starter-test:${springBootVersion}")
}

noArg {
Expand Down
2 changes: 1 addition & 1 deletion gradle/wrapper/gradle-wrapper.properties
Original file line number Diff line number Diff line change
Expand Up @@ -3,4 +3,4 @@ distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-6.6.1-all.zip
distributionUrl=https\://services.gradle.org/distributions/gradle-7.5.1-all.zip
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,11 @@ package de.paulbrejla.holidays
import org.springframework.boot.SpringApplication
import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.scheduling.annotation.EnableScheduling
import org.springframework.web.servlet.config.annotation.EnableWebMvc

@SpringBootApplication
@EnableScheduling
@EnableWebMvc
class HolidaysApiApplication

fun main(args: Array<String>) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,8 @@ import java.time.temporal.TemporalAccessor

fun assembleHoliday(event: VEvent, state: String): Holiday = Holiday(id = 0, stateCode = assembleStateCode(state),
summary = event.summary.value.toLowerCase(),
start = LocalDateTime.ofInstant(event.dateStart.value.toInstant(), ZoneOffset.UTC),
end = LocalDateTime.ofInstant(event.dateEnd.value.toInstant(), ZoneOffset.UTC),
start = LocalDateTime.ofInstant(event.dateStart.value.toInstant(), ZoneOffset.UTC).toLocalDate(),
end = LocalDateTime.ofInstant(event.dateEnd.value.toInstant(), ZoneOffset.UTC).toLocalDate(),
year = event.dateStart.value.rawComponents.year,
slug = assembleSlug(event.dateStart.value.rawComponents.year, event.summary.value, assembleStateCode(state)))

Expand Down
6 changes: 3 additions & 3 deletions src/main/kotlin/de/paulbrejla/holidays/domain/Models.kt
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package de.paulbrejla.holidays.domain

import java.io.Serializable
import java.time.LocalDateTime
import java.time.LocalDate
import javax.persistence.*


Expand All @@ -13,6 +13,6 @@ data class Holiday(@Id
@Enumerated(EnumType.STRING) var stateCode: State,
val year: Int,
var summary: String,
var start: LocalDateTime,
var end: LocalDateTime,
var start: LocalDate,
var end: LocalDate,
var slug: String) : Serializable
4 changes: 2 additions & 2 deletions src/main/kotlin/de/paulbrejla/holidays/rest/Assembler.kt
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@ import de.paulbrejla.holidays.domain.Holiday
import java.time.ZoneOffset

fun assembleHolidayDto(holiday: Holiday) = HolidayDto(
start = holiday.start.atOffset(ZoneOffset.UTC).toString(),
end = holiday.end.atOffset(ZoneOffset.UTC).toString(),
start = holiday.start.toString(),
end = holiday.end.toString(),
year = holiday.year,
stateCode = holiday.stateCode,
name = holiday.summary,
Expand Down
2 changes: 1 addition & 1 deletion src/main/kotlin/de/paulbrejla/holidays/rest/Dto.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package de.paulbrejla.holidays.rest

import de.paulbrejla.holidays.domain.State
import java.time.LocalDateTime
import java.time.LocalDate

data class HolidayDto(val start: String, val end: String, val year: Int, val stateCode: State, val name: String, val slug: String)
3 changes: 3 additions & 0 deletions src/main/resources/application.yml
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
spring:
application:
name: holidays-api
mcv:
pathmatch:
matching-strategy: ant_path_matcher
h2:
console:
enabled: false
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
package de.paulbrejla.holidays

import org.junit.Test
import org.junit.runner.RunWith
import org.junit.jupiter.api.Test
import org.springframework.boot.test.context.SpringBootTest
import org.springframework.test.context.junit4.SpringRunner

@RunWith(SpringRunner::class)
@SpringBootTest
class HolidaysApiApplicationTests {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
package de.paulbrejla.holidays.infrastructure.loader.impl

import de.paulbrejla.holidays.infrastructure.loader.api.CalendarLoader
import org.junit.jupiter.api.Test

import org.junit.jupiter.api.Assertions.*
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.boot.test.context.SpringBootTest

@SpringBootTest
internal class LocalFilesystemCalendarLoaderGatewayTest {

@Autowired
lateinit var calendarLoader: CalendarLoader

@Test
fun `calendar files are loaded`() {
// Given
val eventCount = 5

// When
val calendars = calendarLoader.loadCalendarFiles()

// Then
assertNotNull(calendars.first().calendars)
assertEquals(calendars.first().calendars.first().events.count(), eventCount)

}
}
10 changes: 5 additions & 5 deletions src/test/kotlin/de/paulbrejla/holidays/rest/AssemblerKtTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -2,23 +2,23 @@ package de.paulbrejla.holidays.rest

import de.paulbrejla.holidays.domain.Holiday
import de.paulbrejla.holidays.domain.State
import org.junit.Test
import org.junit.jupiter.api.Test

import org.junit.Assert.*
import java.time.LocalDateTime
import org.junit.jupiter.api.Assertions.*
import java.time.LocalDate

class AssemblerKtTest {

@Test
fun `a HolidayDto is assembled from a Holiday`() {
// Given
val holiday = Holiday(id = 1, stateCode = State.HB, year = 2020, summary = "Winterferien Bremen",
start = LocalDateTime.now(), end = LocalDateTime.now().plusYears(2), slug = "ferien-hb")
start = LocalDate.now(), end = LocalDate.now().plusYears(2), slug = "ferien-hb")

// When
val holidayDto = assembleHolidayDto(holiday)

// Then
assertNotNull(holiday)
assertNotNull(holidayDto)
}
}
52 changes: 52 additions & 0 deletions src/test/resources/holidays/ferien_baden-wuerttemberg_2017.ics
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
BEGIN:VCALENDAR
VERSION:2.0
CALSCALE:GREGORIAN
PRODID:FERIEN_API
METHOD:PUBLISH

BEGIN:VEVENT
DTSTAMP:20170922T052539Z
UID:bdfb478f-7169-4171-ad9f-da1887f20676
DTSTART;VALUE=DATE:20170410
DTEND;VALUE=DATE:20170422
DESCRIPTION:Osterferien 2017 Baden-Württemberg
SUMMARY:Osterferien
END:VEVENT

BEGIN:VEVENT
DTSTAMP:20170922T052539Z
UID:9c25e98e-939e-4912-ae58-153cdc88a8ed
DTSTART;VALUE=DATE:20170606
DTEND;VALUE=DATE:20170617
DESCRIPTION:Pfingstferien 2017 Baden-Württemberg
SUMMARY:Pfingstferien
END:VEVENT

BEGIN:VEVENT
DTSTAMP:20170922T052539Z
UID:ed7ebf1a-a8b1-4139-984f-2244b7550978
DTSTART;VALUE=DATE:20170727
DTEND;VALUE=DATE:20170910
DESCRIPTION:Sommerferien 2017 Baden-Württemberg
SUMMARY:Sommerferien
END:VEVENT

BEGIN:VEVENT
DTSTAMP:20170922T052539Z
UID:250f4e37-4ada-492e-a2d1-5b6fc3f619b7
DTSTART;VALUE=DATE:20171030
DTEND;VALUE=DATE:20171104
DESCRIPTION:Herbstferien 2017 Baden-Württemberg
SUMMARY:Herbstferien
END:VEVENT

BEGIN:VEVENT
DTSTAMP:20170922T052539Z
UID:027811ca-48cb-432b-b02a-d63f0d8b842a
DTSTART;VALUE=DATE:20171222
DTEND;VALUE=DATE:20180106
DESCRIPTION:Weihnachtsferien 2017 Baden-Württemberg
SUMMARY:Weihnachtsferien
END:VEVENT

END:VCALENDAR

0 comments on commit bc4ecae

Please sign in to comment.