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

New Classes for Users, Badges and Stickers

parent 290d61c0
No related branches found
No related tags found
1 merge request!25Resolve "As a user, I would like a place to see all my earned badges, so that I can track my progress."
/*AUTHOR: Gabriel Copat*/
package Team5.SmartTowns.rewards;
import lombok.Data;
import java.io.File;
import java.util.Objects;
@Data
public class Badge {
/* 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 */
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;
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.jpg";
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);
}
}
/*AUTHOR: Gabriel Copat*/
package Team5.SmartTowns.rewards;
import lombok.Data;
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 */
int id;
String name;
String description;
String imgPath;
int rarity; //1-5
public Sticker(int id, String name, String description, int rarity) {
this.id = id;
this.name = name;
this.description = 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.jpg";
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;
Sticker sticker = (Sticker) o;
return id == sticker.id && Objects.equals(name, sticker.name);
}
@Override
public int hashCode() {
return Objects.hash(id, name);
}
}
package Team5.SmartTowns.users;
import Team5.SmartTowns.rewards.Badge;
import Team5.SmartTowns.rewards.Sticker;
import java.util.HashMap;
import java.util.Map;
public class User {
String email; //Validation would be done by email, since they will have that
Map<Badge, Integer> badgeProgress = new HashMap<>(); // Demonstrates the progress towards a specific badge (0-100)
Map<Sticker, Boolean> hasStickers = new HashMap<>(); // True if User has sticker (key)
}
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