Class StatController
java.lang.Object
edu.ntnu.idatt2106_2023_06.backend.controller.StatController
@RestController
@CrossOrigin("*")
@RequestMapping("/stat")
public class StatController
extends Object
The StatController class contains the API endpoints related to statistics. It provides functionality for adding
statistics to the database, getting personal statistics, and getting fridge statistics. The endpoints are
protected by a JWT token, and the endpoints that require a fridgeId also check that the user is a member of that fridge.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionorg.springframework.http.ResponseEntity<Object>
getFridgeAvgThrownPerDay
(Long fridgeId, org.springframework.security.core.Authentication authentication) Get the average percentage of items thrown per day in the fridge.org.springframework.http.ResponseEntity<Object>
getFridgeAvgThrownTotal
(Long fridgeId) Get the average percentage of items thrown in total in a fridge.org.springframework.http.ResponseEntity<Object>
getFridgeMoneyUsedPerDay
(Long fridgeId, org.springframework.security.core.Authentication authentication) Get the money spent per day in a fridge.org.springframework.http.ResponseEntity<Object>
getFridgeMoneyWastedPerDay
(Long fridgeId, org.springframework.security.core.Authentication authentication) Get the money wasted in per dey in the fridge.org.springframework.http.ResponseEntity<Object>
getFridgeStats
(Long fridgeId, org.springframework.security.core.Authentication authentication) Get the statistics of a fridge.org.springframework.http.ResponseEntity<Object>
getUserAvgThrownPerDay
(org.springframework.security.core.Authentication authentication) Get the average percentage of items thrown per day by the user.org.springframework.http.ResponseEntity<Object>
Get the average percentage of items thrown in total by the user.org.springframework.http.ResponseEntity<Object>
getUserMoneyUsedPerDay
(org.springframework.security.core.Authentication authentication) Get the money spent per day by the user.org.springframework.http.ResponseEntity<Object>
getUserMoneyWastedPerDay
(org.springframework.security.core.Authentication authentication) Get the money wasted per day by the user.org.springframework.http.ResponseEntity<Object>
getUserStats
(org.springframework.security.core.Authentication authentication) Get the personal statistics of the user.org.springframework.http.ResponseEntity<Object>
statBoughtItem
(StatAddItemToFridgeDTO statAddItemToFridgeDTO, org.springframework.security.core.Authentication authentication) Adds a new stat to the database.org.springframework.http.ResponseEntity<Object>
statDeleteItem
(StatDeleteFromFridgeDTO statDeleteFromFridgeDTO, org.springframework.security.core.Authentication authentication) Adds a new stat to the database.
-
Constructor Details
-
StatController
public StatController()
-
-
Method Details
-
statDeleteItem
@PostMapping("/add/delete-item") public org.springframework.http.ResponseEntity<Object> statDeleteItem(@RequestBody StatDeleteFromFridgeDTO statDeleteFromFridgeDTO, org.springframework.security.core.Authentication authentication) Adds a new stat to the database. The stat is connected to the user automatically with the help of the JWT token. This endpoint should be used when a user deletes an item from their fridge.- Parameters:
statDeleteFromFridgeDTO
- The stat to add to the database.- Returns:
- A response entity with status code 200 if the stat was added successfully.
-
statBoughtItem
@PostMapping("/add/bought-item") public org.springframework.http.ResponseEntity<Object> statBoughtItem(@RequestBody StatAddItemToFridgeDTO statAddItemToFridgeDTO, org.springframework.security.core.Authentication authentication) Adds a new stat to the database. The stat is connected to the user automatically with the help of the JWT token. This endpoint should be used when a user buys an item.- Parameters:
statAddItemToFridgeDTO
- The stat to add to the database.authentication
- The JWT token of the user.- Returns:
- A response entity with status code 200 if the stat was added successfully.
-
getUserStats
@GetMapping("/get/user-stats") public org.springframework.http.ResponseEntity<Object> getUserStats(org.springframework.security.core.Authentication authentication) Get the personal statistics of the user.- Parameters:
authentication
- The JWT token of the user.
-
getFridgeStats
@GetMapping("/get/fridge-stats/{fridgeId}") public org.springframework.http.ResponseEntity<Object> getFridgeStats(@PathVariable Long fridgeId, org.springframework.security.core.Authentication authentication) Get the statistics of a fridge.- Parameters:
fridgeId
- The id of the fridge.authentication
- The JWT token of the user.
-
getUserAvgThrownPerDay
@GetMapping("/get/user-stats/avg-thrown-per-day") public org.springframework.http.ResponseEntity<Object> getUserAvgThrownPerDay(org.springframework.security.core.Authentication authentication) throws com.fasterxml.jackson.core.JsonProcessingException Get the average percentage of items thrown per day by the user.- Parameters:
authentication
- The JWT token of the user.- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
getFridgeAvgThrownPerDay
@GetMapping("/get/fridge-stats/avg-thrown-per-day/{fridgeId}") public org.springframework.http.ResponseEntity<Object> getFridgeAvgThrownPerDay(@PathVariable Long fridgeId, org.springframework.security.core.Authentication authentication) throws com.fasterxml.jackson.core.JsonProcessingException Get the average percentage of items thrown per day in the fridge.- Parameters:
authentication
- The JWT token of the user.- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
getUserMoneyWastedPerDay
@GetMapping("/get/user-stats/money-wasted-per-day") public org.springframework.http.ResponseEntity<Object> getUserMoneyWastedPerDay(org.springframework.security.core.Authentication authentication) throws com.fasterxml.jackson.core.JsonProcessingException Get the money wasted per day by the user.- Parameters:
authentication
- The JWT token of the user.- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
getFridgeMoneyWastedPerDay
@GetMapping("/get/fridge-stats/money-wasted-per-day/{fridgeId}") public org.springframework.http.ResponseEntity<Object> getFridgeMoneyWastedPerDay(@PathVariable Long fridgeId, org.springframework.security.core.Authentication authentication) throws com.fasterxml.jackson.core.JsonProcessingException Get the money wasted in per dey in the fridge.- Parameters:
authentication
- The JWT token of the user.fridgeId
- The id of the fridge.- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
getUserMoneyUsedPerDay
@GetMapping("/get/user-stats/money-used-per-day") public org.springframework.http.ResponseEntity<Object> getUserMoneyUsedPerDay(org.springframework.security.core.Authentication authentication) throws com.fasterxml.jackson.core.JsonProcessingException Get the money spent per day by the user.- Parameters:
authentication
- The JWT token of the user.- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
getFridgeMoneyUsedPerDay
@GetMapping("/get/fridge-stats/money-used-per-day/{fridgeId}") public org.springframework.http.ResponseEntity<Object> getFridgeMoneyUsedPerDay(@PathVariable Long fridgeId, org.springframework.security.core.Authentication authentication) throws com.fasterxml.jackson.core.JsonProcessingException Get the money spent per day in a fridge.- Parameters:
authentication
- The JWT token of the user.- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
getUserAvgThrownTotal
@GetMapping("/get/user-stats/avg-thrown-total") public org.springframework.http.ResponseEntity<Object> getUserAvgThrownTotal() throws com.fasterxml.jackson.core.JsonProcessingExceptionGet the average percentage of items thrown in total by the user.- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-
getFridgeAvgThrownTotal
@GetMapping("/get/fridge-stats/avg-thrown-total/{fridgeId}") public org.springframework.http.ResponseEntity<Object> getFridgeAvgThrownTotal(@PathVariable Long fridgeId) throws com.fasterxml.jackson.core.JsonProcessingException Get the average percentage of items thrown in total in a fridge.- Parameters:
fridgeId
- The id of the fridge.- Throws:
com.fasterxml.jackson.core.JsonProcessingException
-