Compare commits

...

4 Commits

Author SHA1 Message Date
Jeas0001
e30110bcff Usercontrollers comments 2025-05-07 12:30:12 +02:00
Jeas0001
38cf388ea8 Shoppinglistcontroller comments 2025-05-07 11:54:02 +02:00
Jeas0001
edf8c73ec4 authorize atribute added to shppinglistcontroller 2025-05-07 11:29:35 +02:00
Jeas0001
1ce1f355c0 Recipecontroller comments 2025-05-07 11:28:21 +02:00
3 changed files with 105 additions and 2 deletions

View File

@ -20,6 +20,10 @@ namespace API.Controllers
_openAiRecipes = openAiRecipes;
}
/// <summary>
/// Gets the userId from the jwt token amd returns a list of recipes without their ingredients and directions
/// </summary>
/// <returns>returns a okobjectresult with a list of recipes if it fails it returns a confliftobjectresult with a message of why it failed</returns>
[Authorize]
[HttpGet("getall")]
public async Task<IActionResult> ReadRecipes()
@ -30,6 +34,11 @@ namespace API.Controllers
return await _recipeLogic.GetRecipes(userId);
}
/// <summary>
/// Gets a specifik recipe including the ingredients and directions
/// </summary>
/// <param name="recipeId">The recipe that is you want</param>
/// <returns>returns a okobjectresult with a recipe if it fails it returns a confliftobjectresult with a message of why it failed</returns>
[Authorize]
[HttpGet("get/{recipeId}")]
public async Task<IActionResult> ReadRecipe(int recipeId)
@ -37,13 +46,27 @@ namespace API.Controllers
return await _recipeLogic.GetRecipe(recipeId);
}
/// <summary>
/// Creates a recipe and adds it to the users recipes
/// </summary>
/// <param name="recipe">The recipe to be added</param>
/// <returns>returns a okobjectresult with a boolean that is true if it fails it returns a confliftobjectresult with a message of why it failed</returns>
[Authorize]
[HttpPost("create/{RecipesId}")]
public async Task<IActionResult> CreateRecipe([FromBody] RecipeDTO recipe, int RecipesId)
public async Task<IActionResult> CreateRecipe([FromBody] RecipeDTO recipe)
{
return await _recipeLogic.CreateRecipe(recipe, RecipesId);
var claims = HttpContext.User.Claims;
string userIdString = claims.FirstOrDefault(c => c.Type == ClaimTypes.NameIdentifier).Value;
int userId = Convert.ToInt32(userIdString);
return await _recipeLogic.CreateRecipe(recipe, userId);
}
/// <summary>
/// Edits a recipe
/// </summary>
/// <param name="recipe">the edited recipe</param>
/// <param name="recipeId">the recipe to be edited</param>
/// <returns>returns a okobjectresult with a boolean that is true if it fails it returns a confliftobjectresult with a message of why it failed</returns>
[Authorize]
[HttpPut("edit/{recipeId}")]
public async Task<IActionResult> EditRecipe([FromBody] RecipeDTO recipe, int recipeId)
@ -54,6 +77,11 @@ namespace API.Controllers
return await _recipeLogic.EditRecipe(recipe, recipeId, userId);
}
/// <summary>
/// Deletess a recipe
/// </summary>
/// <param name="recipeId">the id of the recipe to be deleted</param>
/// <returns>returns a okobjectresult with a boolean that is true if it fails it returns a confliftobjectresult with a message of why it failed</returns>
[Authorize]
[HttpDelete("delete/{recipeId}")]
public async Task<IActionResult> DeleteRecipe(int recipeId)
@ -61,6 +89,11 @@ namespace API.Controllers
return await _recipeLogic.DeleteRecipe(recipeId);
}
/// <summary>
/// Generates a recipe using chatgpt
/// </summary>
/// <param name="recipeDTO">Contains all the infomation that is needed to generate a recipe</param>
/// <returns>returns a list of generated recipes</returns>
[Authorize]
[HttpPost("chatbot")]
public async Task<IActionResult> GenerateRecipe([FromBody] GenerateRecipeDTO recipeDTO)

View File

@ -1,6 +1,7 @@

using API.BusinessLogic;
using API.Models.ShoppingListModels;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Security.Claims;
@ -17,6 +18,11 @@ namespace API.Controllers
_shoppingListLogic = shoppingListLogic;
}
/// <summary>
/// Gets the entire shoppinglist connected to the user
/// </summary>
/// <returns>returns a list of shoppinglist items if it fails it returns a confliftobjectresult with a message of why it failed</returns>
[Authorize]
[HttpGet("get")]
public async Task<IActionResult> ReadShoppingList()
{
@ -26,6 +32,12 @@ namespace API.Controllers
return await _shoppingListLogic.ReadShoppingList(userId);
}
/// <summary>
/// Adds an item to the shopping list
/// </summary>
/// <param name="listItemDTO"></param>
/// <returns></returns>
[Authorize]
[HttpPost("add")]
public async Task<IActionResult> AddItem([FromBody] ShoppingListItemDTO listItemDTO)
{
@ -35,6 +47,12 @@ namespace API.Controllers
return await _shoppingListLogic.AddItemToShoppingList(listItemDTO, userId);
}
/// <summary>
/// Checks/Unchecks an item on the shoppinglist
/// </summary>
/// <param name="itemId">The item to be checked/unchecked</param>
/// <returns>returns a okobjectresult with a boolean that is true if it fails it returns a confliftobjectresult with a message of why it failed</returns>
[Authorize]
[HttpPut("check")]
public async Task<IActionResult> CheckItem(int itemId)
{
@ -44,6 +62,13 @@ namespace API.Controllers
return await _shoppingListLogic.CheckItemInShoppingList(userId, itemId);
}
/// <summary>
/// Edits an item on the shoppinglist
/// </summary>
/// <param name="listItemDTO">The edited item</param>
/// <param name="itemId">The item to be edited</param>
/// <returns>returns a okobjectresult with a boolean that is true if it fails it returns a confliftobjectresult with a message of why it failed</returns>
[Authorize]
[HttpPut("update")]
public async Task<IActionResult> UpdateItem([FromBody] ShoppingListItemDTO listItemDTO, int itemId)
{
@ -53,6 +78,12 @@ namespace API.Controllers
return await _shoppingListLogic.UpdateItemInShoppingList(userId, itemId, listItemDTO);
}
/// <summary>
/// Deletes an item on the shoppinglist
/// </summary>
/// <param name="itemId">The item to be deleted</param>
/// <returns>returns a okobjectresult with a boolean that is true if it fails it returns a confliftobjectresult with a message of why it failed</returns>
[Authorize]
[HttpDelete("delete")]
public async Task<IActionResult> DeleteItem(int itemId)
{
@ -62,6 +93,12 @@ namespace API.Controllers
return await _shoppingListLogic.DeleteItemInShoppingList(userId, itemId);
}
/// <summary>
/// Add an entire recipes ingredients to the shoppinglist
/// </summary>
/// <param name="recipeId">The recipes ingredients to be added</param>
/// <returns>returns a okobjectresult with a boolean that is true if it fails it returns a confliftobjectresult with a message of why it failed</returns>
[Authorize]
[HttpPost("recipeadd")]
public async Task<IActionResult> AddARecipesItems(int recipeId)
{

View File

@ -17,6 +17,10 @@ namespace API.Controllers
_userLogic = userLogic;
}
/// <summary>
/// Gets the users email and username
/// </summary>
/// <returns>returns the users email, username and Id</returns>
[Authorize]
[HttpGet("get")]
public async Task<IActionResult> ReadUser()
@ -27,18 +31,33 @@ namespace API.Controllers
return await _userLogic.GetUser(userId);
}
/// <summary>
/// Logins a user
/// </summary>
/// <param name="loginDTO">The users login credentials</param>
/// <returns>Returns a jwttoken their username, id and a refreshtoken</returns>
[HttpPost("login")]
public async Task<IActionResult> Login([FromBody] LoginDTO loginDTO)
{
return await _userLogic.Login(loginDTO);
}
/// <summary>
/// Create a new user
/// </summary>
/// <param name="userDTO">contains the username email and password</param>
/// <returns>returns a okobjectresult with a boolean that is true if it fails it returns a confliftobjectresult with a message of why it failed</returns>
[HttpPost("create")]
public async Task<IActionResult> CreateUser([FromBody] CreateUserDTO userDTO)
{
return await _userLogic.RegisterUser(userDTO);
}
/// <summary>
/// Changes the password of the user
/// </summary>
/// <param name="passwordDTO">Contains the old password and the new one</param>
/// <returns>returns a okobjectresult with a boolean that is true if it fails it returns a confliftobjectresult with a message of why it failed</returns>
[Authorize]
[HttpPut("change-password")]
public async Task<IActionResult> ChangePassword([FromBody] ChangePasswordDTO passwordDTO)
@ -49,6 +68,11 @@ namespace API.Controllers
return await _userLogic.ChangePassword(passwordDTO, userId);
}
/// <summary>
/// Edits the email and username of the user
/// </summary>
/// <param name="userDTO">The updated username and email</param>
/// <returns>returns a okobjectresult with a boolean that is true if it fails it returns a confliftobjectresult with a message of why it failed</returns>
[Authorize]
[HttpPut("update")]
public async Task<IActionResult> UpdateUser([FromBody] UpdateUserDTO userDTO)
@ -59,6 +83,10 @@ namespace API.Controllers
return await _userLogic.EditProfile(userDTO, userId);
}
/// <summary>
/// Deletes the user
/// </summary>
/// <returns>returns a okobjectresult with a boolean that is true if it fails it returns a confliftobjectresult with a message of why it failed</returns>
[Authorize]
[HttpDelete("delete")]
public async Task<IActionResult> DeleteUser()
@ -69,6 +97,11 @@ namespace API.Controllers
return await _userLogic.DeleteUser(userId);
}
/// <summary>
/// For when the jwt token is outdated
/// </summary>
/// <param name="refreshToken">contains a string with the refreshtoken</param>
/// <returns>returns a new refreshtoken and new jwt token</returns>
[HttpPost("refreshtoken")]
public async Task<IActionResult> RefreashToken([FromBody] RefreshTokenDTO refreshToken)
{