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

Rewards like Badges and Stickers now extend an abstract class Rewards

Restructured rewards package for organization
parent cb6e801c
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."
/*AUTHOR: Gabriel Copat*/
package team5.smartTowns.rewards;
import lombok.Data;
import lombok.Getter;
import java.io.File;
import java.util.Objects;
@Data
public class Badge {
@Getter
public class Badge extends Reward {
/* Badges can be earned by completing certain goals.
* They are displayed in the user profile page
*
* For example, one might earn a badge after visiting 20 locations */
static final String DEFAULT_IMAGE = "0.png";
int id;
String name;
String description;
String imgPath;
int difficulty; //1-5
public Badge(int id, String name, String description, int difficulty) {
this.id = id;
this.name = name;
this.description = description;
super(id, name, description);
this.difficulty = difficulty;
imgPath = findImagePath();
}
private String findImagePath(){
/* Finds the image in the Path folder, if image is not found assigns default image */
String imgPath = "images/rewards/badges/" + id + ".jpg";
String notFoundPath = "/images/rewards/badges/0.png";
File imgFile = new File("src/main/resources/static/" + imgPath);
return imgFile.exists() ? imgPath : notFoundPath;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Badge badge = (Badge) o;
return id == badge.id && Objects.equals(name, badge.name);
}
@Override
public int hashCode() {
return Objects.hash(id, name);
public String getImgFolder() {
return "badges";
}
}
package team5.smartTowns.rewards;
import lombok.Getter;
import java.io.File;
@Getter
public abstract class Reward {
/* Abstract class for all rewards */
int id;
String displayImg; //Path to the image file
String name;
String description;
public Reward(int id, String name, String description) {
//Default constructor
this.id = id;
this.name = name;
this.description = description;
displayImg = findImagePath();
}
public abstract String getImgFolder();
/*Returns folder in which images are located*/
public String getDefaultImg(){
/*Returns the name of the default image to be used in case no image is found*/
return "0.png";
};
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 notFoundPath = "images/rewards/" + getImgFolder() + "/" + getDefaultImg();
File imgFile = new File("src/main/resources/static/" + imgPath);
return imgFile.exists() ? imgPath : notFoundPath;
}
}
package team5.smartTowns.rewards;
import org.springframework.stereotype.Controller;
@Controller
public class RewardsController {
}
......@@ -2,36 +2,27 @@
package team5.smartTowns.rewards;
import lombok.Data;
import lombok.Getter;
import java.io.File;
import java.util.Objects;
@Data
public class Sticker {
/* Stickers are trade-able rewards, they vary in rarity and are earned at random */
@Getter
public class Sticker extends Reward{
/* Stickers are randomly earned rewards from a specific pack */
int id;
String name;
String description;
String imgPath;
int rarity; //1-5
boolean hasSticker;
String pack;
public Sticker(int id, String name, String description, int rarity) {
this.id = id;
this.name = name;
this.description = description;
public Sticker(int id, String name, String description, int rarity, String pack) {
super(id, name, description);
this.rarity = rarity;
imgPath = findImagePath();
}
private String findImagePath(){
/* Finds the image in the Path folder, if image is not found assigns default image */
String imgPath = "images/rewards/stickers/" + id + ".jpg";
String notFoundPath = "images/rewards/stickers/0.png";
File imgFile = new File("src/main/resources/static/" + imgPath);
return imgFile.exists() ? imgPath : notFoundPath;
@Override
public String getImgFolder() {
return "stickers";
}
public boolean hasSticker(){
......@@ -43,19 +34,5 @@ public class Sticker {
public String getVisibility(){
return hasSticker? "" : "grayedOut";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Sticker sticker = (Sticker) o;
return id == sticker.id && Objects.equals(name, sticker.name);
}
@Override
public int hashCode() {
return Objects.hash(id, name);
}
}
//Holds locations data repository
package team5.smartTowns.rewards;
package Team5.SmartTowns.rewards.data;
import Team5.SmartTowns.rewards.Badge;
import java.util.List;
......
//Implements the locations repository using JDBC
package team5.smartTowns.rewards;
package Team5.SmartTowns.rewards.data;
import Team5.SmartTowns.rewards.Badge;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
......
//Holds locations data repository
package team5.smartTowns.rewards;
package Team5.SmartTowns.rewards.data;
import Team5.SmartTowns.rewards.Sticker;
import java.util.List;
......
//Implements the locations repository using JDBC
package team5.smartTowns.rewards;
package Team5.SmartTowns.rewards.data;
import Team5.SmartTowns.rewards.Sticker;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.jdbc.core.RowMapper;
import org.springframework.stereotype.Repository;
......@@ -21,7 +22,8 @@ public class StickersRepositoryJDBC implements StickersRepository {
rs.getInt("stickerID"),
rs.getString("name"),
rs.getString("description"),
rs.getInt("rarity")
rs.getInt("rarity"),
rs.getString("pack")
);
}
......
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