Skip to content

Commit

Permalink
Added anaylitics controller, service and dto.
Browse files Browse the repository at this point in the history
  • Loading branch information
nenadjakic committed Sep 27, 2024
1 parent 63c95ec commit 6d06da6
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 0 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
package com.github.nenadjakic.ocr.studio.controller

import com.github.nenadjakic.ocr.studio.dto.StatusCount
import com.github.nenadjakic.ocr.studio.service.AnalyticsService
import io.swagger.v3.oas.annotations.Operation
import io.swagger.v3.oas.annotations.responses.ApiResponse
import io.swagger.v3.oas.annotations.responses.ApiResponses
import io.swagger.v3.oas.annotations.tags.Tag
import org.springframework.http.ResponseEntity
import org.springframework.web.bind.annotation.GetMapping
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

@Tag(name = "Analytics controller", description = "API endpoints for analytics.")
@RestController
@RequestMapping("/analytics")
class AnalyticsController(private val analyticsService: AnalyticsService) {

@Operation(
operationId = "getCountByStatus",
summary = "Get count by status.",
description = "Returns count by status information.")
@ApiResponses(
value = [
ApiResponse(responseCode = "200", description = "Successfully retrieved count by status.")
]
)
@GetMapping(value = ["/count-by-status"], produces = [org.springframework.http.MediaType.APPLICATION_JSON_VALUE])
fun getCountByStatus(): ResponseEntity<List<StatusCount>> = ResponseEntity.ok(analyticsService.getCountByStatus())

@Operation(
operationId = "getAverageInDocuments",
summary = "Get average count across inDocuments.",
description = "Returns average count across inDocuments.")
@ApiResponses(
value = [
ApiResponse(responseCode = "200", description = "Successfully retrieved average count across inDocuments.")
]
)
@GetMapping(value = ["/average-in-documents"], produces = [org.springframework.http.MediaType.APPLICATION_JSON_VALUE])
fun getAverageInDocuments(): ResponseEntity<Long> = ResponseEntity.ok(analyticsService.getAverageInDocuments())
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.github.nenadjakic.ocr.studio.dto

import com.github.nenadjakic.ocr.studio.entity.Status

data class StatusCount(
val status: Status,
val count: Long
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.github.nenadjakic.ocr.studio.service

import com.github.nenadjakic.ocr.studio.dto.StatusCount
import com.github.nenadjakic.ocr.studio.repository.TaskRepository
import org.springframework.stereotype.Service

@Service
class AnalyticsService(
private val taskRepository: TaskRepository
) {
fun getCountByStatus(): List<StatusCount> = taskRepository.countTasksByStatus()

fun getAverageInDocuments(): Long = taskRepository.averageInDocuments()
}

0 comments on commit 6d06da6

Please sign in to comment.