Adding images and category to badges
This commit is contained in:
@@ -81,7 +81,9 @@ public class BadgeService {
|
||||
|
||||
badge.setName(modifiedBadge.getName());
|
||||
badge.setDescription(modifiedBadge.getDescription());
|
||||
badge.setCategory(modifiedBadge.getCategory());
|
||||
badge.setCriteria(modifiedBadge.getCriteria());
|
||||
badge.setImage(modifiedBadge.getImage());
|
||||
|
||||
return badgeRepository.save(badge);
|
||||
}
|
||||
|
||||
@@ -19,6 +19,7 @@ public class UserBadgeMapper {
|
||||
dto.setBadgeId(badge.getId());
|
||||
dto.setName(badge.getName());
|
||||
dto.setDescription(badge.getDescription());
|
||||
dto.setCategory(badge.getCategory());
|
||||
dto.setCriteria(badge.getCriteria());
|
||||
dto.setAwardedAt(userBadge.getAwardedAt());
|
||||
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
package SuMoC.backend.gamification.badges.models;
|
||||
|
||||
import SuMoC.backend.images.ImageEntity;
|
||||
import jakarta.persistence.*;
|
||||
|
||||
import java.util.HashMap;
|
||||
@@ -13,6 +14,10 @@ public class Badge {
|
||||
|
||||
private String name;
|
||||
private String description;
|
||||
private BadgeCategory category;
|
||||
|
||||
@OneToOne(mappedBy = "badge", cascade = CascadeType.ALL, orphanRemoval = true)
|
||||
private BadgeImageEntity image;
|
||||
|
||||
@ElementCollection
|
||||
@CollectionTable(name = "badge_criteria", joinColumns = @JoinColumn(name = "badge_id"))
|
||||
@@ -20,34 +25,33 @@ public class Badge {
|
||||
@Column(name = "criteria_value")
|
||||
private Map<String, Integer> criteria = new HashMap<>();
|
||||
|
||||
// Constructor
|
||||
|
||||
/**
|
||||
* Badge without criteria - if the Badge shouldn't be reachable by now
|
||||
* @param name name of the badge
|
||||
* @param description a short description
|
||||
*/
|
||||
public Badge(String name, String description) {
|
||||
// Constructors
|
||||
public Badge(String name, String description, BadgeCategory category) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.category = category;
|
||||
this.image = new BadgeImageEntity(this, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* Badge with criteria
|
||||
* @param name name of the badge
|
||||
* @param description a short description
|
||||
* @param criteria criteria Mapping StatField-Long
|
||||
*/
|
||||
public Badge(String name, String description, Map<String, Integer> criteria) {
|
||||
public Badge(String name, String description, BadgeCategory category, Map<String, Integer> criteria) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.category = category;
|
||||
this.criteria = criteria;
|
||||
}
|
||||
|
||||
public Badge(String name, String description, BadgeCategory category, Map<String, Integer> criteria, BadgeImageEntity image) {
|
||||
this.name = name;
|
||||
this.description = description;
|
||||
this.category = category;
|
||||
this.criteria = criteria;
|
||||
this.image = image;
|
||||
|
||||
}
|
||||
|
||||
public Badge() {}
|
||||
|
||||
// Getter & Setter
|
||||
|
||||
public Long getId() { return id; }
|
||||
public void setId(Long id) { this.id = id; }
|
||||
|
||||
@@ -57,6 +61,17 @@ public class Badge {
|
||||
public String getDescription() { return description; }
|
||||
public void setDescription(String description) { this.description = description; }
|
||||
|
||||
public BadgeCategory getCategory() { return category; }
|
||||
public void setCategory(BadgeCategory category) { this.category = category; }
|
||||
|
||||
public BadgeImageEntity getImage() { return image; }
|
||||
public void setImage(BadgeImageEntity image) {
|
||||
this.image = image;
|
||||
if (image != null) {
|
||||
image.setBadge(this);
|
||||
}
|
||||
}
|
||||
|
||||
public Map<String, Integer> getCriteria() { return criteria; }
|
||||
public void setCriteria(Map<String, Integer> criteria) { this.criteria = criteria; }
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,12 @@
|
||||
package SuMoC.backend.gamification.badges.models;
|
||||
|
||||
public enum BadgeCategory {
|
||||
XP,
|
||||
WALKING,
|
||||
BIKE,
|
||||
CAR,
|
||||
TRAIN,
|
||||
MONTHLY, // Get 10000 XP in January; Travel over 100 KM by train in May
|
||||
HIDDEN
|
||||
|
||||
}
|
||||
@@ -0,0 +1,33 @@
|
||||
package SuMoC.backend.gamification.badges.models;
|
||||
|
||||
import SuMoC.backend.images.ImageEntity;
|
||||
import jakarta.persistence.DiscriminatorValue;
|
||||
import jakarta.persistence.Entity;
|
||||
import jakarta.persistence.JoinColumn;
|
||||
import jakarta.persistence.OneToOne;
|
||||
|
||||
@Entity
|
||||
@DiscriminatorValue("BADGE")
|
||||
public class BadgeImageEntity extends ImageEntity {
|
||||
|
||||
@OneToOne
|
||||
@JoinColumn(name = "badge_id")
|
||||
private Badge badge;
|
||||
|
||||
public BadgeImageEntity() {
|
||||
super();
|
||||
}
|
||||
|
||||
public BadgeImageEntity(Badge badge, byte[] imageData) {
|
||||
super(imageData);
|
||||
this.badge = badge;
|
||||
}
|
||||
|
||||
public Badge getBadge() {
|
||||
return badge;
|
||||
}
|
||||
|
||||
public void setBadge(Badge badge) {
|
||||
this.badge = badge;
|
||||
}
|
||||
}
|
||||
@@ -8,6 +8,7 @@ public class UserBadgeDTO {
|
||||
private Long badgeId;
|
||||
private String name;
|
||||
private String description;
|
||||
private BadgeCategory category;
|
||||
private Map<String, Integer> criteria;
|
||||
private LocalDateTime awardedAt;
|
||||
|
||||
@@ -38,6 +39,14 @@ public class UserBadgeDTO {
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
public BadgeCategory getCategory() {
|
||||
return this.category;
|
||||
}
|
||||
|
||||
public void setCategory(BadgeCategory category) {
|
||||
this.category = category;
|
||||
}
|
||||
|
||||
public Map<String, Integer> getCriteria() {
|
||||
return criteria;
|
||||
}
|
||||
|
||||
@@ -11,7 +11,8 @@ public class ImageEntity {
|
||||
private int id;
|
||||
|
||||
@Lob
|
||||
@Column(columnDefinition = "BLOB")
|
||||
//@Column(columnDefinition = "BYTEA")
|
||||
//@Column(columnDefinition = "BLOB")
|
||||
private byte[] imageData;
|
||||
|
||||
public ImageEntity() {
|
||||
|
||||
@@ -11,7 +11,7 @@ import jakarta.persistence.OneToOne;
|
||||
public class ProfileImageEntity extends ImageEntity {
|
||||
|
||||
@OneToOne
|
||||
@JoinColumn(name = "user_id", nullable = false)
|
||||
@JoinColumn(name = "user_id")
|
||||
private User user;
|
||||
|
||||
public ProfileImageEntity() {
|
||||
|
||||
Reference in New Issue
Block a user