diff --git a/src/main/java/com/example/clientproject/web/controllers/BusinessDetails.java b/src/main/java/com/example/clientproject/web/controllers/BusinessDetails.java index 2c3fd7c7f9959b533c0c48f869d07abde2914a93..e1e203a73d734b0974d6d04ef2b548d335dc7264 100644 --- a/src/main/java/com/example/clientproject/web/controllers/BusinessDetails.java +++ b/src/main/java/com/example/clientproject/web/controllers/BusinessDetails.java @@ -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); diff --git a/src/main/java/com/example/clientproject/web/restControllers/UpdateUserStampPosition.java b/src/main/java/com/example/clientproject/web/restControllers/UpdateUserStampPosition.java index 9497ff611b8bdc37090971cae86b1dc067842780..99046f87f9f73dd020b173bb9d5a834722b6b703 100644 --- a/src/main/java/com/example/clientproject/web/restControllers/UpdateUserStampPosition.java +++ b/src/main/java/com/example/clientproject/web/restControllers/UpdateUserStampPosition.java @@ -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"; } } diff --git a/src/main/resources/static/css/viewShop.css b/src/main/resources/static/css/viewShop.css index ec3aff6a9233e8f4a0d32a51a52930c69494fb2a..a42ee8bb8ec07fa002f15ac0ed2a4942acc82f29 100644 --- a/src/main/resources/static/css/viewShop.css +++ b/src/main/resources/static/css/viewShop.css @@ -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; +} diff --git a/src/main/resources/static/js/viewShop.js b/src/main/resources/static/js/viewShop.js index b62a6909ddb3c9541369b4823844028bcd62bb34..3d7fc0ecf7bc079d4003e3de184fcf3b2585a771 100644 --- a/src/main/resources/static/js/viewShop.js +++ b/src/main/resources/static/js/viewShop.js @@ -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); +} + diff --git a/src/main/resources/templates/shopDetails.html b/src/main/resources/templates/shopDetails.html index 5cde557b520322bb21757a92335de5874790595d..18882f8fa9592f9d7258f761adc0e0688a38a90f 100644 --- a/src/main/resources/templates/shopDetails.html +++ b/src/main/resources/templates/shopDetails.html @@ -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>