Added comments.
This commit is contained in:
parent
5f4ad72a14
commit
be031b0b32
@ -16,16 +16,25 @@ class Controller {
|
||||
@Autowired
|
||||
lateinit var observationRepository: ObservationRepository
|
||||
|
||||
/**
|
||||
* Returns a list of all current sites.
|
||||
*/
|
||||
@GetMapping("/site")
|
||||
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")
|
||||
fun addSite(@Valid @RequestBody newSite: NewSite): NameValue {
|
||||
val site = siteRepository.save(Site(name = newSite.name))
|
||||
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")
|
||||
fun getTutorsForSite(@PathVariable(value = "id") id: Long): List<NameValue>? {
|
||||
val site = siteRepository.findById(id)
|
||||
@ -34,9 +43,16 @@ class Controller {
|
||||
return null
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all known tutors.
|
||||
* Returned in a form compatible with a HTML Select element.
|
||||
*/
|
||||
@GetMapping("/tutor")
|
||||
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")
|
||||
fun addTutor(@Valid @RequestBody newTutor: NewTutor): NameValue? {
|
||||
var nameValue: NameValue? = null
|
||||
@ -49,12 +65,18 @@ class Controller {
|
||||
return nameValue
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all observations overseen by the tutor with [id].
|
||||
*/
|
||||
@GetMapping("/tutor/{id}/observations")
|
||||
fun getObservationsForTutor(@PathVariable(value = "id") id: Long): List<SimpleObservation> =
|
||||
tutorRepository.findById(id).map { tutor ->
|
||||
tutor.observations.map { SimpleObservation(it) }
|
||||
}.orElse(listOf())
|
||||
|
||||
/**
|
||||
* Add a new observation to the database using data provided in [newObservation].
|
||||
*/
|
||||
@PostMapping("/observation")
|
||||
fun addObservation(@Valid @RequestBody newObservation: NewObservation): Long? {
|
||||
val site = siteRepository.findById(newObservation.site)
|
||||
@ -87,6 +109,9 @@ class Controller {
|
||||
return observation.id
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all observations that are within the constraints provided in [observationsRequest].
|
||||
*/
|
||||
@PostMapping("/observations")
|
||||
fun getObservations(@Valid @RequestBody observationsRequest: ObservationsRequest): List<Observation> {
|
||||
if (observationsRequest.tutor != null) {
|
||||
@ -118,6 +143,10 @@ class Controller {
|
||||
return listOf()
|
||||
}
|
||||
|
||||
/**
|
||||
* Get all observations that are within the constraints provided in [observationsRequest]
|
||||
* in a format compatible with ChartJS.
|
||||
*/
|
||||
@PostMapping("/observations/chartdata")
|
||||
fun getObservationsChartData(@Valid @RequestBody observationsRequest: ObservationsRequest): ChartData? {
|
||||
val data = getObservations(observationsRequest)
|
||||
|
@ -5,6 +5,9 @@ import com.fasterxml.jackson.annotation.JsonProperty
|
||||
import org.joda.time.LocalDate
|
||||
import javax.persistence.*
|
||||
|
||||
/**
|
||||
* Defines a location at which observations occur.
|
||||
*/
|
||||
@Entity
|
||||
data class Site(
|
||||
@Id
|
||||
@ -15,6 +18,9 @@ data class Site(
|
||||
val tutors: MutableSet<Tutor> = mutableSetOf()
|
||||
}
|
||||
|
||||
/**
|
||||
* Defines a tutor who can oversee observations.
|
||||
*/
|
||||
@Entity
|
||||
data class Tutor(
|
||||
@Id
|
||||
@ -39,6 +45,9 @@ enum class RatingCategory {
|
||||
MONITORING, CONTROL, CONSERVATISM, TEAMWORK, KNOWLEDGE
|
||||
}
|
||||
|
||||
/**
|
||||
* Data record for a training observation.
|
||||
*/
|
||||
@Entity
|
||||
@Table(indexes = [Index(name = "dateIndex", columnList = "date")])
|
||||
data class Observation(
|
||||
@ -68,6 +77,9 @@ data class Observation(
|
||||
val tutors: Set<Tutor>
|
||||
)
|
||||
|
||||
/**
|
||||
* Entry giving specific details on observation performance for a tutor defined constraint.
|
||||
*/
|
||||
@Embeddable
|
||||
data class Entry(
|
||||
@Column(nullable = false)
|
||||
|
Loading…
Reference in New Issue
Block a user