Skip to content
Snippets Groups Projects
Commit ff3199f4 authored by Joshua Gill's avatar Joshua Gill
Browse files

Merge branch 'develop' into 'issueEleven'

Branch update

See merge request !44
parents 19579c09 56d4ee74
No related branches found
No related tags found
5 merge requests!56tags will be saved to userFavTags table (needs user ID of current logged in user),!50Merging for latest changes,!46Develop,!45Issue Complete, merging branch,!44Branch update
Showing
with 156 additions and 25 deletions
......@@ -25,7 +25,7 @@ import java.util.List;
public class Shops {
@Id
@GeneratedValue(strategy=GenerationType.IDENTITY)
private int shopId;
private long shopId;
private String shopName;
private String shopDescription;
private String shopWebsite;
......
......@@ -35,7 +35,10 @@ public class BusinessRegisterSaver {
@Autowired
JdbcTemplate jdbc;
public void save(BusinessRegisterDTO business){
@Autowired
LinkUserShop linkShop;
public void save(BusinessRegisterDTO business, long userId){
StampBoards stampBoard = stampBoards.findById(1L).get();
Categories categories = categoriesRepo.findById(1L).get();
......@@ -69,11 +72,14 @@ public class BusinessRegisterSaver {
jdbc.execute(query);
}
linkShop.linkUserShop(shop.getShopId(), userId);
//System.out.println(shop.getShopId());
//System.out.println(tagsRepo.findAll());
System.out.println(shopsRepo.findByShopName(business.getBusiness_register_name()).get().getShopName());
//System.out.println(shopsRepo.findByShopName(business.getBusiness_register_name()).get().getShopName());
}
}
package com.example.clientproject.services;
import com.example.clientproject.data.adminTypes.AdminTypes;
import com.example.clientproject.data.adminTypes.AdminTypesRepo;
import com.example.clientproject.data.shops.Shops;
import com.example.clientproject.data.shops.ShopsRepo;
import com.example.clientproject.data.userPermissions.UserPermissions;
import com.example.clientproject.data.userPermissions.UserPermissionsRepo;
import com.example.clientproject.data.users.Users;
import com.example.clientproject.data.users.UsersRepo;
import org.springframework.stereotype.Service;
@Service
public class LinkUserShop {
UsersRepo userRepo;
ShopsRepo shopsRepo;
AdminTypesRepo adminTypesRepo;
UserPermissionsRepo userPermissionsRepo;
public LinkUserShop(UsersRepo aUsersRepo,
ShopsRepo aShopsRepo,
AdminTypesRepo anAdminTypesRepo,
UserPermissionsRepo aUserPermissionsRepo){
userRepo = aUsersRepo;
shopsRepo = aShopsRepo;
adminTypesRepo = anAdminTypesRepo;
userPermissionsRepo = aUserPermissionsRepo;
}
public void linkUserShop(long shopId, long userID){
try {
Users user = userRepo.findById(userID).get();
Shops shop = shopsRepo.getById(shopId);
AdminTypes adminType = adminTypesRepo.getById(2L);
UserPermissions link = new UserPermissions(user, shop, adminType);
userPermissionsRepo.save(link);
}catch(Exception e){
e.printStackTrace();
}
}
}
......@@ -10,9 +10,9 @@ public class UserFavouriteDTO {
long userId;
long shopId;
public UserFavouriteDTO(UserFavouriteForm urf){
public UserFavouriteDTO(UserFavouriteForm urf, long userId){
this(
urf.getUserId(),
userId,
urf.getShopId()
);
}
......
......@@ -31,7 +31,7 @@ public class registerUserServiceStatic implements registerUserService{
LocalDateTime.now().format(formatter), twoFactorMethods);
usersRepo.save(newUser);
System.out.println(usersRepo.findById(newUser.getUserId()));
//System.out.println(usersRepo.findById(newUser.getUserId()));
}
}
package com.example.clientproject.web.controllers;
import com.example.clientproject.data.shops.Shops;
import com.example.clientproject.data.shops.ShopsRepo;
import com.example.clientproject.data.stampBoards.StampBoards;
import com.example.clientproject.data.stampBoards.StampBoardsRepo;
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 java.util.List;
@Controller
public class BusinessDetails {
private ShopsRepo shopsRepo;
private StampBoardsRepo stampRepo;
public BusinessDetails(ShopsRepo aShopRepo, StampBoardsRepo aStampBoard){
shopsRepo = aShopRepo;
stampRepo = aStampBoard;
}
@GetMapping("/businessDetails")
public String getBusiness(@RequestParam(value = "shopId") int shopId, Model model){
StampBoards stampBoard;
Shops shop;
try {
shop = shopsRepo.getById(Long.valueOf(shopId));
//stampBoard = stampRepo.findById(Long.valueOf(shopId)).get();
}catch(Exception e){
e.printStackTrace();
return "redirect:/";
}
//model.addAttribute("stampBoard", stampBoard);
model.addAttribute("shop", shop);
return "shopDetails.html";
}
}
......@@ -2,6 +2,7 @@ package com.example.clientproject.web.controllers;
import com.example.clientproject.data.shops.Shops;
import com.example.clientproject.data.shops.ShopsRepo;
import com.example.clientproject.service.Utils.JWTUtils;
import com.example.clientproject.service.searches.UsersSearch;
import com.example.clientproject.services.BusinessRegisterSaver;
import com.example.clientproject.services.UserFavouriteDTO;
......@@ -12,6 +13,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import javax.servlet.http.HttpSession;
import java.util.ArrayList;
import java.util.List;
......@@ -30,8 +32,7 @@ public class HomeController {
}
@GetMapping({"/", "dashboard"})
public String index(Model model) throws Exception{
loggedIn=true;
public String index(Model model, HttpSession session) throws Exception{
if (!loggedIn) {
model.addAttribute("loggedIn", loggedIn);
return "redirect:/login";
......@@ -43,8 +44,8 @@ public class HomeController {
List<Shops> normalShops = new ArrayList();
for(Shops s : allShops){
UserFavouriteForm uff = new UserFavouriteForm(2,s.getShopId());
if(toggleFavourite.alreadyInDb(new UserFavouriteDTO(uff))){
UserFavouriteForm uff = new UserFavouriteForm(s.getShopId());
if(toggleFavourite.alreadyInDb(new UserFavouriteDTO(uff, JWTUtils.getLoggedInUserId(session).get()))){
favouriteShops.add(s);
}else{
normalShops.add(s);
......
......@@ -7,11 +7,19 @@ import org.springframework.web.bind.annotation.RequestParam;
@Controller
public class Redirect {
/**
* Redirects user to new url, workaround for models not loading properly on redirect to same
* controller.
* @param url, the page to redirect to (e.g. /businessRegister), submitted like:
* /redirect?url=<page>
* @return Redirection.
*/
@GetMapping("/redirect")
public String redirect(@RequestParam(name="url") String url){
try{
return "redirect:/"+url;
}catch(Exception e){
e.printStackTrace();
return "redirect:/";
}
}
......
......@@ -40,12 +40,12 @@ public class SignInController {
}
@PostMapping("/businessRegister")
public String submitBusinessInfo(@Valid BusinessRegisterForm brf, BindingResult bindingResult){
public String submitBusinessInfo(@Valid BusinessRegisterForm brf, BindingResult bindingResult, HttpSession session){
if (bindingResult.hasErrors()) {
System.out.println(bindingResult.getAllErrors());
return "registerbusiness.html";
}
saveBusiness.save(new BusinessRegisterDTO(brf));
saveBusiness.save(new BusinessRegisterDTO(brf), JWTUtils.getLoggedInUserId(session).get());
return "redirect:/redirect?url=businessRegister";
}
......@@ -86,7 +86,8 @@ public class SignInController {
@PostMapping("login")
public String signInChecks(@Valid LoginForm loginForm,
BindingResult bindingResult,
Model model) {
Model model,
HttpSession session) {
if (bindingResult.hasErrors()) {
model.addAttribute("loggedIn", loggedIn);
......@@ -106,6 +107,9 @@ public class SignInController {
// If they match, set the loggedIn flag to true
if (passwordMatch) {
JWTUtils.makeUserJWT(
(int) usersDTOOptional.get().getUserId(),
session);
loggedIn = true;
// Otherwise, throw an exception with the correct error message
} else {
......
......@@ -30,10 +30,6 @@ public class selectCategoriesControllers {
public String selectCategories(Model model){
List<Tags> allTags = getTagService.findAll();
model.addAttribute("allTags", allTags);
for (Tags allTag : allTags) {
System.out.println(allTag);
}
System.out.println("Test");
return("selectCategories");
}
}
......@@ -38,7 +38,6 @@ public class BusinessRegisterForm {
int earnings;
public void setBusinessTags(String tempTags){
System.out.println(tempTags);
this.businessTags = new ArrayList(Arrays.asList(tempTags.split(",")));
}
}
......@@ -8,7 +8,6 @@ import lombok.NoArgsConstructor;
@AllArgsConstructor
@NoArgsConstructor
public class UserFavouriteForm {
long userId;
long shopId;
......
package com.example.clientproject.web.restControllers;
import com.example.clientproject.service.Utils.JWTUtils;
import com.example.clientproject.service.searches.UsersSearch;
import com.example.clientproject.services.*;
import com.example.clientproject.web.forms.UserFavouriteForm;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;
@RestController
public class BusinessFavouriter {
......@@ -26,8 +29,8 @@ public class BusinessFavouriter {
* @return ERROR or OK depending on whether it any errors are thrown.
*/
@PostMapping("/favouriteBusiness")
public String favouriteBusiness(UserFavouriteForm uff){
UserFavouriteDTO ufDTO = new UserFavouriteDTO(uff);
public String favouriteBusiness(UserFavouriteForm uff, HttpSession session){
UserFavouriteDTO ufDTO = new UserFavouriteDTO(uff, JWTUtils.getLoggedInUserId(session).get());
try{
if(toggleFavourite.alreadyInDb(ufDTO)){
deleteFavourite.delete(ufDTO);
......
......@@ -57,6 +57,8 @@ def namePopulator(amount, userType):
salt = "EXAMPLESALT"
stdPassword = hashlib.sha256(salt.encode() + b'password123').hexdigest()
stdPassword = "$2a$10$YnDtWkRyd3WfYb5CDHBNx.yfuWPW7dOg86NteaEAyaEmaRywfwueK"
profilePic = "testImage.png"
insertArray = []
......@@ -113,8 +115,8 @@ def companyPopulator(amount):
countryi = random.randint(0, len(countries)-1)
stringInsert = '"' + companyNames[i] + '","' + "" + '","' + websiteArray[i] + '","' + str(earnings) + '","' + countries[countryi] + '","' + "shopPic.png" + '",' + str(random.randint(0, 1))
insertArray.append(createInsert(stringInsert, "Shops", "Shop_Name, Shop_Description, Shop_Website, Shop_Earnings, Shop_Countries, Shop_Image, Shop_Active"))
stringInsert = '"' + companyNames[i] + '","' + "" + '","' + websiteArray[i] + '","' + str(earnings) + '","' + countries[countryi] + '","' + "shopPic.png" + '",' + str(random.randint(0, 1)) + ',' + str(1)
insertArray.append(createInsert(stringInsert, "Shops", "Shop_Name, Shop_Description, Shop_Website, Shop_Earnings, Shop_Countries, Shop_Image, Shop_Active, Stamp_Board_Id"))
return insertArray
......
......@@ -7,7 +7,7 @@ function favouriteBusiness(e,shopId){
}
var xhttp = new XMLHttpRequest();
let params= 'userId=' + "2" + "&shopId=" + shopId
let params= "shopId=" + shopId
xhttp.open("POST", '/favouriteBusiness', true);
xhttp.setRequestHeader("Content-type", "application/x-www-form-urlencoded");
xhttp.onload = function() {
......@@ -23,4 +23,8 @@ function favouriteBusiness(e,shopId){
xhttp.send(params);
}
function redirect(shopId){
location.href = "businessDetails?shopId="+shopId;
}
\ No newline at end of file
......@@ -27,7 +27,7 @@
<p th:text="${reward_amount}"></p>
</div>
<div class="level-right">
<button class="button is-rounded gradient">
<button class="button is-rounded gradient" th:onclick="'redirect('+ ${shopId} + ')'">
View Shop
<span class="icon is-small is-left ml-1">
<i class="fas fa-arrow-right"></i>
......
<!DOCTYPE html>
<html lang="en">
<head>
<title>ShopHub | Dashboard</title>
<link th:replace="fragments/libs.html :: bulma"/>
<link th:replace="fragments/libs.html :: fa"/>
<link th:replace="fragments/nav.html :: nav-css"/>
</head>
<body>
<div th:replace="fragments/nav.html :: nav"></div>
<div>
<h1 th:text="${shop.shopName}"></h1>
<p th:text="${shop.shopDescription}"></p>
<p th:text="${shop.shopWebsite}"></p>
<p th:text="${shop.shopEarnings}"></p>
<p th:text="${shop.shopCountries}"></p>
<img th:src="${shop.shopImage}" alt="">
</div>
</body>
</html>
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment