Skip to content

Commit

Permalink
Habit statistics (#7976)
Browse files Browse the repository at this point in the history
* user interest statistics

* formatter + checkstyle

* small change in getUserInterestStatistic logic. add part 2 of user story about how statistics how users behave with habits.

* statistic of how users interact with habits (creation, subscription)

* delete logs

* test for service

* sneaky throws to test method

* sneaky throws to test method

* controller tests

* issue

* javadoc for new habit repo methods

* javadoc for new habit statistic service methods

* formatter

* Update ManagementHabitStatisticControllerTest.java

* Update HabitStatisticServiceImplTest.java

* Update ManagementHabitStatisticController.java
  • Loading branch information
holotsvan authored Jan 6, 2025
1 parent b0e5abc commit 1dc7c09
Show file tree
Hide file tree
Showing 17 changed files with 1,043 additions and 18 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,74 @@
package greencity.webcontroller;

import greencity.constant.HttpStatuses;
import greencity.dto.habitstatistic.HabitDateCount;
import greencity.service.HabitStatisticService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import lombok.AllArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import java.util.List;
import java.util.Map;

@Controller
@AllArgsConstructor
@RequestMapping("/management/habit/statistics")
public class ManagementHabitStatisticController {
HabitStatisticService habitStatisticService;

@GetMapping
public String getStatisticsPage() {
return "core/management_habit_statistics";
}

/**
* Endpoint to retrieve user interest statistics.
*
* @return ResponseEntity containing user interest statistics.
*/
@Operation(summary = "Retrieve user interest statistics.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = HttpStatuses.OK),
@ApiResponse(responseCode = "403", description = HttpStatuses.FORBIDDEN)
})
@GetMapping("/interest")
public ResponseEntity<Map<String, Long>> getUserInterestStatistics() {
return ResponseEntity.ok(habitStatisticService.calculateUserInterest());
}

/**
* Endpoint to retrieve habit behavior statistics.
*
* @return ResponseEntity containing habit behavior statistics.
*/
@Operation(summary = "Retrieve statistics of how users behave with habits.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = HttpStatuses.OK),
@ApiResponse(responseCode = "403", description = HttpStatuses.FORBIDDEN)
})
@GetMapping("/habit-behavior")
public ResponseEntity<Map<String, Long>> getHabitBehaviorStatistics() {
return ResponseEntity.ok(habitStatisticService.calculateHabitBehaviorStatistic());
}

/**
* Endpoint to retrieve user interaction with habits(creation, subscription).
*
* @return ResponseEntity containing habit behavior statistics.
*/
@Operation(summary = "Retrieve statistics of how users interact with habits.")
@ApiResponses(value = {
@ApiResponse(responseCode = "200", description = HttpStatuses.OK),
@ApiResponse(responseCode = "403", description = HttpStatuses.FORBIDDEN)
})
@GetMapping("/user-interaction")
public ResponseEntity<Map<String, List<HabitDateCount>>> getUserHabitInteractionStatistics(
@RequestParam(defaultValue = "weekly") String range) {
return ResponseEntity.ok(habitStatisticService.calculateInteractions(range));
}
}
Loading

0 comments on commit 1dc7c09

Please sign in to comment.