Skip to content

Commit

Permalink
Refactor model classes
Browse files Browse the repository at this point in the history
BilledTrain380 committed Jul 27, 2018
1 parent aa8261e commit cbb8515
Showing 18 changed files with 411 additions and 28 deletions.
Original file line number Diff line number Diff line change
@@ -68,13 +68,13 @@ class DefaultParticipationManager(
*
* @return the resulting list
*/
override fun getParticipantListByClazz(clazz: Clazz): List<Participant> {
override fun getParticipantListByClazz(clazz: ClazzObj): List<ParticipantObj> {

val absentCompetitorList = absentCompetitorRepository.findAll()

return competitorRepository.findByClazzId(clazz.id)
.map {
Participant(
ParticipantObj(
it.id!!,
it.surname,
it.prename,
Original file line number Diff line number Diff line change
@@ -36,8 +36,8 @@

package ch.schulealtendorf.sporttagpsa.business.participation

import ch.schulealtendorf.sporttagpsa.model.Clazz
import ch.schulealtendorf.sporttagpsa.model.Participant
import ch.schulealtendorf.sporttagpsa.model.ClazzObj
import ch.schulealtendorf.sporttagpsa.model.ParticipantObj
import ch.schulealtendorf.sporttagpsa.model.SingleParticipant
import ch.schulealtendorf.sporttagpsa.model.Sport

@@ -57,7 +57,7 @@ interface ParticipationManager {
*
* @return the resulting list
*/
fun getParticipantListByClazz(clazz: Clazz): List<Participant>
fun getParticipantListByClazz(clazz: ClazzObj): List<ParticipantObj>

/**
* @return the participant matching the given {@code id}
Original file line number Diff line number Diff line change
@@ -36,21 +36,21 @@

package ch.schulealtendorf.sporttagpsa.business.provider

import ch.schulealtendorf.sporttagpsa.model.Clazz
import ch.schulealtendorf.sporttagpsa.model.ClazzObj

/**
* Describes a provider for classes.
*
* @author nmaerchy
* @version 2.0.0
*/
interface ClazzProvider: Provider<Clazz> {
interface ClazzProvider: Provider<ClazzObj> {

/**
* @param id id of the class
*
* @return the class matching the given {@code id}
* @throws IllegalArgumentException if the class with the given id does not exist
*/
fun getOne(id: Int): Clazz
fun getOne(id: Int): ClazzObj
}
Original file line number Diff line number Diff line change
@@ -37,7 +37,7 @@
package ch.schulealtendorf.sporttagpsa.business.provider

import ch.schulealtendorf.sporttagpsa.entity.ClazzEntity
import ch.schulealtendorf.sporttagpsa.model.Clazz
import ch.schulealtendorf.sporttagpsa.model.ClazzObj
import ch.schulealtendorf.sporttagpsa.repository.ClazzRepository
import org.springframework.stereotype.Component

@@ -55,9 +55,9 @@ class SimpleClazzProvider(
/**
* @return all the data from this provider
*/
override fun getAll(): Collection<Clazz> {
override fun getAll(): Collection<ClazzObj> {
return clazzRepository.findAll().map {
Clazz(it?.id!!, it.name, it.teacher.name)
ClazzObj(it?.id!!, it.name, it.teacher.name)
}
}

@@ -67,11 +67,11 @@ class SimpleClazzProvider(
* @return the class matching the given {@code id}
* @throws IllegalArgumentException if the class with the given id does not exist
*/
override fun getOne(id: Int): Clazz {
override fun getOne(id: Int): ClazzObj {

val clazz: ClazzEntity = clazzRepository.findById(id)
.orElseThrow { IllegalArgumentException("Class does not exits: id=$id") }!!

return Clazz(clazz.id!!, clazz.name, clazz.teacher.name)
return ClazzObj(clazz.id!!, clazz.name, clazz.teacher.name)
}
}
10 changes: 10 additions & 0 deletions src/main/kotlin/ch/schulealtendorf/sporttagpsa/model/Birthday.kt
Original file line number Diff line number Diff line change
@@ -36,6 +36,7 @@

package ch.schulealtendorf.sporttagpsa.model

import java.text.SimpleDateFormat
import java.util.*

data class Birthday(
@@ -45,4 +46,13 @@ data class Birthday(
constructor(date: Date) : this(date.time)

fun date() = Date(milliseconds)

/**
* Formats this Birthday by the given {@code pattern}.
*
* Valid values are the same used in the {@link SimpleDateFormat} class constructor.
*
* @param pattern the format pattern of the date
*/
fun format(pattern: String): String = SimpleDateFormat(pattern).format(this.date())
}
14 changes: 10 additions & 4 deletions src/main/kotlin/ch/schulealtendorf/sporttagpsa/model/Clazz.kt
Original file line number Diff line number Diff line change
@@ -36,8 +36,14 @@

package ch.schulealtendorf.sporttagpsa.model

data class Clazz(
val id: Int,
/**
* Data class representing the class or category of a participant.
*
* @author nmaerchy
* @since 2.0.0
*/
data class Clazz @JvmOverloads constructor(
val name: String,
val teacher: String
)
val coach: String,
val pendingParticipation: Boolean = false
)
44 changes: 44 additions & 0 deletions src/main/kotlin/ch/schulealtendorf/sporttagpsa/model/ClazzObj.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
/*
* Copyright (c) 2018 by Nicolas Märchy
*
* This file is part of Sporttag PSA.
*
* Sporttag PSA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Sporttag PSA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Sporttag PSA. If not, see <http://www.gnu.org/licenses/>.
*
* Diese Datei ist Teil von Sporttag PSA.
*
* Sporttag PSA ist Freie Software: Sie können es unter den Bedingungen
* der GNU General Public License, wie von der Free Software Foundation,
* Version 3 der Lizenz oder (nach Ihrer Wahl) jeder späteren
* veröffentlichten Version, weiterverbreiten und/oder modifizieren.
*
* Sporttag PSA wird in der Hoffnung, dass es nützlich sein wird, aber
* OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
* Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
* Siehe die GNU General Public License für weitere Details.
*
* Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
* Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
*
*
*/

package ch.schulealtendorf.sporttagpsa.model

@Deprecated("ClazzObj will no longer be used. Use Clazz instead")
data class ClazzObj(
val id: Int,
val name: String,
val teacher: String
)
57 changes: 57 additions & 0 deletions src/main/kotlin/ch/schulealtendorf/sporttagpsa/model/Competitor.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright (c) 2018 by Nicolas Märchy
*
* This file is part of Sporttag PSA.
*
* Sporttag PSA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Sporttag PSA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Sporttag PSA. If not, see <http://www.gnu.org/licenses/>.
*
* Diese Datei ist Teil von Sporttag PSA.
*
* Sporttag PSA ist Freie Software: Sie können es unter den Bedingungen
* der GNU General Public License, wie von der Free Software Foundation,
* Version 3 der Lizenz oder (nach Ihrer Wahl) jeder späteren
* veröffentlichten Version, weiterverbreiten und/oder modifizieren.
*
* Sporttag PSA wird in der Hoffnung, dass es nützlich sein wird, aber
* OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
* Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
* Siehe die GNU General Public License für weitere Details.
*
* Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
* Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
*
*
*/

package ch.schulealtendorf.sporttagpsa.model

/**
* Data class representing a competitor.
*
* @author nmaerchy <billedtrain380@gmail.com>
* @since 2.0.0
*/
data class Competitor(
val id: Int,
val startNumber: Int,
val surname: String,
val prename: String,
val gender: Gender,
val birthday: Birthday,
val absent: Boolean,
val address: String,
val town: Town,
val clazz: Clazz,
val results: List<Result>
)
51 changes: 51 additions & 0 deletions src/main/kotlin/ch/schulealtendorf/sporttagpsa/model/Discipline.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2018 by Nicolas Märchy
*
* This file is part of Sporttag PSA.
*
* Sporttag PSA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Sporttag PSA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Sporttag PSA. If not, see <http://www.gnu.org/licenses/>.
*
* Diese Datei ist Teil von Sporttag PSA.
*
* Sporttag PSA ist Freie Software: Sie können es unter den Bedingungen
* der GNU General Public License, wie von der Free Software Foundation,
* Version 3 der Lizenz oder (nach Ihrer Wahl) jeder späteren
* veröffentlichten Version, weiterverbreiten und/oder modifizieren.
*
* Sporttag PSA wird in der Hoffnung, dass es nützlich sein wird, aber
* OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
* Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
* Siehe die GNU General Public License für weitere Details.
*
* Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
* Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
*
*
*/

package ch.schulealtendorf.sporttagpsa.model

import java.util.*

/**
* Data class representing a discipline.
*
* @author nmaerchy <billedtrain380@gmail.com>
* @since 2.0.0
*/
data class Discipline @JvmOverloads constructor(
val name: String,
val unit: String,
val discipline: Optional<String> = Optional.empty()
)
Original file line number Diff line number Diff line change
@@ -36,6 +36,12 @@

package ch.schulealtendorf.sporttagpsa.model

/**
* Data class representing a gender.
*
* @author nmaerchy
* @since 1.0.0
*/
data class Gender(
val value: Boolean = true
) {
@@ -50,4 +56,4 @@ data class Gender(
fun isFemale() = !value

override fun toString() = if(value) "Knaben" else "Mädchen"
}
}
Original file line number Diff line number Diff line change
@@ -38,13 +38,21 @@ package ch.schulealtendorf.sporttagpsa.model

import java.util.*

data class Participant(
/**
* Data class representing a participant.
*
* @author nmaerchy <billedtrain380@gmail.com>
* @since 2.0.0
*/
data class Participant @JvmOverloads constructor(
val id: Int,
val surname: String,
val prename: String,
val gender: Gender,
val birthday: Birthday,
val address: String,
val absent: Boolean,
val sport: Optional<Sport>
)
val address: String,
val town: Town,
val clazz: Clazz,
val sport: Optional<String> = Optional.empty()
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* Copyright (c) 2018 by Nicolas Märchy
*
* This file is part of Sporttag PSA.
*
* Sporttag PSA is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Sporttag PSA is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Sporttag PSA. If not, see <http://www.gnu.org/licenses/>.
*
* Diese Datei ist Teil von Sporttag PSA.
*
* Sporttag PSA ist Freie Software: Sie können es unter den Bedingungen
* der GNU General Public License, wie von der Free Software Foundation,
* Version 3 der Lizenz oder (nach Ihrer Wahl) jeder späteren
* veröffentlichten Version, weiterverbreiten und/oder modifizieren.
*
* Sporttag PSA wird in der Hoffnung, dass es nützlich sein wird, aber
* OHNE JEDE GEWÄHRLEISTUNG, bereitgestellt; sogar ohne die implizite
* Gewährleistung der MARKTFÄHIGKEIT oder EIGNUNG FÜR EINEN BESTIMMTEN ZWECK.
* Siehe die GNU General Public License für weitere Details.
*
* Sie sollten eine Kopie der GNU General Public License zusammen mit diesem
* Programm erhalten haben. Wenn nicht, siehe <http://www.gnu.org/licenses/>.
*
*
*/

package ch.schulealtendorf.sporttagpsa.model

import java.util.*

@Deprecated("ParticipantObj will no longer be used. Use Participant instead")
data class ParticipantObj(
val id: Int,
val surname: String,
val prename: String,
val gender: Gender,
val birthday: Birthday,
val address: String,
val absent: Boolean,
val sport: Optional<Sport>
)
Loading

0 comments on commit cbb8515

Please sign in to comment.