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

Merge branch 'issueFive' into 'develop'

Added partial saving, new shop is created but info needs to be saved e.g....

See merge request !14
parents 3a2df964 03fe81d7
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),!22Branch Update,!17Removal of "AUTO_INCREMENT" on AdminTypes id field since there will only ever...,!16Develop,!14Added partial saving, new shop is created but info needs to be saved e.g....
Showing
with 377 additions and 1032 deletions
......@@ -10,6 +10,7 @@ public class SecurityConfig extends WebSecurityConfigurerAdapter {
@Override
protected void configure(HttpSecurity security) throws Exception
{
security.cors().and().csrf().disable();
security.httpBasic().disable();
}
}
\ No newline at end of file
......@@ -24,6 +24,7 @@ public class Shops {
@GeneratedValue(strategy=GenerationType.IDENTITY)
private String shopId;
private String shopName;
private String shopDescription;
private String shopWebsite;
private int shopEarnings;
private String shopImage;
......@@ -41,9 +42,10 @@ public class Shops {
* @param countries - shop countries
* @param active - shop active status
*/
public Shops(String name, String website, int earnings,
public Shops(String name, String website, String description, int earnings,
String image, String countries, boolean active) {
this.shopName = name;
this.shopDescription = description;
this.shopWebsite = website;
this.shopEarnings = earnings;
this.shopImage = image;
......
package com.example.clientproject.services;
import com.example.clientproject.web.forms.BusinessRegisterForm;
import lombok.AllArgsConstructor;
import lombok.Value;
import java.util.ArrayList;
@Value
@AllArgsConstructor
public class BusinessRegisterDTO {
String business_register_url;
String business_register_name;
String business_register_desc;
//String businessCategory;
//ArrayList<String> businessTags;
//String instagram;
//String facebook;
//String twitter;
//String tiktok;
int earnings;
public BusinessRegisterDTO(BusinessRegisterForm brf){
this(
brf.getBusiness_register_url(),
brf.getBusiness_register_name(),
brf.getBusiness_register_desc(),
//brf.getBusinessCategory(),
//brf.getBusinessTags(),
//brf.getInstagram(),
//brf.getFacebook(),
//brf.getTwitter(),
//brf.getTiktok(),
brf.getEarnings()
);
}
}
package com.example.clientproject.services;
import com.example.clientproject.data.shops.Shops;
import com.example.clientproject.data.shops.ShopsRepo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
@Service
public class BusinessRegisterSaver {
@Autowired
ShopsRepo shopsRepo;
public void save(BusinessRegisterDTO business){
Shops shop = new Shops(business.getBusiness_register_name(),
business.getBusiness_register_url(),
business.getBusiness_register_desc(),
business.getEarnings(),
"shopPic.png",
"UK United Kingdom",
false);
shopsRepo.save(shop);
System.out.println(shopsRepo.findByShopName(business.getBusiness_register_name()));
}
}
package com.example.clientproject.web.controllers;
import com.example.clientproject.services.BusinessRegisterDTO;
import com.example.clientproject.services.BusinessRegisterSaver;
import com.example.clientproject.web.forms.BusinessRegisterForm;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import java.util.ArrayList;
import java.util.Arrays;
......@@ -10,10 +15,25 @@ import java.util.Arrays;
@Controller
public class SignInController {
@GetMapping("/register")
private BusinessRegisterSaver saveBusiness;
@Autowired
public SignInController(BusinessRegisterSaver sBusiness){
saveBusiness = sBusiness;
}
@PostMapping("/businessRegister")
public String submitBusinessInfo(BusinessRegisterForm brf){
saveBusiness.save(new BusinessRegisterDTO(brf));
//System.out.println(brf.getBusinessTags());
return "registerbusiness.html";
}
@GetMapping("/businessRegister")
public String registerBusiness(Model model){
ArrayList<String> categories = new ArrayList<>(Arrays.asList("Food and drink","Animals","Alcohol"));
model.addAttribute("categories", categories);
return "registerbusiness.html";
}
}
package com.example.clientproject.web.forms;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.ArrayList;
import java.util.Arrays;
@Data
@AllArgsConstructor
@NoArgsConstructor
public class BusinessRegisterForm {
String business_register_url;
String business_register_name;
String business_register_desc;
String businessCategory;
ArrayList<String> businessTags;
String instagram;
String facebook;
String twitter;
String tiktok;
int earnings;
public void setTags(String tempTags){
this.businessTags = new ArrayList(Arrays.asList(tempTags.split(",")));
}
}
This diff is collapsed.
......@@ -113,8 +113,8 @@ def companyPopulator(amount):
countryi = random.randint(0, len(countries)-1)
stringInsert = '"' + companyNames[i] + '","' + websiteArray[i] + '","' + str(earnings) + '","' + countries[countryi] + '",' + str(random.randint(1, 2))
insertArray.append(createInsert(stringInsert, "Shops", "Shop_Name, Shop_Website, Shop_Earnings, Shop_Countries, Shop_Active"))
stringInsert = '"' + companyNames[i] + '","' + "" + '","' + websiteArray[i] + '","' + str(earnings) + '","' + countries[countryi] + '",' + str(random.randint(1, 2))
insertArray.append(createInsert(stringInsert, "Shops", "Shop_Name, Shop_Description, Shop_Website, Shop_Earnings, Shop_Countries, Shop_Active"))
return insertArray
......
SET MODE MYSQL;
SET IGNORECASE=TRUE;
-- -----------------------------------------------------
-- -----------------------------------------------------
-- Schema mydb
......@@ -25,6 +22,7 @@ CREATE TABLE IF NOT EXISTS `mydb`.`Two_Factor_Methods` (
CREATE TABLE IF NOT EXISTS `mydb`.`Shops` (
`Shop_Id` INT NOT NULL AUTO_INCREMENT,
`Shop_Name` VARCHAR(45) NOT NULL,
`Shop_Description` VARCHAR(250) NOT NULL,
`Shop_Website` VARCHAR(45) NOT NULL,
`Shop_Earnings` INT NOT NULL,
`Shop_Countries` VARCHAR(150) NOT NULL,
......@@ -237,7 +235,7 @@ CREATE TABLE IF NOT EXISTS `mydb`.`User_Stamp_Boards` (
INSERT INTO two_factor_methods (`Two_Factor_Method_Id`, `Two_Factor_Method_Name`) VALUES (1, 'None');
INSERT INTO two_factor_methods (`Two_Factor_Method_Id`, `Two_Factor_Method_Name`) VALUES (2, 'GAuth');
INSERT INTO Shops (Shop_Name, Shop_Website, Shop_Earnings, Shop_Countries, Shop_Active) VALUES ('','',0,'',0);
INSERT INTO Shops (Shop_Name, Shop_Description, Shop_Website, Shop_Earnings, Shop_Countries, Shop_Active) VALUES ('','','',0,'',0);
INSERT INTO Admin_Types (Admin_Type_Id, Admin_Type_Name) VALUES (1,'User');
INSERT INTO Admin_Types (Admin_Type_Id, Admin_Type_Name) VALUES (2,'Business Admin');
......
......@@ -78,6 +78,18 @@ url-centering{
#categoryContainer{
width:100%;
display: flex;
flex-direction: row;
flex-direction: column;
justify-content: center;
align-items: center;
}
.socialInput{
width:100%;
margin-right:5%;
}
.socialContainer{
display: flex;
flex-direction: row;
justify-content: flex-start;
}
\ No newline at end of file
var modalStage = 0
var urlInput, urlPrefixInput, nameInput, descInput = null;
function htmlDecode(input) {
var doc = new DOMParser().parseFromString(input, "text/html");
return doc.documentElement.textContent;
}
function setLoadingBar(){
let progressAmount = (modalStage+1)*20
......@@ -11,19 +17,61 @@ function setLoadingBar(){
}
function progress(){
urlInput = document.getElementById("business_register_url");
urlPrefixInput = document.getElementById("business_register_url_prefix");
nameInput = document.getElementById("business_register_name");
descInput = document.getElementById("business_register_desc");
if(document.getElementById("forwardButton").innerHTML == "Done"){
document.getElementById("businessForm").submit();
}
if(modalStage==3) {
document.getElementById("forwardButton").innerHTML = "Done"
}
if(modalStage<5){
modalStage += 1
if(modalStage == 1){
nameInput.parentElement.classList.add("is-loading")
descInput.parentElement.classList.add("is-loading")
getBusinessInfo(urlPrefixInput.value + urlInput.value);
}
let currentStageId = "modal_page" + modalStage.toString()
let nextStageId = "modal_page"+ (modalStage+1).toString()
let newHeight = (document.getElementById(nextStageId).offsetHeight)+40
document.getElementById("modal_container").style.height = newHeight.toString()+"px"
console.log(currentStageId)
console.log(document.getElementById(currentStageId))
console.log(document.getElementById(currentStageId).style.transform)
document.getElementById(currentStageId.toString()).style.transform = "translateX(-150%)"
document.getElementById(nextStageId.toString()).style.transform = "translateX(0%)"
}
setLoadingBar()
}
function getBusinessInfo(url){
fetch("http://localhost:8080/infoExtract?url=" + url)
.then(response => response.json())
.then(data => handleInfo(data));
}
function handleInfo(data){
nameInput.parentElement.classList.remove("is-loading")
descInput.parentElement.classList.remove("is-loading")
let name = data.site_name;
let url = data.url;
let description = data.description;
if(description !== undefined){
description = htmlDecode(unescape(description));
}
if(name !== undefined){
nameInput.value = name;
}
if(description !== undefined){
descInput.value = description;
}
}
\ No newline at end of file
......@@ -20,7 +20,6 @@
<div id="ShopHubNav" class="navbar-menu">
<div class="navbar-start">
<a class="navbar-item" href="/">Dashboard</a>
<a class="navbar-item" href="/register">Register</a>
</div>
<div class="navbar-end">
......@@ -35,7 +34,7 @@
<span class="icon mr-2"><i class="fas fa-cog"></i></span>
Settings
</a>
<a class="navbar-item">
<a class="navbar-item" href="/businessRegister">
<span class="icon mr-2"><i class="fas fa-briefcase"></i></span>
Business
</a>
......
......@@ -28,56 +28,133 @@
<div id="progressBar" class="progressBar">
<div style="width:20%"></div>
</div>
<form id="businessForm" action="/businessRegister" th:method="post">
<section class="modal-card-body url-centering" id="modal_container">
<div id="modal_page1" class="modal_page">
<h5 class="title is-5" style="text-align:center">Enter your shop URL</h5>
<p class="control has-icons-left" style="min-width:50%; width:70%; margin:auto">
<input class="input" type="url" placeholder="Business URL" style="width:100%; align-content:center">
<span class="icon is-small is-left">
<i class="fas fa-link"></i>
</span>
</p>
</div>
<div id="modal_page2" class="modal_page">
<h5 class="title is-5" style="text-align:center">Shop Name</h5>
<p class="control has-icons-left" style="min-width:50%; width:70%; margin:auto">
<input class="input" style="width:100%; align-content:center">
<span class="icon is-small is-left">
<i class="fas fa-store"></i>
</span>
</p>
<h5 class="title is-5" style="text-align:center">Description</h5>
<p class="control has-icons-left" style="min-width:50%; width:70%; margin:auto">
<textarea class="textarea"></textarea>
</p>
</div>
<div id="modal_page3" class="modal_page">
<h5 class="title is-5" style="text-align:center; margin-bottom: 2%">Choose a category</h5>
<div id="categoryContainer">
<div class="dropdown is-hoverable">
<div class="dropdown-trigger">
<button class="button" aria-haspopup="true" aria-controls="dropdown-menu4">
<span>Categories</span>
<span class="icon is-small">
<i class="fas fa-angle-down" aria-hidden="true"></i>
</span>
</button>
</div>
<div class="dropdown-menu" id="dropdown-menu4" role="menu">
<div class="dropdown-content">
<div th:each="category: ${categories}" class="dropdown-item">
<a th:text="${category}"></a>
</div>
</div>
<div id="modal_page1" class="modal_page">
<h5 class="title is-5" style="text-align:center">Enter your shop URL</h5>
<div class="field has-addons" style="display: flex;justify-content: center">
<p class="control">
<span class="select">
<select id="business_register_url_prefix">
<option>https://</option>
<option>http://</option>
</select>
</span>
</p>
<p class="control">
<input class="input" type="url" name="business_register_url" placeholder="Business URL" style="width:100%; align-content:center"
id="business_register_url">
</p>
</div>
</div>
<div id="modal_page2" class="modal_page">
<h5 class="title is-5" style="text-align:center">Shop Name</h5>
<p class="control has-icons-left" style="min-width:50%; width:70%; margin:auto">
<input class="input" style="width:100%; align-content:center" id="business_register_name" name="business_register_name">
<span class="icon is-small is-left">
<i class="fas fa-store"></i>
</span>
</p>
<h5 class="title is-5" style="text-align:center; margin-bottom:5%; margin-top:5%">Description</h5>
<p class="control has-icons-left" style="min-width:50%; width:70%; margin:auto">
<textarea class="textarea" name="business_register_desc" id="business_register_desc"></textarea>
</p>
</div>
<div id="modal_page3" class="modal_page">
<h5 class="title is-5" style="text-align:center; margin-bottom: 2%">Choose a category</h5>
<div id="categoryContainer">
<div class="select" name="businessCategory">
<select>
<option th:each="category: ${categories}" th:text="${category}"></option>
</select>
</div>
</div>
<h5 class="title is-5" style="text-align:center; margin-bottom: 2%">Add tags that describe your business</h5>
<div style="width:100%;">
<!-- Need to fix this, shouldn't be full width of modal -->
<textarea name="businessTags" maxlength="50" style="width:75%;" class="textarea" rows="2"></textarea>
</div>
</div>
<div id="modal_page4" class="modal_page">
<h5 class="title is-5" style="text-align:center">Social Media Links</h5>
</div>
<div class="socialContainer">
<span class="icon is-large is-left">
<i class="fab fa-instagram"></i>
</span>
<div class="field has-addons" style="display: flex;justify-content: center">
<p class="control">
<input value="instagram.com/" class="input" disabled>
</p>
<p class="control">
<input class="input" name="instagram" type="url" style="width:100%; align-content:center">
</p>
</div>
<!-- <input class="input socialInput">-->
</div>
<div class="socialContainer">
<span class="icon is-large is-left">
<i class="fab fa-facebook-f"></i>
</span>
<div class="field has-addons" style="display: flex;justify-content: center">
<p class="control">
<input value="facebook.com/" class="input" disabled>
</p>
<p class="control">
<input class="input" name="facebook" type="url" style="width:100%; align-content:center">
</p>
</div>
<!-- <input class="input socialInput">-->
</div>
<div class="socialContainer">
<span class="icon is-large is-left">
<i class="fab fa-twitter"></i>
</span>
<div class="field has-addons" style="display: flex;justify-content: center">
<p class="control">
<input value="twitter.com/" class="input" disabled>
</p>
<p class="control">
<input class="input" name="twitter" type="url" style="width:100%; align-content:center">
</p>
</div>
<!-- <input class="input socialInput">-->
</div>
<div class="socialContainer">
<span class="icon is-large is-left">
<i class="fab fa-tiktok"></i>
</span>
<div class="field has-addons" style="display: flex;justify-content: center">
<p class="control">
<input value="tiktok.com/@" class="input" disabled>
</p>
<p class="control">
<input class="input" name="tiktok" type="url" style="width:100%; align-content:center">
</p>
</div>
<!-- <input class="input socialInput">-->
</div>
</div>
<div id="modal_page5" class="modal_page">
<h5 class="title is-5" style="text-align:center">Average Monthly Sales</h5>
<div class="socialContainer">
<p class="control has-icons-left" style="min-width:50%; width:70%; margin:auto">
<span class="icon is-large is-left">
<i class="fas fa-pound-sign"></i>
</span>
<input class="input socialInput" name="earnings" style="margin-bottom:5%">
</p>
</div>
<p class="subtitle is-5" style="text-align: center; font-size:10px">
We need to know this, so we can accurately start you on the correct pricing tier
</p>
</div>
</section>
<footer class="modal-card-foot modal-footer">
<button class="button is-success" onclick="progress();">Next</button>
<button id="forwardButton" class="button is-success" onclick="progress();">Next</button>
</footer>
</form>
</div>
</div>
</body>
......
......@@ -27,7 +27,7 @@ public class ShopsTests {
@Test
public void shouldGet12ShopsAfterInsert() throws Exception {
Shops newShop = new Shops("", "", 0, "", "", true);
Shops newShop = new Shops("", "", "", 0, "", "", true);
Shops shop = shopsRepo.save(newShop);
List<Shops> shopsList = shopsRepo.findAll();
......
......@@ -45,7 +45,7 @@ public class UserPermissionsTests {
@Test
public void shouldGet158PermissionsAfterInsert() throws Exception {
Shops newShop = new Shops("", "", 0, "", "", true);
Shops newShop = new Shops("", "", "", 0, "", "", true);
shopsRepo.save(newShop);
TwoFactorMethods twoFactorMethods = twoFactorMethodsRepo.findByTwoFactorMethodId(1).get();
DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss");
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment