Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
27 changes: 9 additions & 18 deletions Server/Controllers/IngrController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,10 @@ public IngrController(RecipEaseContext context)
/// Returns all the ingredients in Ingredient
/// </summary>
/// <remarks>
///
/// functionalities : Retrieves all ingredients.
///
/// database: Ingredient
///
/// constraints: no constraints
///
/// query: select * in Ingredient
///
/// Functionalities : Retrieves all ingredients.
/// Database: Ingredient.
/// Constraints: no constraints.
/// Query: Select * in Ingredient.
/// </remarks>

[HttpGet]
Expand All @@ -47,16 +42,12 @@ public async Task<ActionResult<IEnumerable<ApiIngredient>>> GetApiIngredient()
/// Returns the ingredients in Ingredient with the given id
/// </summary>
/// <remarks>
///
/// functionalities : Retrieves 1 row of ingredient
///
/// database: Ingredient
///
/// constraints: no constraints
///
/// query: select * in Ingredient where name=id
///
/// Functionalities : Retrieves 1 row of ingredient.
/// Database: Ingredient.
/// Constraints: No constraints.
/// Query: Select * in Ingredient where name=id.
/// </remarks>
/// <param name="id">id of the specific ingredient</param>
[HttpGet("{id}")]
public async Task<ActionResult<ApiIngredient>> GetApiIngredient(string id)
{
Expand Down
95 changes: 31 additions & 64 deletions Server/Controllers/IngrInShoppingListController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,48 +27,31 @@ public IngrInShoppingListController(RecipEaseContext context)
/// Returns all the items in an user's shopping list
/// </summary>
/// <remarks>
///
/// functionalities : Retrieves ingredient in a user's shopping list with according unit.
///
/// database: IngrInShoppingList, Customer
///
/// constraints: The authenticated user making this request must be the owner of the
/// shopping list.
///
/// query: select * IngrInShoppingList with UserId = id
///
/// Functionalities : Retrieves ingredients in a user's shopping list.
/// Database: IngrInShoppingList, Customer.
/// Constraints: The authenticated user making this request must be the owner of the shopping list.
/// Query: select * IngrInShoppingList with UserId = id.
/// </remarks>
/// <param name="id">id of the user who have the shopping list to converse to.</param>

/// <param name="id">id of the user of the shopping list</param>
[HttpGet("{id}")]
public async Task<ActionResult<ApiIngrInShoppingList>> GetApiIngrInShoppingList(string id)
public async Task<ActionResult<IEnumerable<ApiIngrInShoppingList>>> GetApiIngrInShoppingList(string id)
{
var apiIngrInShoppingList = await _context.ApiIngrInShoppingList.FindAsync(id);

if (apiIngrInShoppingList == null)
{
return NotFound();
}

return apiIngrInShoppingList;
return await _context.ApiIngrInShoppingList.ToListAsync();
}


/// <summary>
/// Returns the specific item in the IngrInShoppingList
/// Returns the specific item in the IngrInShoppingList.
/// </summary>
/// <remarks>
///
/// functionalities : Retrieves an item ingredient with a specific userid ,ingredient and unit.
///
/// database: IngrInShoppingList, Customer
///
/// constraints: The authenticated user making this request must be the owner of the
/// shopping list.
///
/// query: select * IngrInShoppingList with UserId = id and IngrName = iname and UnitName = uname
///
/// Functionalities : Retrieves an item ingredient with a specific userid ,ingredient and unit.
/// Database: IngrInShoppingList, Customer.
/// Constraints: The authenticated user making this request must be the owner of the shopping list.
/// Query: select * IngrInShoppingList with UserId = id and IngrName = iname and UnitName = uname.
/// </remarks>
/// <param name="id">id of the user of the shopping list</param>
/// <param name="uname">specify unit</param>
/// <param name="iname">specify ingredient</param>

[HttpGet]
public async Task<ActionResult<ApiIngrInShoppingList>> GetApiIngrInShoppingList(string id, string uname, string iname)
{
Expand All @@ -86,18 +69,12 @@ public async Task<ActionResult<ApiIngrInShoppingList>> GetApiIngrInShoppingList(
/// Edit the specific item in the IngrInShoppingList
/// </summary>
/// <remarks>
///
/// functionalities : Edit an item ingredient with a specific userid ,ingredient and unit.
///
/// database: IngrInShoppingList, Customer
///
/// constraints: The authenticated user making this request must be the owner of the
/// shopping list.
///
/// query: update * IngrInShoppingList set (some instance) where UserId = id and IngrName = iname and UnitName = uname
///
/// Functionalities : Edit an item ingredient with a specific userid ,ingredient and unit.
/// Database: IngrInShoppingList, Customer.
/// Constraints: The authenticated user making this request must be the owner of the shopping list.
/// query: update * IngrInShoppingList set (some instance) where UserId = id and IngrName = iname and UnitName = uname.
/// </remarks>

/// <param name="id">id of the user of the shopping list</param>
[HttpPut]
[Consumes("application/json")]
public async Task<IActionResult> PutApiIngrInShoppingList(string id, ApiIngrInShoppingList apiIngrInShoppingList)
Expand Down Expand Up @@ -129,18 +106,13 @@ public async Task<IActionResult> PutApiIngrInShoppingList(string id, ApiIngrInSh
}

/// <summary>
/// Create new row in IngrInShoppingList
/// Create new row in IngrInShoppingList
/// </summary>
/// <remarks>
///
/// functionalities : Insert a row with a specific userid ,ingredient and unit.
///
/// database: IngrInShoppingList, Customer
///
/// constraints: The authenticated user making this request must be the owner of the
/// shopping list.
///
/// query: insert into IngrInShoppingList
/// Functionalities : Insert a row with a specific userid ,ingredient and unit.
/// Database: IngrInShoppingList, Customer.
/// Constraints: The authenticated user making this request must be the owner of the shopping list.
/// Query: insert into IngrInShoppingList.
/// </remarks>
[HttpPost]
[Consumes("application/json")]
Expand Down Expand Up @@ -170,19 +142,14 @@ public async Task<ActionResult<ApiIngrInShoppingList>> PostApiIngrInShoppingList
/// Delete an ingredient in an user's shopping list
/// </summary>
/// <remarks>
///
/// functionalities : Retrieves ingredient in a user's shopping list with according unit.
///
/// database: IngrInShoppingList, Customer
///
/// constraints: The authenticated user making this request must be the owner of the
/// shopping list.
///
/// query: delete from IngrInShoppingList where userId = userId, ingrName = ingrName, unitName = unitName
///
/// Functionalities : Delete a row with a specific userid ,ingredient and unit.
/// Database: IngrInShoppingList, Customer.
/// Constraints: The authenticated user making this request must be the owner of the shopping list.
/// Query: Delete from IngrInShoppingList where userId = userId, ingrName = ingrName, unitName = unitName.
/// </remarks>

[HttpDelete]
[Consumes("application/json")]
public async Task<IActionResult> DeleteApiIngrInShoppingList(ApiIngrInShoppingList apiIngrInShoppingList)
{
if (apiIngrInShoppingList == null)
Expand Down
30 changes: 8 additions & 22 deletions Server/Controllers/ShoppingListController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,16 +27,10 @@ public ShoppingListController(RecipEaseContext context)
/// Returns an user's shopping list
/// </summary>
/// <remarks>
///
/// functionalities : Retrieves an user's shopping list with accordinging id.
///
/// database: ShoppingList, User
///
/// constraints: The authenticated user making this request must be the owner of the
/// shopping list.
///
/// query: select * ShoppingList with UserId = userId
///
/// Functionalities : Retrieves an user's shopping list with according id.
/// Database: ShoppingList, User.
/// Constraints: The authenticated user making this request must be the owner of the shopping list.
/// Query: select * ShoppingList with UserId = userId.
/// </remarks>
/// <param name="userId">id of the user who have the shopping list.</param>
[HttpGet("{userId}")]
Expand All @@ -56,20 +50,12 @@ public async Task<ActionResult<ApiShoppingList>> GetApiShoppingList(string userI
/// Edit an user's shopping list
/// </summary>
/// <remarks>
///
/// functionalities : Edit an user's shopping list with accordinging id.
///
/// database: ShoppingList, User
///
/// constraints: The authenticated user making this request must be the owner of the
/// shopping list.
///
/// query: update ShoppingList Set (some values) where UserId = userId
///
/// Functionalities : Edit an user's shopping list with accordinging id.
/// Database: ShoppingList, User.
/// Constraints: The authenticated user making this request must be the owner of the shopping list.
/// Query: update ShoppingList Set (some values) where UserId = userId
/// </remarks>
/// <param name="userId">id of the user who have the shopping list.</param>
/// <param name="apiShoppingList"></param>

[HttpPut("{userId}")]
[Consumes("application/json")]
public async Task<IActionResult> PutApiShoppingList(string userId, ApiShoppingList apiShoppingList)
Expand Down
11 changes: 0 additions & 11 deletions Server/Controllers/UnitController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,17 +26,11 @@ public UnitController(RecipEaseContext context)
/// Retrieves every unit
/// </summary>
/// <remarks>
///
/// functionalities : retrieve all unit in Unit table
///
/// database: Unit
///
/// constraints: no constraints
///
/// query: Select * from Unit
///
/// </remarks>

[HttpGet]
public async Task<ActionResult<IEnumerable<ApiUnit>>> GetApiUnit()
{
Expand All @@ -47,15 +41,10 @@ public async Task<ActionResult<IEnumerable<ApiUnit>>> GetApiUnit()
/// Get a unit with the specified name
/// </summary>
/// <remarks>
///
/// functionalities : retrieve the unit with the specified id
///
/// database: Unit
///
/// constraints: no constraints
///
/// query: select * from Unit where Name = id
///
/// </remarks>
/// <param name="id">name of the unit to be retrieved.</param>

Expand Down
13 changes: 1 addition & 12 deletions Server/Controllers/UnitConverseController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,15 +26,10 @@ public UnitConverseController(RecipEaseContext context)
/// Get all unit conversion
/// </summary>
/// <remarks>
///
/// functionalities : retrieve all unitconversion in UnitConversion
///
/// database: UnitConversion
///
/// constraints: no constraints
///
/// query: select * from UnitConversion
///
/// </remarks>
[HttpGet]
[Route("all")]
Expand All @@ -47,18 +42,12 @@ public async Task<ActionResult<IEnumerable<ApiUnitConversion>>> GetApiUnitConver
/// Get unit conversion from one unit to another
/// </summary>
/// <remarks>
///
/// functionalities : retrieve all unitconversion in UnitConversion
///
/// functionalities : retrieve unitconversion in UnitConversion with the specified units from both side
/// database: UnitConversion, Unit
///
/// constraints: two unit must be the same unit type
///
/// query: select * from UnitConversion where ConvertsToUnitName = id1 and
/// ConvertsFromUnitName = id2
///
/// </remarks>

[HttpGet]
public async Task<ActionResult<ApiUnitConversion>> GetApiUnitConversion(string id1, string id2)
{
Expand Down
75 changes: 75 additions & 0 deletions Server/Data/DbInitializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,10 @@
using Microsoft.EntityFrameworkCore;
using Microsoft.Extensions.DependencyInjection;
using RecipEase.Shared.Models;
using System.IO;
using System.Collections.Generic;
using LumenWorks.Framework.IO.Csv;


namespace RecipEase.Server.Data
{
Expand Down Expand Up @@ -34,5 +38,76 @@ public static void Initialize(RecipEaseContext context)
context.WeatherForecasts.AddRange(weatherForecasts);
context.SaveChanges();
}
public static void InitializeUnit(RecipEaseContext context)
{



CsvReader csv;

csv = new CsvReader(new StreamReader("unit_and_ingr/volume.csv"), true);

UnitType utype;
String uname, usym;
Unit temp;

if (!context.Unit.Any())
{
while (csv.ReadNextRecord())
{
utype = UnitType.Volume;
uname = csv[0];
usym = csv[1];
temp = new Unit { Name = uname, UnitType = utype, Symbol = usym };
context.Unit.Add(temp);

}


csv = new CsvReader(new StreamReader("unit_and_ingr/weight.csv"), true);

while (csv.ReadNextRecord())
{
utype = UnitType.Weight;
uname = csv[0];
usym = csv[1];

temp = new Unit { Name = uname, UnitType = utype, Symbol = usym };
context.Unit.Add(temp);
}
context.SaveChanges();
}


if (!context.UnitConversion.Any())
{

Dictionary<Unit, double> myDict;

csv = new CsvReader(new StreamReader("unit_and_ingr/frompound.csv"));
myDict = new Dictionary<Unit, double>();

while (csv.ReadNextRecord())
{
Unit aUnit = context.Unit.Find(csv[0]);
myDict.Add(aUnit, Double.Parse(csv[1]));
}
myDict.ToList().ForEach(x => myDict.ToList().ForEach(y =>
context.UnitConversion.Add(new UnitConversion { ConvertsToUnitName = x.Key.Name, ConvertsFromUnitName = y.Key.Name, Ratio = x.Value / y.Value })));
context.SaveChanges();

csv = new CsvReader(new StreamReader("unit_and_ingr/fromfluidounce.csv"));
myDict = new Dictionary<Unit, double>();

while (csv.ReadNextRecord())
{
Unit aUnit = context.Unit.Find(csv[0]);
myDict.Add(aUnit, Double.Parse(csv[1]));
}
myDict.ToList().ForEach(x => myDict.ToList().ForEach(y =>
context.UnitConversion.Add(new UnitConversion { ConvertsToUnitName = x.Key.Name, ConvertsFromUnitName = y.Key.Name, Ratio = x.Value / y.Value })));
context.SaveChanges();
}
}
}
}
1 change: 1 addition & 0 deletions Server/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ private static void CreateDbIfNotExists(IHost host)
{
var context = services.GetRequiredService<RecipEaseContext>();
DbInitializer.Initialize(context);
DbInitializer.InitializeUnit(context);
}
catch (Exception ex)
{
Expand Down
Loading