Skip to content
Snippets Groups Projects
Commit 4185db8b authored by Ethan Allen-Harris's avatar Ethan Allen-Harris
Browse files

Added javaDoc and added a working test for changing shop activity

parent 20570be8
No related branches found
No related tags found
4 merge requests!114LoggingService service class, new method to add a log to the "Logs" table when...,!88fixed small bug,!85fixed small bug,!81merging branch into develop
......@@ -13,6 +13,11 @@ public class ShopActiveService {
@Autowired
JdbcTemplate jdbc;
/**
* @param shopId - uses shopId to select which shop will have its active field checked
* @return - an int of Shop activity 1 = active || 0 = not active
*/
public int isShopActive(Integer shopId){
String query = "SELECT Shop_Active FROM shops WHERE Shop_Id = " + shopId + ";";
try{
......@@ -25,6 +30,11 @@ public class ShopActiveService {
}
}
/**
* @param shopId - uses shopId to select which shop will have its active field changed/updated
* @param active - will either be 1 or 0 and will update shops "Shop_Active" field accordingly
*/
public void updateShopActive(Integer shopId, Integer active){
if(active == 0 || active == 1){ //only allows active values of 0 or 1
String query = "UPDATE shops SET Shop_Active = " + active + " WHERE Shop_Id = " + shopId + ";";
......
package com.example.clientproject.data;
import com.example.clientproject.data.categories.Categories;
import com.example.clientproject.data.shops.Shops;
import com.example.clientproject.data.shops.ShopsRepo;
import com.example.clientproject.services.ShopActiveService;
import org.jetbrains.annotations.ApiStatus;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.data.jdbc.DataJdbcTest;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.jdbc.Sql;
import java.util.List;
import static org.junit.jupiter.api.Assertions.assertEquals;
@SpringBootTest
@Sql(scripts={"/schema-test-h2.sql","/script-test-h2.sql"})
@ActiveProfiles("h2")
@DirtiesContext
public class ShopActivityTests {
@Autowired
JdbcTemplate jdbc;
@Autowired
private ShopActiveService shopActiveService;
@Autowired
ShopsRepo shopsRepo;
@Test
public void activeShopsDecreasedBy1AfterMethodCalled(){
List<Shops> activeShopsListBeforeChange = shopsRepo.findActiveShops();
shopActiveService.updateShopActive(6, 0);
List<Shops> activeShopsListAfterChange = shopsRepo.findActiveShops();
assertEquals(activeShopsListBeforeChange.size()-1, activeShopsListAfterChange.size());
//size after change should be equal to size before change minus one
}
}
......@@ -112,6 +112,8 @@ ENGINE = InnoDB;
CREATE TABLE IF NOT EXISTS `Stamp_Boards` (
`Stamp_Board_Id` INT NOT NULL AUTO_INCREMENT,
`Stamp_Board_Size` INT NOT NULL,
`Stamp_Board_Colour` VARCHAR(7),
`Stamp_Board_Icon` varchar(255),
PRIMARY KEY (`Stamp_Board_Id`))
ENGINE = InnoDB;
......
......@@ -40,13 +40,15 @@ INSERT INTO User_Permissions (User_ID, Shop_ID, Admin_Type_Id) VALUES (19,1,2);
INSERT INTO Users (User_First_Name, User_Last_Name, User_Email, User_Password, User_Profile_Picture, Two_Factor_Method_Id) VALUES ('Amatul','PINNER','AmatulPINNER@email.com','$2a$10$YnDtWkRyd3WfYb5CDHBNx.yfuWPW7dOg86NteaEAyaEmaRywfwueK','testImage.png',2);
INSERT INTO Shops (Shop_Name, Shop_Description, Shop_Website, Shop_Earnings, Shop_Countries, Shop_Image, Shop_Active, Stamp_Board_Id, Category_Id) VALUES ('Roob Group','','RoobGroup.com','24811','CD Congo The Democratic Republic Of The','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 ('Marks - Durgan','','MarksDurgan.com','18079','EG Egypt','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 ('Fay - Koepp','','FayKoepp.com','12140','KP Korea Democratic Peoples Republic Of','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 ('Roob Group','','RoobGroup.com','24811','CD Congo The Democratic Republic Of The','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 ('Marks - Durgan','','MarksDurgan.com','18079','EG Egypt','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 ('Fay - Koepp','','FayKoepp.com','12140','KP Korea Democratic Peoples Republic Of','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 ('Mueller, Lueilwitz and Roberts','','MuellerLueilwitzandRoberts.com','20157','CZ Czech Republic','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 ('Balistreri, Aufderhar and Huels','','BalistreriAufderharandHuels.com','31289','BS Bahamas','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 ('Balistreri, Aufderhar and Huels','','BalistreriAufderharandHuels.com','31289','BS Bahamas','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 ('Murray, Barrows and Tillman','','MurrayBarrowsandTillman.com','745','HK Hong Kong','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 ('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 ('Schoen Group','','SchoenGroup.com','10783','FR France','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 ('Homenick and Sons','','HomenickandSons.com','14948','SM San Marino','shopPic.png',1,1,1);
INSERT INTO stamp_boards (Stamp_Board_Size, STAMP_BOARD_COLOUR, Stamp_Board_Icon) VALUES (3, 'red', 'ims/icon.png');
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment