Skip to content
Snippets Groups Projects
Commit ac35fc97 authored by Gabriel Copat's avatar Gabriel Copat
Browse files

Pack specific stickers now show on user page

parent 29f464d0
No related branches found
No related tags found
1 merge request!33Resolve "As a QR-scanning connoisseur , I want to unlock stickers after scanning a QR code to feel a sense of reward."
......@@ -30,7 +30,7 @@ public abstract class Reward {
}
public String findImagePath(){
/* Finds the image in the Path folder, if image is not found assigns default image */
String imgPath = "images/rewards/" + getImgFolder() + "/" + id + ".jpg";
String imgPath = "images/rewards/" + getImgFolder() + "/" + id + ".png";
String notFoundPath = "images/rewards/" + getImgFolder() + "/" + getDefaultImg();
File imgFile = new File("src/main/resources/static/" + imgPath);
......
......@@ -8,6 +8,12 @@ import java.util.List;
public interface RewardsRepository {
List<Badge> getAllBadges();
List<Sticker> getAllStickers();
List<Sticker> getAllStickersFromPack(int packID);
List<Pack> getAllPacks();
}
......@@ -12,12 +12,15 @@ public class RewardsRepositoryJDBC implements RewardsRepository {
private final JdbcTemplate jdbc;
private RowMapper<Badge> badgeMapper;
private RowMapper<Sticker> stickerMapper;
private RowMapper<Pack> packMapper;
public RewardsRepositoryJDBC(JdbcTemplate aJdbc) {
this.jdbc = aJdbc;
setBadgeMapper();
setStickerMapper();
setPackMapper();
}
private void setBadgeMapper(){
badgeMapper = (rs, i) -> new Badge(
rs.getInt("badgeID"),
......@@ -32,7 +35,15 @@ public class RewardsRepositoryJDBC implements RewardsRepository {
rs.getInt("stickerID"),
rs.getString("name"),
rs.getString("description"),
rs.getInt("rarity")
rs.getInt("rarity"),
rs.getInt("packID")
);
}
private void setPackMapper(){
packMapper = (rs, i) -> new Pack(
rs.getInt("id"),
rs.getString("name"),
rs.getString("description")
);
}
......@@ -42,9 +53,20 @@ public class RewardsRepositoryJDBC implements RewardsRepository {
return jdbc.query(sql, stickerMapper);
}
@Override
public List<Pack> getAllPacks() {
String sql= "SELECT * FROM packs";
return jdbc.query(sql, packMapper);
}
@Override
public List<Badge> getAllBadges(){
String sql= "SELECT * FROM badges";
return jdbc.query(sql, badgeMapper);
}
public List<Sticker> getAllStickersFromPack(int packID){
String sql= "SELECT * FROM stickers WHERE packID="+packID;
return jdbc.query(sql, stickerMapper);
}
}
......@@ -10,10 +10,12 @@ public class Sticker extends Reward{
int rarity; //1-5
boolean hasSticker;
int packID;
public Sticker(int id, String name, String description, int rarity) {
public Sticker(int id, String name, String description, int rarity, int packID) {
super(id, name, description);
this.rarity = rarity;
this.packID = packID;
}
@Override
......
......@@ -2,6 +2,7 @@ package team5.smartTowns.users;
import team5.smartTowns.rewards.Badge;
import team5.smartTowns.rewards.Pack;
import team5.smartTowns.rewards.RewardsRepository;
import team5.smartTowns.rewards.Sticker;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -42,6 +43,7 @@ public class UserController {
ModelAndView mav = new ModelAndView("users/userProfile");
List<Badge> badges = rewardsRepository.getAllBadges(); /*DEPRECATED FOR THE MOMENT*/
List<Sticker> allStickers = rewardsRepository.getAllStickers();
List<Pack> allPacks = rewardsRepository.getAllPacks();
......@@ -53,7 +55,7 @@ public class UserController {
.findFirst().ifPresent(sticker -> sticker.setVisibility(userStickers.get(stickerID)));
}
mav.addObject("user", userRepository.getUser(id));
mav.addObject("packs", badges);
mav.addObject("packs", allPacks);
mav.addObject("stickers", allStickers);
return mav;
......
......@@ -45,12 +45,23 @@ insert into badgeprogress (userID, badgeID, progress) value ('1', '1', '40');
insert into badgeprogress (userID, badgeID, progress) value ('1', '2', '70');
insert into badgeprogress (userID, badgeID, progress) value ('2', '2', '70');
delete from packs;
insert into packs (name, description) value ('Pack One Has a Kind of Long Name', 'This is pack 1');
insert into packs (name, description) value ('Pack2', 'This is pack 2');
insert into packs (name, description) value ('Pack3', 'This is pack 2');
insert into packs (name, description) value ('Pack3', 'This is pack 2');
insert into packs (name, description) value ('Pack3', 'This is pack 2');
insert into packs (name, description) value ('Pack3', 'This is pack 2');
insert into packs (name, description) value ('Pack3', 'This is pack 2');
insert into packs (name, description) value ('Pack3', 'This is pack 2');
delete from stickers;
insert into stickers (name, description, rarity) value ('TownConnoisseur', 'You know the town very well!', '2');
insert into stickers (name, description, rarity) value ('TownRegular', 'You visited the town 3 days in a row!', '1');
insert into stickers (name, description, rarity) value ('TownMaster', 'You visited the town 7 days in a row!', '1');
insert into stickers (name, description, rarity) value ('TownRegular', 'You visited the town 3 days in a row!', '1');
insert into stickers (name, description, rarity) value ('TownRegular', 'You visited the town 3 days in a row!', '1');
insert into stickers (name, description, rarity, packID) value ('TownConnoisseur', 'You know the town very well!', '2', 1);
insert into stickers (name, description, rarity, packID) value ('TownRegular', 'You visited the town 3 days in a row!', '1', 1);
insert into stickers (name, description, rarity, packID) value ('TownMaster', 'You visited the town 7 days in a row!', '1', 1);
insert into stickers (name, description, rarity, packID) value ('TownRegular', 'You visited the town 3 days in a row!', '1', 2);
insert into stickers (name, description, rarity, packID) value ('TownRegular', 'You visited the town 3 days in a row!', '1', 2);
delete from stickerprogress;
insert into stickerprogress (userID, stickerID, hasSticker) value ('1', '1', true);
......
......@@ -36,13 +36,25 @@ create table if not exists badges
) engine=InnoDB;
drop table if exists stickers;
drop table if exists packs;
create table if not exists packs
(
id bigint auto_increment primary key,
name varchar(128),
description varchar(128)
) engine=InnoDB;
create table if not exists stickers
(
stickerID bigint auto_increment primary key,
packID bigint,
name varchar(128),
description varchar(128),
rarity bigint
rarity bigint,
packID bigint,
FOREIGN KEY (packID) REFERENCES packs(id)
ON DELETE CASCADE
ON UPDATE RESTRICT
) engine=InnoDB;
drop table if exists badgeProgress;
......@@ -59,10 +71,3 @@ create table if not exists stickerProgress
stickerID bigint,
hasSticker boolean /*Has sticker or not*/
) engine=InnoDB;
create table if not exists packs
(
packID bigint auto_increment primary key,
name varchar(128),
description varchar(128)
) engine=InnoDB;
\ No newline at end of file
......@@ -46,4 +46,6 @@ function validateForm(){
return false;
}
//TODO SERVER SIDE VALIDATION AND CHECK AGAINST USERS DB TABLE
}
\ 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