Skip to content
Snippets Groups Projects
Commit 24e1657a authored by Seb Barnard's avatar Seb Barnard :speech_balloon:
Browse files

Merge remote-tracking branch 'origin/issueTwentyone' into issueTwentyone

# Conflicts:
#	src/test/resources/schema-test-h2.sql
parents 5d48b8bd 2d4f9e15
No related branches found
No related tags found
No related merge requests found
Showing
with 275 additions and 12 deletions
package com.example.clientproject;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.datasource.DataSourceTransactionManager;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabase;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseType;
import org.springframework.session.jdbc.config.annotation.web.http.EnableJdbcHttpSession;
import org.springframework.session.web.context.AbstractHttpSessionApplicationInitializer;
import org.springframework.transaction.PlatformTransactionManager;
import javax.sql.DataSource;
@Configuration
@EnableJdbcHttpSession
public class Config
extends AbstractHttpSessionApplicationInitializer {
@Bean
public EmbeddedDatabase dataSource() {
return new EmbeddedDatabaseBuilder()
.setType(EmbeddedDatabaseType.H2)
.addScript("org/springframework/session/jdbc/schema-h2.sql").build();
}
@Bean
public PlatformTransactionManager transactionManager(DataSource dataSource) {
return new DataSourceTransactionManager(dataSource);
}
}
package com.example.clientproject.data.misc;
import com.example.clientproject.data.tags.Tags;
import com.example.clientproject.data.users.Users;
import com.example.clientproject.service.dtos.UsersDTO;
import java.util.List;
public interface MiscQueries {
void saveUserFavouriteTags(Users user, Tags tag);
void saveUser(Users user);
void saveTag(Tags tag);
List<UserFavouriteTags> findAllUserFavouriteTags();
}
package com.example.clientproject.data.misc;
import com.example.clientproject.data.tags.Tags;
import com.example.clientproject.data.users.Users;
import com.example.clientproject.service.dtos.UsersDTO;
import org.springframework.jdbc.core.JdbcOperations;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.jdbc.core.simple.SimpleJdbcInsert;
import org.springframework.stereotype.Repository;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Class for any misc queries, JDBC will be used instead of JPA for more customization
*/
@Repository
public class MiscQueriesImpl implements MiscQueries{
private final JdbcTemplate jdbcTemplate;
private final RowMapper<UserFavouriteTags> userFavouriteTagsRowMapper;
/**
* Constructor
* @param aJdbcTemplate - the JDBC Template to pass in
*/
public MiscQueriesImpl(JdbcTemplate aJdbcTemplate) {
this.jdbcTemplate = aJdbcTemplate;
userFavouriteTagsRowMapper = (rs, i) -> new UserFavouriteTags(
rs.getLong("User_Favourite_Tag_Id"),
rs.getLong("User_Id"),
rs.getLong("Tag_Id")
);
}
/**
* Insert into "User_Favourite_Tags"
* @param user - the user
* @param tag - the tag
*/
public void saveUserFavouriteTags(Users user, Tags tag) {
SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(jdbcTemplate)
.withTableName("User_Favourite_Tags")
.usingGeneratedKeyColumns("User_Favourite_Tag_Id");
Map<String, Object> parameters = new HashMap<>();
parameters.put("User_Id", user.getUserId());
parameters.put("Tag_Id", tag.getTagId());
Number id = simpleJdbcInsert.execute(parameters);
}
/**
* Insert into "Users" table
* @param user - the user to insert
*/
public void saveUser(Users user) {
SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(jdbcTemplate)
.withTableName("Users")
.usingGeneratedKeyColumns("User_Id");
Map<String, Object> parameters = new HashMap<>();
parameters.put("User_Id", user.getUserId());
parameters.put("User_First_Name", user.getUserFirstName());
parameters.put("User_Last_Name", user.getUserLastName());
parameters.put("User_Email", user.getUserEmail());
parameters.put("User_Password", user.getUserPassword());
parameters.put("User_Profile_Picture", user.getUserProfilePicture());
parameters.put("Two_Factor_Method_Id", user.getTwoFactorMethod().getTwoFactorMethodId());
parameters.put("User_Reset_Code", user.getUserResetCode());
parameters.put("User_Reset_Code_Expiry", user.getUserResetCodeExpiry());
Number id = simpleJdbcInsert.execute(parameters);
}
/**
* Insert into the "Tags" table
* @param tag - the tag to insert
*/
public void saveTag(Tags tag) {
SimpleJdbcInsert simpleJdbcInsert = new SimpleJdbcInsert(jdbcTemplate)
.withTableName("Tags")
.usingGeneratedKeyColumns("Tag_Id");
Map<String, Object> parameters = new HashMap<>();
parameters.put("Tag_Id", tag.getTagId());
parameters.put("Tag_Name", tag.getTagName());
Number id = simpleJdbcInsert.execute(parameters);
}
/**
* Find all entries into the "User_Favourite_Tags" table
* @return - list of all entries found
*/
public List<UserFavouriteTags> findAllUserFavouriteTags() {
return jdbcTemplate.query(
"select * from User_Favourite_Tags",
userFavouriteTagsRowMapper,
new Object[]{}
);
}
}
package com.example.clientproject.data.misc;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class UserFavouriteTags {
private long userFavouriteTagId;
private long userId;
private long tagId;
}
......@@ -5,6 +5,7 @@ import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
import java.util.Optional;
/**
* JPA Repository for the "Tags" Entity
......@@ -20,4 +21,7 @@ public interface TagsRepo extends JpaRepository<Tags, Long> {
@Query("select t.tagId from Tags t where t.tagId = (select max(t.tagId) from Tags t)")
int findMostRecent();
@Query("select t from Tags t where t.tagName = ?1")
Optional<Tags> findByTagName(String tagName);
}
......@@ -19,4 +19,5 @@ public interface UserStampBoardsRepo extends JpaRepository<UserStampBoards, Long
UserStampBoards save(UserStampBoards userStampBoards);
}
......@@ -3,7 +3,6 @@ package com.example.clientproject.data.users;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import java.util.List;
import java.util.Optional;
/**
......
......@@ -20,14 +20,22 @@ public class ThymeMath {
}
return rewardLocs;
}
public String getRewardTextFromId(List<Rewards> rewardsList, int position){
for (Rewards r : rewardsList){
if(r.getRewardStampLocation() == position){
if(r.getRewardId() == position){
return r.getRewardName();
}
}
return "";
}
public String getRewardTextFromObject(Rewards reward){
return reward.getRewardName();
}
public int getRewardValueFromObject(Rewards reward){
return reward.getRewardStampLocation();
}
}
package com.example.clientproject.service.searches;
import com.example.clientproject.data.users.Users;
import com.example.clientproject.service.dtos.UsersDTO;
import java.util.List;
......@@ -9,4 +10,6 @@ public interface UsersSearch {
List<UsersDTO> findAll();
Optional<UsersDTO> findByEmail(String email);
Users save(Users user);
}
......@@ -37,5 +37,10 @@ public class UsersSearchImpl implements UsersSearch {
return Optional.empty();
}
}
@Override
public Users save(Users user) {
return usersRepo.save(user);
}
}
......@@ -4,6 +4,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
//This can be deleted, class "UserFavouriteTagSaver" is being used
@Service
public class UserFavouriteSaver {
......
package com.example.clientproject.services;
import com.example.clientproject.data.userStampBoards.UserStampBoards;
import com.example.clientproject.data.userStampBoards.UserStampBoardsRepo;
import com.example.clientproject.data.users.UsersRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Service;
import java.sql.ResultSet;
import java.util.List;
import java.util.Map;
@Service
public class UserStampBoardRetriever {
@Autowired
JdbcTemplate jdbc;
@Autowired
UserStampBoardsRepo userRepo;
public int getUserStampPos(int userID, int stampBoardID){
String query = "SELECT User_Stamp_Position FROM user_stamp_boards WHERE User_Id = " + userID + " AND Stamp_Board_Id = " + stampBoardID + ";";
System.out.println(query);
List<Map<String, Object>> rs = jdbc.queryForList(query);
System.out.println((int) rs.get(0).get("User_Stamp_Position"));
return (int) rs.get(0).get("User_Stamp_Position");
}
}
......@@ -9,12 +9,15 @@ import com.example.clientproject.data.userStampBoards.UserStampBoardsRepo;
import com.example.clientproject.data.users.Users;
import com.example.clientproject.data.users.UsersRepo;
import com.example.clientproject.service.Utils.JWTUtils;
import com.example.clientproject.services.UserFavouriteTagSaver;
import com.example.clientproject.services.UserStampBoardRetriever;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
import java.util.NoSuchElementException;
import java.util.Optional;
......@@ -30,14 +33,17 @@ public class BusinessDetails {
private JWTUtils jwtUtils;
private UserStampBoardRetriever userStampService;
public BusinessDetails(ShopsRepo aShopRepo, StampBoardsRepo aStampBoard,
UsersRepo aUsersRepo,
UsersRepo aUsersRepo, UserStampBoardRetriever aUserStampService,
JWTUtils ajwtUtils){
shopsRepo = aShopRepo;
stampRepo = aStampBoard;
usersRepo = aUsersRepo;
jwtUtils = ajwtUtils;
userStampService = aUserStampService;
}
@GetMapping("/businessDetails")
......@@ -64,6 +70,14 @@ public class BusinessDetails {
e.printStackTrace();
return "redirect:/";
}
int UserStampPos = userStampService.getUserStampPos(1, (int) shop.getShopId());
ArrayList <Integer> UserStampPosOBJ = new ArrayList<>();
UserStampPosOBJ.add(UserStampPos);
model.addAttribute("UserStampPos", UserStampPosOBJ);
//model.addAttribute("stampBoard", stampBoard);
model.addAttribute("loggedInUser", user.get());
model.addAttribute("shop", shop);
......
......@@ -60,6 +60,8 @@ public class HomeController {
return "redirect:/login";
}
//System.out.println(shopsRepo.findAll());
List<Shops> allShops = shopsRepo.findAll();
List<Shops> favouriteShops = new ArrayList();
......
package com.example.clientproject.web.controllers;
import com.example.clientproject.data.users.Users;
import com.example.clientproject.service.Utils.JWTUtils;
import com.example.clientproject.services.UserFavouriteTagSaver;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -10,6 +11,7 @@ import org.springframework.web.bind.annotation.RequestParam;
import javax.servlet.http.HttpSession;
import java.util.Arrays;
import java.util.List;
import java.util.Optional;
@Controller
public class SaveUserFavouriteTagController {
......@@ -25,7 +27,11 @@ public class SaveUserFavouriteTagController {
@PostMapping("/selectCategories")
public String selectCategories(@RequestParam String listOfTagIDs, HttpSession session){
//System.out.println(listOfTagIDs);
Optional<Users> user = jwtUtils.getLoggedInUserRow(session);
if(user.isEmpty()){
return "redirect:/login";
}
System.out.println(listOfTagIDs);
//listOfIDs will be a string of each ID separated by "," for example: ",2,6,7,9,14"
List<String> TagID_List = Arrays.asList(listOfTagIDs.split(",")); //splits it into string list for easier handling
for (String TagID : TagID_List){
......
......@@ -58,10 +58,8 @@ public class SignUpController {
Optional<UsersDTO> usersDTOOptional = usersSearch.findByEmail(signUpForm.getNewUserEmail());
// If one does
if (usersDTOOptional.isPresent()) {
// Set a boolean flag to true
boolean emailInUse = true;
// Add it to the model to alert the user
model.addAttribute("emailInUse", emailInUse);
model.addAttribute("emailInUse", true);
// Return to the SignUp page
return "signUp.html";
// Otherwise
......
INSERT INTO Users (User_First_Name, User_Last_Name, User_Email, User_Password, User_Profile_Picture, Two_Factor_Method_Id) VALUES ('Ethan','Allen-Harris','ethanaharris10@gmail.com','$2a$10$nIjlchUua8JPHUcChoSBfu8hdHfCH2QDInC6785FJidGENP22pIly', 'testImage.png', 1);
INSERT INTO Users (User_First_Name, User_Last_Name, User_Email, User_Password, User_Profile_Picture, Two_Factor_Method_Id) VALUES ('Shraya','BELUSKO','ShrayaBELUSKO@email.com','$2a$10$YnDtWkRyd3WfYb5CDHBNx.yfuWPW7dOg86NteaEAyaEmaRywfwueK','testImage.png',1);
INSERT INTO Users (User_First_Name, User_Last_Name, User_Email, User_Password, User_Profile_Picture, Two_Factor_Method_Id) VALUES ('Saleem','GETTI','SaleemGETTI@email.com','$2a$10$YnDtWkRyd3WfYb5CDHBNx.yfuWPW7dOg86NteaEAyaEmaRywfwueK','testImage.png',1);
INSERT INTO Users (User_First_Name, User_Last_Name, User_Email, User_Password, User_Profile_Picture, Two_Factor_Method_Id) VALUES ('Saajid','EFREHN','SaajidEFREHN@email.com','$2a$10$YnDtWkRyd3WfYb5CDHBNx.yfuWPW7dOg86NteaEAyaEmaRywfwueK','testImage.png',2);
......@@ -49,4 +50,16 @@ INSERT INTO Shops (Shop_Name, Shop_Description, Shop_Website, Shop_Earnings, Sho
INSERT INTO Shops (Shop_Name, Shop_Description, Shop_Website, Shop_Earnings, Shop_Countries, Shop_Image, Shop_Active, Stamp_Board_Id, Category_Id) VALUES ('Weimann - Hauck','','WeimannHauck.com','39160','SZ Swaziland','shopPic.png',1,1,1);
INSERT INTO Shops (Shop_Name, Shop_Description, Shop_Website, Shop_Earnings, Shop_Countries, Shop_Image, Shop_Active, Stamp_Board_Id, Category_Id) VALUES ('Douglas, Reichert and Kutch','','DouglasReichertandKutch.com','2093','SC Seychelles','shopPic.png',1,1,1);
INSERT INTO Shops (Shop_Name, Shop_Description, Shop_Website, Shop_Earnings, Shop_Countries, Shop_Image, Shop_Active, Stamp_Board_Id, Category_Id) VALUES ('Schoen Group','','SchoenGroup.com','10783','FR France','shopPic.png',0,1,1);
INSERT INTO Shops (Shop_Name, Shop_Description, Shop_Website, Shop_Earnings, Shop_Countries, Shop_Image, Shop_Active, Stamp_Board_Id, Category_Id) VALUES ('Homenick and Sons','','HomenickandSons.com','14948','SM San Marino','shopPic.png',0,1,1);
INSERT INTO Shops (Shop_Name, Shop_Description, Shop_Website, Shop_Earnings, Shop_Countries, Shop_Image, Shop_Active, Stamp_Board_Id, Category_Id) VALUES ('Homenick and Sons','The best burrito place in New York, our owner Benjamin has moved to New York to bring over his families techniques and recipes that have been blessing tastebuds of customers for years.user_stamp_boards ','HomenickandSons.com','14948','SM San Marino','shopPic.png',0,1,1);
INSERT INTO stamp_boards (Stamp_Board_Size, Stamp_Board_Colour, Stamp_Board_Icon) VALUES (14, "#ffc5c5", "imgs/burrito.png");
INSERT INTO rewards (Reward_Name, Reward_Stamp_Location, Stamp_Board_Id) VALUES ("Free medium Burrito", 4, 2);
INSERT INTO rewards (Reward_Name, Reward_Stamp_Location, Stamp_Board_Id) VALUES ("Free delivery", 7, 2);
INSERT INTO rewards (Reward_Name, Reward_Stamp_Location, Stamp_Board_Id) VALUES ("2 for 1 deal", 12, 2);
INSERT INTO Shops (Shop_Name, Shop_Description, Shop_Website, Shop_Earnings, Shop_Countries, Shop_Image, Shop_Active, Stamp_Board_Id, Category_Id) VALUES ('Bens Burritos','Our owner Benjamin has taked his family recipes and techniques that have been passed down for generations in mexico to come bless the tastebuds of the USA, land of freedom. Come and get tasty burritos delivered to your home!','BensBurritos.com','13708','SM San Marino','imgs/benburrito.png',0,2,2);
SET FOREIGN_KEY_CHECKS=0;
INSERT INTO user_stamp_boards (User_Id, Stamp_Board_Id, User_Stamp_Position) VALUES (1, 12, 4);
SET FOREIGN_KEY_CHECKS=1;
......@@ -91,7 +91,6 @@ img.stamp{
height: auto;
display: flex;
flex-direction: column;
background-color: purple;
}
.stampNavBar{
......@@ -133,12 +132,21 @@ img.stamp{
.reward {
border-top-style: solid;
border-top-width: 1px;
height: 75px;
height: 125px;
}
.buttonRewardNotReady{
background-color: rgb(216, 216, 216);
float: right;
margin-top: 10px;
font-weight: bold;
}
.buttonRewardisReady{
background-color: #48c774;
float: right;
margin-top: 10px;
font-weight: bold;
}
.stampProgressText{
......@@ -149,6 +157,9 @@ img.stamp{
.reward-text{
font-size: 15px;
margin: 13px;
width: 200;
font-weight: bold;
float: left;
}
.marginBottom7px{
......
src/main/resources/static/imgs/benburrito.png

77.9 KiB

src/main/resources/static/imgs/burrito.png

36.9 KiB

0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment