Skip to content

Commit

Permalink
Merge pull request #57 from MaartenVercammen/frontend-butmakeitfancy
Browse files Browse the repository at this point in the history
Frontend butmakeitfancy
  • Loading branch information
tomassabol authored Nov 23, 2022
2 parents 69fd089 + 57fedd8 commit a104e52
Show file tree
Hide file tree
Showing 25 changed files with 659 additions and 253 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ public interface IRecipeData
{
Recipe? Get(Guid id);
List<Recipe>? Get();
List<Recipe>? GetLiked(Guid userId);
Guid Add(Recipe recipeToAdd);
bool Put(Recipe recipeToUpdate);
bool Delete(Guid id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,20 @@ public bool Put(Recipe recipeToUpdate)
throw new NotImplementedException();
}

// TODO: Fix this method - retrieve random from db
public List<Recipe>? GetLiked(Guid userId)
{
List<Recipe>? foundRecipes;
try
{
foundRecipes = _RecipeAccess.GetLikedRecipes(userId);
}
catch (Exception)
{
foundRecipes = null;
}
return foundRecipes;
}

public Recipe GetRandomRecipe(Guid userId){
List<Recipe> recipes = new List<Recipe>();
try{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public SwipedRecipeDataControl(IConfiguration inConfiguration)
List<SwipedRecipe>? foundRecipes;
try
{
foundRecipes = _SwipedRecipeAccess.GetSwipeRecipesByUser(userId);
foundRecipes = _SwipedRecipeAccess.GetSwipedRecipesByUser(userId);
}
catch (Exception)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,38 @@ public ActionResult<List<RecipeDto>> Get()

}

[HttpGet, Route("user/{userId}/liked")] //liked/{userId}
public ActionResult<List<RecipeDto>> GetLiked(string userId)
{
Guid userIdGuid = Guid.Parse(userId);
ActionResult<List<RecipeDto>> foundReturn;
// retrieve and convert data
List<Recipe>? foundRecipes = _rControl.GetLiked(userIdGuid);
List<RecipeDto>? foundDts = null;
if (foundRecipes != null)
{
foundDts = RecipeDtoConvert.FromRecipeCollection(foundRecipes);
}
// evaluate
if (foundDts != null)
{
if (foundDts.Count > 0)
{
foundReturn = Ok(foundDts); // Statuscode 200
}
else
{
foundReturn = new StatusCodeResult(204); // Ok, but no content
}
}
else
{
foundReturn = new StatusCodeResult(500); // Internal server error
}
// send response back to client
return foundReturn;
}

[HttpPost]
public ActionResult<string> Post([FromBody] RecipeDto inRecipe)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@ public interface IRecipeAccess
List<Recipe> GetRecipesSimplified();

List<Recipe> GetRandomRecipe(Guid userId);
List<Recipe> GetLikedRecipes(Guid userId);

Guid CreateRecipe(Recipe recipe);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public interface ISwipedRecipeAccess
{
SwipedRecipe GetSwipedRecipeById(Guid id);

List<SwipedRecipe> GetSwipeRecipesByUser(Guid userId);
List<SwipedRecipe> GetSwipedRecipesByUser(Guid userId);
List<SwipedRecipe> GetLikedByUser(Guid userId);

SwipedRecipe CreateSwipedRecipe(SwipedRecipe swipedRecipe);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,12 +71,12 @@ public List<Recipe> GetRecipes()
{
con.Open();
// Execute read
SqlDataReader recipeReader = readCommand.ExecuteReader();
SqlDataReader reader = readCommand.ExecuteReader();
// Collect data
foundRecipes = new List<Recipe>();
while (recipeReader.Read())
while (reader.Read())
{
readRecipe = GetRecipeById(Guid.Parse(recipeReader.GetString(recipeReader.GetOrdinal("recipeId"))));
readRecipe = GetRecipeById(Guid.Parse(reader.GetString(reader.GetOrdinal("recipeId"))));
foundRecipes.Add(readRecipe);
}

Expand All @@ -89,7 +89,7 @@ public List<Recipe> GetRandomRecipe(Guid userId)
{
List<Recipe> foundRecipes = new List<Recipe>();
Recipe recipe = new Recipe();
String userIdString = userId.ToString();
String userIdString = userId.ToString();

using (SqlConnection connection = new SqlConnection(_connectionString))
{
Expand All @@ -112,7 +112,7 @@ public List<Recipe> GetRandomRecipe(Guid userId)
return foundRecipes;
}

public List<Recipe> GetRecipesSimplified()
public List<Recipe> GetRecipesSimplified()
{
List<Recipe> foundRecipes;
Recipe readRecipe;
Expand All @@ -123,17 +123,17 @@ public List<Recipe> GetRecipesSimplified()
{
con.Open();
// Execute read
SqlDataReader recipeReader = readCommand.ExecuteReader();
SqlDataReader reader = readCommand.ExecuteReader();
// Collect data
foundRecipes = new List<Recipe>();
while (recipeReader.Read())
while (reader.Read())
{
readRecipe = new Recipe();
readRecipe.RecipeId = Guid.Parse(recipeReader.GetString(recipeReader.GetOrdinal("recipeId")));
readRecipe.Name = recipeReader.GetString(recipeReader.GetOrdinal("name"));
readRecipe.Description = recipeReader.GetString(recipeReader.GetOrdinal("description"));
readRecipe.PictureURL = recipeReader.GetString(recipeReader.GetOrdinal("pictureUrl"));
readRecipe.Time = recipeReader.GetInt32(recipeReader.GetOrdinal("time"));
readRecipe.RecipeId = Guid.Parse(reader.GetString(reader.GetOrdinal("recipeId")));
readRecipe.Name = reader.GetString(reader.GetOrdinal("name"));
readRecipe.Description = reader.GetString(reader.GetOrdinal("description"));
readRecipe.PictureURL = reader.GetString(reader.GetOrdinal("pictureUrl"));
readRecipe.Time = reader.GetInt32(reader.GetOrdinal("time"));

foundRecipes.Add(readRecipe);
}
Expand All @@ -143,6 +143,37 @@ public List<Recipe> GetRecipesSimplified()
return foundRecipes;
}

public List<Recipe> GetLikedRecipes(Guid userId)
{
List<Recipe> foundRecipes = new List<Recipe>();
Recipe readRecipe;
String userIdString = userId.ToString();

using (SqlConnection connection = new SqlConnection(_connectionString))
{
connection.Open();
using (SqlCommand command = connection.CreateCommand())
{
command.CommandText = "SELECT recipe.recipeId as recipeId, recipe.name as name, recipe.pictureUrl as pictureUrl, recipe.time as time FROM recipe inner JOIN [swipedRecipe] on recipe.recipeId = swipedRecipe.recipeId where swipedRecipe.userId = '00000000-0000-0000-0000-000000000000'";

command.Parameters.AddWithValue("@userId", userId);

SqlDataReader reader = command.ExecuteReader();
while (reader.Read())
{
readRecipe = new Recipe();
readRecipe.RecipeId = Guid.Parse(reader.GetString(reader.GetOrdinal("recipeId")));
readRecipe.Name = reader.GetString(reader.GetOrdinal("name"));
readRecipe.PictureURL = reader.GetString(reader.GetOrdinal("pictureUrl"));
readRecipe.Time = reader.GetInt32(reader.GetOrdinal("time"));
foundRecipes.Add(readRecipe);
}
reader.Close();
}
}
return foundRecipes;
}

/// <summary>
/// Insterts a recipe into the database
/// </summary>
Expand Down Expand Up @@ -246,7 +277,7 @@ public List<Guid> GetNotSwipedGuidsByUserId(Guid userId)
}
return guids;
}

/// <summary>
/// Updates a recipe
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ public SwipedRecipe GetSwipedRecipeById(Guid id)
/// </summary>
/// <param name="userId">The user's Guid</param>
/// <returns>A list of the user's all SwipedRecipe</returns>
public List<SwipedRecipe> GetSwipeRecipesByUser(Guid userId)
public List<SwipedRecipe> GetSwipedRecipesByUser(Guid userId)
{
String guidString = userId.ToString();
List<SwipedRecipe> sRecipeList = new List<SwipedRecipe>();
Expand Down
14 changes: 8 additions & 6 deletions frontend/src/App.tsx
Original file line number Diff line number Diff line change
@@ -1,22 +1,24 @@
import React from 'react';
import { Routes, Route } from 'react-router-dom';
import Index from './components';
import Create from './components/pages/Create';
import Explore from './components/pages/Explore';
import Home from './components/pages/Home';
import CreateRecipe from './components/recipe/CreateRecipe';
import GetRecipe from './components/recipe/GetRecipe';
import Liked from './components/pages/Liked';
import Recipe from './components/pages/Recipe';
import GetRecipes from './components/recipe/GetRecipes';
import Swipe from './components/swipe/swipe';
import './css/index.css';

const App: React.FC = () => {
return (
<Routes>
<Route path="/" element={<Index />} />
<Route path="/app" element={<Home />} />
<Route path="/createRecipe" element={<CreateRecipe />} />
<Route path="/createRecipe" element={<CreateRecipe />} />
<Route path="/createRecipe" element={<Create />} />
<Route path="/recipes" element={<GetRecipes />} />
<Route path="/recipes/:id" element={<GetRecipe />} />
<Route path="/recipes/:id" element={<Recipe />} />
<Route path="/explore" element={<Explore />} />
<Route path="/user/:id/liked" element={<Liked />} />
</Routes>
);
};
Expand Down
5 changes: 2 additions & 3 deletions frontend/src/components/Navbar.module.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
nav {
display: flex;
height: 8rem;
height: 6rem;
justify-content: center;
}

Expand All @@ -14,8 +14,7 @@ nav {
}

.pandaLogo {
font-size: 2rem;
font-size: 1.9rem;
color: #D8A8DC;
margin-left: 10px;
margin-bottom: 43px;
}
21 changes: 21 additions & 0 deletions frontend/src/components/pages/Create.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
import React from 'react';
import Header from './Header';
import style from './Home.module.css';
import Navbar from './Navbar';
import CreateRecipe from '../recipe/CreateRecipe';

const Explore: React.FC = () => {
return (
<>
<div className={style.homePage}>
<Header />
<div className={style.homeContent}>
<CreateRecipe />
</div>
<Navbar />
</div>
</>
);
};

export default Explore;
22 changes: 22 additions & 0 deletions frontend/src/components/pages/Explore.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
import React from 'react';
import Swipe from '../swipe/swipe';
import Header from './Header';
import style from './Home.module.css';
import Navbar from './Navbar';
import GetRecipes from '../recipe/GetRecipes';

const Explore: React.FC = () => {
return (
<>
<div className={style.homePage}>
<Header />
<div className={style.homeContent}>
<GetRecipes />
</div>
<Navbar />
</div>
</>
);
};

export default Explore;
22 changes: 0 additions & 22 deletions frontend/src/components/pages/Header.module.css

This file was deleted.

7 changes: 7 additions & 0 deletions frontend/src/components/pages/Home.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,11 @@
max-width: 575px;
margin-left: auto;
margin-right: auto;
}

.homeContent {
display: block;
overflow-y: scroll;
overflow-x: hidden;
height: 79vh;
}
23 changes: 23 additions & 0 deletions frontend/src/components/pages/Liked.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import React from 'react';
import Swipe from '../swipe/swipe';
import Header from './Header';
import style from './Home.module.css';
import Navbar from './Navbar';
import GetRecipe from '../recipe/GetRecipe';
import GetLikedRecipes from '../recipe/GetLikedRecipes';

const Liked: React.FC = () => {
return (
<>
<div className={style.homePage}>
<Header />
<div className={style.homeContent}>
<GetLikedRecipes />
</div>
<Navbar />
</div>
</>
);
};

export default Liked;
Loading

0 comments on commit a104e52

Please sign in to comment.