-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added anaylitics controller, service and dto.
- Loading branch information
1 parent
63c95ec
commit 6d06da6
Showing
3 changed files
with
64 additions
and
0 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/kotlin/com/github/nenadjakic/ocr/studio/controller/AnalyticsController.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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()) | ||
} |
8 changes: 8 additions & 0 deletions
8
src/main/kotlin/com/github/nenadjakic/ocr/studio/dto/StatusCount.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
) |
14 changes: 14 additions & 0 deletions
14
src/main/kotlin/com/github/nenadjakic/ocr/studio/service/AnalyticsService.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() | ||
} |