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

increase/decrease buttons only show up if user is shop admin, and added reward...

increase/decrease buttons only show up if user is shop admin, and added reward code pop-up upon claim

Signed-off-by: default avatarc2064724 <allen-harrise@cardiff.ac.uk>
parent a2545f41
No related branches found
No related tags found
3 merge requests!114LoggingService service class, new method to add a log to the "Logs" table when...,!98added buttons to increase/decrease stamp position,!96merge into develop
......@@ -6,6 +6,8 @@ import com.example.clientproject.data.socials.Socials;
import com.example.clientproject.data.socials.SocialsRepo;
import com.example.clientproject.data.stampBoards.StampBoards;
import com.example.clientproject.data.stampBoards.StampBoardsRepo;
import com.example.clientproject.data.userPermissions.UserPermissions;
import com.example.clientproject.data.userPermissions.UserPermissionsRepo;
import com.example.clientproject.data.userStampBoards.UserStampBoards;
import com.example.clientproject.data.userStampBoards.UserStampBoardsRepo;
import com.example.clientproject.data.users.Users;
......@@ -39,16 +41,20 @@ public class BusinessDetails {
private SocialsRepo socialsRepo;
UserPermissionsRepo userPermissionsRepo;
public BusinessDetails(ShopsRepo aShopRepo, StampBoardsRepo aStampBoard,
UsersRepo aUsersRepo, UserStampBoardService aUserStampService,
JWTUtils ajwtUtils, SocialsRepo aSocialsRepo){
JWTUtils ajwtUtils, SocialsRepo aSocialsRepo,
UserPermissionsRepo upr){
shopsRepo = aShopRepo;
stampRepo = aStampBoard;
usersRepo = aUsersRepo;
jwtUtils = ajwtUtils;
userStampService = aUserStampService;
socialsRepo = aSocialsRepo;
userPermissionsRepo = upr;
}
@GetMapping("/businessDetails")
......@@ -80,6 +86,20 @@ public class BusinessDetails {
List<Socials> socialMedia = socialsRepo.findByShopId(shop.getShopId());
//gets users permission level for shop
long shopPermissionLevel = 0;
List<UserPermissions> userShops = userPermissionsRepo.findByUserId(jwtUtils.getLoggedInUserId(session).get());
//loops through userPermissions and saves it to variable to be passed into model
for (UserPermissions u : userShops) {
if (u.getShop().getShopId() == shop.getShopId()) {
shopPermissionLevel = u.getAdminType().getAdminTypeId();
}
}
//creates an object to pass into model
ArrayList <Integer> userShopPermissionOBJ = new ArrayList<>();
userShopPermissionOBJ.add((int) shopPermissionLevel);
model.addAttribute("userPermission", userShopPermissionOBJ);
model.addAttribute("socials", socialMedia);
......
......@@ -18,10 +18,8 @@ import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.Set;
import java.nio.charset.Charset;
import java.util.*;
@RestController
public class UpdateUserStampPosition {
......@@ -61,9 +59,6 @@ public class UpdateUserStampPosition {
shopStampBoardSize = u.getShop().getStampBoard().getStampBoardSize();
}
}
System.out.println(shopPermissionLevel);
System.out.println(shopStampBoardId);
System.out.println(shopStampBoardSize);
if(shopPermissionLevel > 1){//user has the correct level to add/subtract their own stampBoard place
currentUserStampPos = userStampBoardService.getUserStampPos(jwtUtils.getLoggedInUserId(session).get(), (int) shopStampBoardId );
if(Objects.equals(direction, "subtract")){
......@@ -79,7 +74,7 @@ public class UpdateUserStampPosition {
}
@PostMapping("/reedeemReward")
public void reedeemStamps(@RequestParam(name="rewardId", required = true) int rewardId, HttpSession session){
public String reedeemStamps(@RequestParam(name="rewardId", required = true) int rewardId, HttpSession session){
Optional<Rewards> reward = rewardsRepo.findByRewardId(Long.valueOf(rewardId));
int stampBoardId = getStampBoardIdFromRewardId.getStampBoardId(rewardId);
Optional<Users> user = usersRepo.findById(Long.valueOf(jwtUtils.getLoggedInUserId(session).get()));
......@@ -96,9 +91,22 @@ public class UpdateUserStampPosition {
if(userIsLinkedToStampBoard){
if(userStampPos >= reward.get().getRewardStampLocation()){
userStampBoardService.changeUserStampPosition(jwtUtils.getLoggedInUserId(session).get(), -reward.get().getRewardStampLocation(), userStampPos);
//credit to www.programiz.com for code generator
String alphabet = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";//creates a string of all characters
StringBuilder sb = new StringBuilder();
Random random = new Random();
for(int i = 0; i < 8; i++) {
int index = random.nextInt(alphabet.length());
char randomChar = alphabet.charAt(index);
sb.append(randomChar);
}
String code = sb.toString().toUpperCase();
return code;
}
} else {
System.out.println("User is not linked to stampboard you are trying to claim a reward from");
System.out.println("User is not linked to stampboard they are trying to claim a reward from");
}
return "no";
}
}
......@@ -192,3 +192,40 @@ img.stamp{
right: 3%;
width: 10px;
}
.reward-box{
width: inherit;
}
.text-align-center{
text-align: center;
}
.inherit-width{
width: inherit;
}
.reward-claim-title{
font-weight: bold;
font-size: 40px;
}
.big-margin-top{
margin-top: 70px;
}
.reward-claim-code{
color: black;
font-weight: bold;
font-size: 60px;
}
.custom-modal-card-body{
background-color: #fff;
flex-grow: 1;
flex-shrink: 1;
padding: 20px;
height: 400px;
border-radius: 0px 0px 10px 10px;
}
......@@ -61,7 +61,10 @@ function claimReward(rewardId){
xhttp.onload = function () {
if (xhttp.readyState === 4 && xhttp.status === 200) {
console.log(xhttp.responseText);
window.location.reload(true);
var modal = document.getElementById("rewardModal");
var code = document.getElementById("reward-code");
code.innerText = xhttp.responseText;
modal.classList.add("is-active");
}
}
xhttp.onerror = function () {
......@@ -70,3 +73,9 @@ function claimReward(rewardId){
xhttp.send(params);
return false;
}
function closeModal(){
window.location.reload(true);
}
......@@ -75,7 +75,7 @@
</div>
</div>
<div th:if="${@loadSocials.getSocial(socials, 'facebook' != '')}" class="control">
<div th:if="${@loadSocials.getSocial(socials, 'facebook') != ''}" class="control">
<div class="tags has-addons">
<span class="tag is-large is-grey">
<span class="icon-text">
......@@ -110,7 +110,7 @@
</span>
</span>
</span>
<a th:href="'https://twitter.com/' + ${@loadSocials.getSocial(socials, 'instagram')}"><span class="tag is-large is-danger mousePointerWhenHovered">Instagram</span></a>
<a th:href="'https://instagram.com/' + ${@loadSocials.getSocial(socials, 'instagram')}"><span class="tag is-large is-danger mousePointerWhenHovered">Instagram</span></a>
</div>
</div>
......@@ -132,10 +132,24 @@
<!-- <img th:src="${shop.shopImage}" alt=""> -->
<!-- <h1 th:text="${stampBoard.stampBoardSize}"></h1> -->
</div>
<div class="change-stamp-progress-container">
<div class="change-stamp-progress-container" th:if="${userPermission[0] > 1}">
<button class="button is-rounded is-info" th:onclick="changeUserStampPos('add', [[${shop.getShopId}]])">+</button>
<button class="button is-rounded is-info" th:onclick="changeUserStampPos('subtract', [[${shop.getShopId}]])">-</button>
</div>
<div class="modal" id="rewardModal">
<div class="modal-background"></div>
<div class="modal-card">
<header class="modal-card-head text-align-center">
<p class="modal-card-title reward-claim-title">Claim your reward!</p>
<button class="delete" aria-label="close" onclick="closeModal()"></button>
</header>
<section class="custom-modal-card-body">
<div class="inherit-width text-align-center big-margin-top">reward code:</div>
<div class="inherit-width text-align-center reward-claim-code" id="reward-code">XKMSTVZ</div>
</section>
</div>
</div>
<span th:value="${shop.getShopId}" id="shopId"/>
</body>
</html>
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment