Added stats endpoint
This commit is contained in:
parent
4e40f0bdd8
commit
77bff3924c
@ -0,0 +1,29 @@
|
|||||||
|
package org.ros.chatto.controller;
|
||||||
|
|
||||||
|
import java.time.Instant;
|
||||||
|
|
||||||
|
import org.ros.chatto.dto.StatsDTO;
|
||||||
|
import org.ros.chatto.service.StatisticsService;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/stats")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class StatisticsController {
|
||||||
|
private final StatisticsService statisticsService;
|
||||||
|
|
||||||
|
@GetMapping
|
||||||
|
public StatsDTO rootStats() {
|
||||||
|
return StatsDTO.builder()
|
||||||
|
.totalMessages(statisticsService.totalMessage())
|
||||||
|
.totalOnlineUsers(statisticsService.totalUsersOnline())
|
||||||
|
.numMessagesToday(
|
||||||
|
statisticsService.messagesOnDay(Instant.now()))
|
||||||
|
.totalUsers(statisticsService.totalUsers()).build();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
21
src/main/java/org/ros/chatto/dto/StatsDTO.java
Normal file
21
src/main/java/org/ros/chatto/dto/StatsDTO.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package org.ros.chatto.dto;
|
||||||
|
|
||||||
|
import lombok.Builder;
|
||||||
|
import lombok.Getter;
|
||||||
|
|
||||||
|
@Builder
|
||||||
|
@Getter
|
||||||
|
public class StatsDTO {
|
||||||
|
@Builder.Default
|
||||||
|
private long totalUsers = 0;
|
||||||
|
|
||||||
|
@Builder.Default
|
||||||
|
private long totalOnlineUsers = 0;
|
||||||
|
|
||||||
|
@Builder.Default
|
||||||
|
private long totalMessages = 0;
|
||||||
|
|
||||||
|
@Builder.Default
|
||||||
|
private long numMessagesToday = 0;
|
||||||
|
|
||||||
|
}
|
@ -6,11 +6,13 @@ import org.ros.chatto.repository.ChatMessageRepository;
|
|||||||
import org.ros.chatto.repository.UserRepository;
|
import org.ros.chatto.repository.UserRepository;
|
||||||
import org.ros.chatto.repository.UserSessionRepository;
|
import org.ros.chatto.repository.UserSessionRepository;
|
||||||
import org.springframework.stereotype.Service;
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
|
||||||
import lombok.RequiredArgsConstructor;
|
import lombok.RequiredArgsConstructor;
|
||||||
|
|
||||||
@RequiredArgsConstructor
|
@RequiredArgsConstructor
|
||||||
@Service
|
@Service
|
||||||
|
@Transactional(readOnly = true)
|
||||||
public class StatisticsService {
|
public class StatisticsService {
|
||||||
private final ChatMessageRepository chatMessageRepository;
|
private final ChatMessageRepository chatMessageRepository;
|
||||||
private final UserRepository userRepo;
|
private final UserRepository userRepo;
|
||||||
|
Loading…
Reference in New Issue
Block a user