Added comments.

This commit is contained in:
neviyn 2018-10-09 16:22:11 +01:00
parent 5f4ad72a14
commit be031b0b32
2 changed files with 45 additions and 4 deletions

View File

@ -16,16 +16,25 @@ class Controller {
@Autowired @Autowired
lateinit var observationRepository: ObservationRepository lateinit var observationRepository: ObservationRepository
/**
* Returns a list of all current sites.
*/
@GetMapping("/site") @GetMapping("/site")
fun getAllSites(): List<NameValue> = siteRepository.findAll().map { NameValue(it.name, it.id) } fun getAllSites(): List<NameValue> = siteRepository.findAll().map { NameValue(it.name, it.id) }
/**
* Add a new Site to the database based on the data provided in [newSite].
*/
@PostMapping("/site") @PostMapping("/site")
fun addSite(@Valid @RequestBody newSite: NewSite): NameValue { fun addSite(@Valid @RequestBody newSite: NewSite): NameValue {
val site = siteRepository.save(Site(name = newSite.name)) val site = siteRepository.save(Site(name = newSite.name))
return NameValue(site.name, site.id) return NameValue(site.name, site.id)
} }
/**
* Get all the tutors assigned to the site with the given [id].
* Returned in a form compatible with a HTML Select element.
*/
@GetMapping("/site/{id}/tutors") @GetMapping("/site/{id}/tutors")
fun getTutorsForSite(@PathVariable(value = "id") id: Long): List<NameValue>? { fun getTutorsForSite(@PathVariable(value = "id") id: Long): List<NameValue>? {
val site = siteRepository.findById(id) val site = siteRepository.findById(id)
@ -34,9 +43,16 @@ class Controller {
return null return null
} }
/**
* Get all known tutors.
* Returned in a form compatible with a HTML Select element.
*/
@GetMapping("/tutor") @GetMapping("/tutor")
fun getAllTutors(): List<NameValue> = tutorRepository.findAll().map { NameValue(it.name, it.id) } fun getAllTutors(): List<NameValue> = tutorRepository.findAll().map { NameValue(it.name, it.id) }
/**
* Add a new Tutor to the database based on the data provided in [newTutor].
*/
@PostMapping("/tutor") @PostMapping("/tutor")
fun addTutor(@Valid @RequestBody newTutor: NewTutor): NameValue? { fun addTutor(@Valid @RequestBody newTutor: NewTutor): NameValue? {
var nameValue: NameValue? = null var nameValue: NameValue? = null
@ -49,12 +65,18 @@ class Controller {
return nameValue return nameValue
} }
/**
* Get all observations overseen by the tutor with [id].
*/
@GetMapping("/tutor/{id}/observations") @GetMapping("/tutor/{id}/observations")
fun getObservationsForTutor(@PathVariable(value = "id") id: Long): List<SimpleObservation> = fun getObservationsForTutor(@PathVariable(value = "id") id: Long): List<SimpleObservation> =
tutorRepository.findById(id).map { tutor -> tutorRepository.findById(id).map { tutor ->
tutor.observations.map { SimpleObservation(it) } tutor.observations.map { SimpleObservation(it) }
}.orElse(listOf()) }.orElse(listOf())
/**
* Add a new observation to the database using data provided in [newObservation].
*/
@PostMapping("/observation") @PostMapping("/observation")
fun addObservation(@Valid @RequestBody newObservation: NewObservation): Long? { fun addObservation(@Valid @RequestBody newObservation: NewObservation): Long? {
val site = siteRepository.findById(newObservation.site) val site = siteRepository.findById(newObservation.site)
@ -87,6 +109,9 @@ class Controller {
return observation.id return observation.id
} }
/**
* Get all observations that are within the constraints provided in [observationsRequest].
*/
@PostMapping("/observations") @PostMapping("/observations")
fun getObservations(@Valid @RequestBody observationsRequest: ObservationsRequest): List<Observation> { fun getObservations(@Valid @RequestBody observationsRequest: ObservationsRequest): List<Observation> {
if (observationsRequest.tutor != null) { if (observationsRequest.tutor != null) {
@ -118,6 +143,10 @@ class Controller {
return listOf() return listOf()
} }
/**
* Get all observations that are within the constraints provided in [observationsRequest]
* in a format compatible with ChartJS.
*/
@PostMapping("/observations/chartdata") @PostMapping("/observations/chartdata")
fun getObservationsChartData(@Valid @RequestBody observationsRequest: ObservationsRequest): ChartData? { fun getObservationsChartData(@Valid @RequestBody observationsRequest: ObservationsRequest): ChartData? {
val data = getObservations(observationsRequest) val data = getObservations(observationsRequest)

View File

@ -5,6 +5,9 @@ import com.fasterxml.jackson.annotation.JsonProperty
import org.joda.time.LocalDate import org.joda.time.LocalDate
import javax.persistence.* import javax.persistence.*
/**
* Defines a location at which observations occur.
*/
@Entity @Entity
data class Site( data class Site(
@Id @Id
@ -15,6 +18,9 @@ data class Site(
val tutors: MutableSet<Tutor> = mutableSetOf() val tutors: MutableSet<Tutor> = mutableSetOf()
} }
/**
* Defines a tutor who can oversee observations.
*/
@Entity @Entity
data class Tutor( data class Tutor(
@Id @Id
@ -39,6 +45,9 @@ enum class RatingCategory {
MONITORING, CONTROL, CONSERVATISM, TEAMWORK, KNOWLEDGE MONITORING, CONTROL, CONSERVATISM, TEAMWORK, KNOWLEDGE
} }
/**
* Data record for a training observation.
*/
@Entity @Entity
@Table(indexes = [Index(name = "dateIndex", columnList = "date")]) @Table(indexes = [Index(name = "dateIndex", columnList = "date")])
data class Observation( data class Observation(
@ -68,6 +77,9 @@ data class Observation(
val tutors: Set<Tutor> val tutors: Set<Tutor>
) )
/**
* Entry giving specific details on observation performance for a tutor defined constraint.
*/
@Embeddable @Embeddable
data class Entry( data class Entry(
@Column(nullable = false) @Column(nullable = false)