Skip to content
Snippets Groups Projects
Commit 559294aa authored by Anders Austlid's avatar Anders Austlid
Browse files

Added and updated some javadoc

parent ed93cffd
No related branches found
No related tags found
No related merge requests found
Showing
with 50 additions and 51 deletions
......@@ -8,5 +8,5 @@
</list>
</option>
</component>
<component name="ProjectRootManager" version="2" languageLevel="JDK_X" default="true" project-jdk-name="openjdk-20" project-jdk-type="JavaSDK" />
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" project-jdk-name="openjdk-20" project-jdk-type="JavaSDK" />
</project>
\ No newline at end of file
......@@ -12,9 +12,8 @@ import java.util.Arrays;
/**
* Cors configuration for application
* @author Birk
* @version 1.0
* @since 04.04.2023
* @author Birk, Anders
* @version 1.1
*/
@Configuration
@AllArgsConstructor
......@@ -35,7 +34,6 @@ public class CorsConfig {
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**")
.allowedOrigins(Arrays.asList("https://localhost",
"https://10.24.38.136",
domainProperty.domain()
).toArray(String[]::new))
.allowedMethods(Arrays.asList(
......
......@@ -13,7 +13,6 @@ import org.springframework.security.web.SecurityFilterChain;
* Configs for security and authentication
* @author Birk
* @version 1.0
* @since 04.04.2023
*/
@Configuration
@AllArgsConstructor
......@@ -23,8 +22,6 @@ public class SecurityConfig {
* Configures the HttpSecurity for the application.
* Dose not need ot have csrf enabled, because we are using jwt
* and the application is stateless
* <p>
* TODO: Enable CORS policy when possible!
*
* @param http HttpSecurity to configure
* @return SecurityFilterChain with configured HttpSecurity
......
......@@ -26,7 +26,6 @@ import org.springframework.security.provisioning.InMemoryUserDetailsManager;
* Configures the authentication for the application.
* @author Anders and birk
* @version 1.1
* @since 05.04.2023
*/
@Configuration
public class AuthenticationConfig {
......
......@@ -6,7 +6,6 @@ import org.springframework.boot.context.properties.ConfigurationProperties;
* Configuration properties for the domain of the application
* @author Birk
* @version 1.0
* @since 04.04.2023
*/
@ConfigurationProperties(prefix = "domain")
public record DomainProperty (String domain){
......
......@@ -13,7 +13,6 @@ import org.springframework.web.bind.annotation.*;
/**
* Controller for allergies
* @author Stian Lyng
* @version 1.0
*/
@AllArgsConstructor
@RestController
......
......@@ -19,7 +19,6 @@ import org.springframework.web.bind.annotation.RestController;
*
* @author Anders
* @version 1.0
* @since 19.04.2023
*/
@RestController
......
......@@ -23,9 +23,6 @@ import org.springframework.web.bind.annotation.*;
@RequestMapping("/api/recipe")
public class RecipeController {
/**
* The recipe service
*/
private final RecipeService recipeService;
/**
......
......@@ -45,6 +45,7 @@ public class ShoppingListController {
* Gets a shopping list by its ID
*
* @param id the shopping list ID
* @param authentication The authentication object of the user.
* @return the shopping list, or an error if the ID is invalid,
* or the user dose not have the rights to edit the shopping list
*/
......@@ -65,6 +66,7 @@ public class ShoppingListController {
* Gets a shopping list by its group ID
*
* @param id the request containing the group ID
* @param authentication The authentication object of the user.
* @return the shopping list, or an error if the ID is invalid
*/
@GetMapping("/group/{groupId}")
......@@ -150,6 +152,7 @@ public class ShoppingListController {
*
* @param shoppingListId the shopping list ID
* @param ean the product EAN
* @param auth The authentication object of the user.
* @return the shopping list with the removed product, or an error if the shopping list ID or EAN is invalid
*/
@DeleteMapping("/removeProduct/{shoppingListId}/{ean}")
......
......@@ -14,28 +14,24 @@ import ntnu.idatt2016.v233.SmartMat.dto.response.WeeklyMenuResponse;
import ntnu.idatt2016.v233.SmartMat.service.RecipeService;
import ntnu.idatt2016.v233.SmartMat.service.WeeklyMenuService;
/**
* Controller for weekly menu
*
* @author Stian Lyng
* @version 1.0
*/
@AllArgsConstructor
@RestController
@RequestMapping("/api/weeklymenu")
public class WeeklyMenuController {
/*
private WeeklyMenuService weeklyMenuService;
@GetMapping("/{fridgeId}")
public ResponseEntity<List<WeeklyMenuResponse>> getWeeklyMenu(@PathVariable("fridgeId") Long fridgeId) {
List<WeeklyMenuResponse> weeklyMenu = weeklyMenuService.getWeeklyMenu(fridgeId);
if (weeklyMenu.isEmpty()) {
return ResponseEntity.notFound().build();
} else {
return ResponseEntity.ok(weeklyMenu);
}
}
*/
final private RecipeService recipeService;
/**
* Gets weekly menu for a fridge
* @param fridgeId the id of the fridge
* @return the weekly menu for the fridge
*/
@GetMapping("/{fridgeId}")
public ResponseEntity<Object> compareWeeklyMenuAndRecipeProducts(@PathVariable("fridgeId") Integer fridgeId) {
List<RecipeWithMatchCount> weeklyMenuDetails = recipeService.getWeeklyMenu(fridgeId);
......
......@@ -58,7 +58,8 @@ public class FridgeController {
/**
* Gets the fridge by its fridge id
* @param fridgeId the id of the fridge
* @param fridgeId the id of the fridge to get
* @param authentication a user authentication object for validation of user authorization
* @return the fridge if it exists, or a 404 if it doesn't, or a 403 if the user is not in the fridge
*/
@GetMapping("/fridge/{fridgeId}")
......@@ -79,6 +80,7 @@ public class FridgeController {
* Adds a product to the fridge of a group
*
* @param request the request containing the group id and product id
* @param authentication a user authentication object for validation of user authorization
* @return success if the product was added, bad request if the product was already in the fridge, or not found if the group or product doesn't exist
*/
@PostMapping("/group/product")
......@@ -107,6 +109,7 @@ public class FridgeController {
/**
* Updates a product in a fridge
* @param request the request containing the group id and product id
* @param authentication a user authentication object for validation of user authorization
* @return success if the product was added, bad request if the product was already in the fridge,
* or not found if the group or product doesn't exist
*/
......@@ -174,6 +177,7 @@ public class FridgeController {
/**
* Deletes a product from the fridge
* @param fridgeProductId the id of the fridge product association
* @param authentication the authentication of the user
* @return success if the product was deleted, bad request if the product wasn't found
* , or forbidden if the user is not in the group
*/
......@@ -207,6 +211,7 @@ public class FridgeController {
* Deletes a product from the fridge and creates a waste object from it.
*
* @param fridgeProductId The id of the fridge product association to be deleted
* @param authentication The authentication of the user
* @return A ResponseEntity with status code 200 if successful,
* or status code 404 if the specified fridge product association was not found.
* or status code 403 if the user is not in the group
......
......@@ -37,6 +37,7 @@ public class GroupController {
/**
* Gets a group by its id
* @param groupId the id of the group
* @param auth the authentication of the user
* @return a ResponseEntity containing the group if it exists, or a 404 if it doesn't
*/
@GetMapping("/{groupId}")
......@@ -72,6 +73,7 @@ public class GroupController {
* Creates a new group
*
* @param groupRequest the group to create
* @param auth the authentication of the user
* @return a ResponseEntity containing the created group if it was created successfully,
* or a 400 if the group name is invalid or already exists, or if the username is invalid
*/
......@@ -130,6 +132,7 @@ public class GroupController {
* Gets the level of a group
*
* @param groupId the id of the group
* @param auth the authentication of the user
* @return a ResponseEntity containing the level of the group if it exists, or a 404 if it doesn't
*/
@GetMapping("/{groupId}/level")
......@@ -174,6 +177,7 @@ public class GroupController {
* Updates the open/closed status of the group with the specified ID.
*
* @param groupId the ID of the group to update
* @param auth the authentication of the user
* @return a ResponseEntity with a Boolean value indicating whether the operation was successful
*/
@PutMapping("/{groupId}/changeOpen")
......@@ -196,6 +200,7 @@ public class GroupController {
* Handles the HTTP PUT request to change the primary group of a user.
*
* @param newPrimaryGroupId the ID of the new primary group
* @param auth the authentication of the user
* @return a ResponseEntity object containing an HTTP status code and the updated UserGroupAsso object,
* or a ResponseEntity object with an HTTP status code indicating that the request was not successful
*/
......@@ -244,6 +249,7 @@ public class GroupController {
* Handles the HTTP POST request to add a new connection between a user and a group.
*
* @param groupConnectionRequest the request object containing the username and link code of the user and group to be connected
* @param auth the authentication of the user
* @return a ResponseEntity object containing an HTTP status code and the newly created UserGroupAsso object,
* or a ResponseEntity object with an HTTP status code indicating that the request was not successful
*/
......@@ -294,6 +300,7 @@ public class GroupController {
* Changes the authority level of a user in a group.
*
* @param authorityRequest the request object containing the username and group ID of the user to change the authority of
* @param auth the authentication of the user
* @return a ResponseEntity object containing the updated UserGroupAsso object and an HTTP status code of 200,
* or a ResponseEntity object with an HTTP status code of 403 if the user is not authorized to change the authority,
* or a ResponseEntity object with an HTTP status code of 404 if the group or user does not exist
......
......@@ -144,6 +144,7 @@ public class WasteController {
* The amount is calculated based on the total cost of the expired products.
*
* @param groupId the ID of the group to retrieve the lost money from
* @param authentication The authentication of the user.
* @return a ResponseEntity with the lost money as a Double if found, or a ResponseEntity with status 404 if the group is not found
*/
@GetMapping("/statistic/lostMoney/{groupId}")
......@@ -159,6 +160,7 @@ public class WasteController {
* Retrieves the amount of CO2 emitted annually per person in a specific group.
*
* @param groupId the ID of the group to retrieve the statistic for
* @param authentication The authentication of the user.
* @return a ResponseEntity containing the amount of CO2 emitted annually per person in the group,
* or a ResponseEntity with HTTP status 404 (not found) if the group or data is not found
*/
......
......@@ -23,7 +23,6 @@ import java.util.Optional;
* It uses the product service to handle the requests.
* @version 1.0
* @Author Birk
* @since 26.04.2023
*/
@RestController
@AllArgsConstructor
......@@ -130,7 +129,7 @@ public class ProductController {
/**
* Returns all products in the database.
* @return All products in the database.
* @return A list of all products in the database.
*/
@GetMapping("/")
public ResponseEntity<List<Product>> getAllProducts() {
......
......@@ -18,7 +18,6 @@ import java.util.Optional;
*
* @author Anders
* @version 1.0
* @sinc 20.04.2023
*/
@AllArgsConstructor
......
......@@ -26,7 +26,6 @@ import java.util.stream.Collectors;
* It uses the user service to handle the requests.
* @author Birk
* @version 1.2
* @since 20.04.2023
*/
@AllArgsConstructor
@RestController
......@@ -38,16 +37,6 @@ public class UserController {
PasswordEncoder passwordEncoder;
/**
* Use this JSON format:
* {
* "username":"kari123",
* "password":"sjokoladekake",
* "email":"kari.nordman@gmail.com",
* "firstName":"kari",
* "lastName":"nordmann",
* "birthDate":"2001-12-12"
* }
*
* create a new user in the database
* uses the user service
* @param user The user to be registered.
......@@ -88,6 +77,7 @@ public class UserController {
/**
* Get a user from the database.
* @param username The username of the user to be fetched.
* @param authentication The authentication object of the user.
* @return The user with the given username.
*/
@GetMapping("/get/{username}")
......@@ -110,6 +100,7 @@ public class UserController {
* Adds the specified allergy to the user with the given username.
*
* @param allergyRequest the request object containing the username and allergy name
* @param authentication The authentication object of the user.
* @return a ResponseEntity with a boolean indicating whether the operation was successful
*/
@PostMapping("/addAllergy")
......@@ -126,6 +117,7 @@ public class UserController {
* Deletes the specified allergy from the user with the given username.
*
* @param allergyRequest the request object containing the username and allergy name
* @param authentication The authentication object of the user.
* @return a ResponseEntity with a boolean indicating whether the operation was successful
*/
@DeleteMapping("/deleteAllergy")
......
......@@ -5,7 +5,6 @@ package ntnu.idatt2016.v233.SmartMat.dto.enums;
*
* @author Birk
* @version 2.0
* @since 19.04.2023
*
*/
public enum Authority{
......
......@@ -2,7 +2,12 @@ package ntnu.idatt2016.v233.SmartMat.dto.request;
/**
* FridgeProductRequest is a record class representing a request to add a product to a fridge.
* @param fridgeProductId the id of the fridge product
* @param groupId the id of the group
* @param ean the ean of the product
* @param amount the amount of the product
* @param days the days before expiry date of the product
* @param price the price of the product
*/
public record FridgeProductRequest(long fridgeProductId, long groupId, long ean, int amount, int days, double price) {
}
......@@ -2,11 +2,6 @@ package ntnu.idatt2016.v233.SmartMat.dto.request;
/**
* LoginRequest is a record class representing a login request.
*
* @author Anders
* @version 1.0
* @since 18.04.2023
*
* @param username
* @param password
*/
......
......@@ -4,6 +4,15 @@ import lombok.Builder;
import java.util.List;
/**
* ProductRequest is a record class representing a request to create a product.
* @param ean the ean of the product
* @param name the name of the product
* @param description the description of the product
* @param image the image of the product
* @param price the price of the product
* @param allergies the allergies of the product
*/
@Builder
public record ProductRequest(long ean, String name, String description, String image, double price, List<String> allergies) {
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment