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

Added dabase and controllers for Stickers

parent 6ca9cb39
No related branches found
No related tags found
1 merge request!26Resolve "As a client I want gamification of the badges, so that users remain engaged."
//Holds locations data repository
package Team5.SmartTowns.rewards;
import java.util.List;
public interface StickersRepository {
List<Sticker> getAllStickers();
}
//Implements the locations repository using JDBC
package Team5.SmartTowns.rewards;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
import java.util.List;
@Repository
public class StickersRepositoryJDBC implements StickersRepository {
private JdbcTemplate jdbc;
private RowMapper<Sticker> stickerMapper;
public StickersRepositoryJDBC(JdbcTemplate aJdbc) {
this.jdbc = aJdbc;
setStickerMapper();
}
private void setStickerMapper(){
stickerMapper = (rs, i) -> new Sticker(
rs.getInt("stickerID"),
rs.getString("name"),
rs.getString("description"),
rs.getInt("rarity")
);
}
@Override
public List<Sticker> getAllStickers(){
String sql= "SELECT * FROM stickers";
return jdbc.query(sql, stickerMapper);
}
}
......@@ -4,6 +4,7 @@ package Team5.SmartTowns.users;
import Team5.SmartTowns.rewards.Badge;
import Team5.SmartTowns.rewards.BadgesRepository;
import Team5.SmartTowns.rewards.Sticker;
import Team5.SmartTowns.rewards.StickersRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
......@@ -19,19 +20,10 @@ public class UserController {
private UserRepository userRepository;
@Autowired
private BadgesRepository badgesRepository;
@Autowired
private StickersRepository stickersRepository;
/*TODO REPLACE IT WITH DATABASE LIST*/
static List<Sticker> stickers = List.of(
new Sticker(1, "Sticker", "Sticker", 1),
new Sticker(2, "Sticker", "Sticker", 4),
new Sticker(3, "Sticker", "Sticker One is This", 4),
new Sticker(4, "Sticker", "Sticker One is This", 5),
new Sticker(5, "Sticker", "Sticker One is This", 5),
new Sticker(46, "Sticker", "Sticker One is This", 5),
new Sticker(7, "Sticker", "Sticker One is This", 2)
);
@GetMapping("/userList")
public ModelAndView userList() {
ModelAndView mav = new ModelAndView("towns/userData");
......@@ -43,6 +35,7 @@ public class UserController {
@GetMapping("/user/{id}")
public ModelAndView getUserPage(@PathVariable int id) {
List<Badge> badges = badgesRepository.getAllBadges();
List<Sticker> stickers = stickersRepository.getAllStickers();
List<User> users = userRepository.getAllUsers();
ModelAndView mav = new ModelAndView("rewards/userProfile");
users.stream()
......
......@@ -11,8 +11,15 @@ insert into locations (locationID, Name) value ('1', 'Caerphilly');
insert into locations (locationID, Name) value ('2', 'Penarth');
delete from badges;
insert into badges (badgeID, name, description, difficulty) value ('1', 'TownConnoisseur', 'You know the town very well!', '2');
insert into badges (badgeID, name, description, difficulty) value ('2', 'TownRegular', 'You visited the town 3 days in a row!', '1');
insert into badges (badgeID, name, description, difficulty) value ('3', 'TownMaster', 'You visited the town 7 days in a row!', '1');
insert into badges (badgeID, name, description, difficulty) value ('4', 'TownRegular', 'You visited the town 3 days in a row!', '1');
insert into badges (badgeID, name, description, difficulty) value ('5', 'TownRegular', 'You visited the town 3 days in a row!', '1');
\ No newline at end of file
insert into badges (name, description, difficulty) value ('TownConnoisseur', 'You know the town very well!', '2');
insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1');
insert into badges (name, description, difficulty) value ('TownMaster', 'You visited the town 7 days in a row!', '1');
insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1');
insert into badges (name, description, difficulty) value ('TownRegular', 'You visited the town 3 days in a row!', '1');
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');
\ No newline at end of file
......@@ -24,4 +24,12 @@ create table if not exists badges
name varchar(128),
description varchar(128),
difficulty bigint
) engine=InnoDB;
drop table if exists stickers;
create table if not exists stickers
(
stickerID bigint auto_increment primary key,
name varchar(128),
description varchar(128),
rarity bigint
) engine=InnoDB;
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment