From fb5584615c72cb316016785a5e7166f798da4793 Mon Sep 17 00:00:00 2001 From: mitch Date: Fri, 9 Sep 2022 07:28:07 -0400 Subject: [PATCH] Added dataslate, weapon, and unikeyword classes with APIs to access them --- .../java/com/warhammer/domain/Dataslate.java | 237 ++++++++++++++++++ .../java/com/warhammer/domain/UnitArmy.java | 4 + .../com/warhammer/domain/UnitKeyword.java | 59 +++++ .../java/com/warhammer/domain/Weapon.java | 119 +++++++++ .../repository/DataslateRepository.java | 13 + .../repository/UnitKeywordRepository.java | 13 + .../repository/WeaponRepository.java | 13 + .../warhammer/service/DataslateService.java | 54 ++++ .../warhammer/service/UnitKeywordService.java | 47 ++++ .../com/warhammer/service/WeaponService.java | 47 ++++ .../warhammer/service/dto/DataslateDTO.java | 233 +++++++++++++++++ .../warhammer/service/dto/UnitKeywordDTO.java | 56 +++++ .../com/warhammer/service/dto/WeaponDTO.java | 113 +++++++++ .../service/impl/DataslateServiceImpl.java | 81 ++++++ .../service/impl/UnitKeywordServiceImpl.java | 69 +++++ .../service/impl/WeaponServiceImpl.java | 73 ++++++ .../service/mapper/DataslateMapper.java | 24 ++ .../service/mapper/UnitKeywordMapper.java | 12 + .../service/mapper/WeaponMapper.java | 15 ++ .../warhammer/web/rest/DataslateResource.java | 111 ++++++++ .../web/rest/UnitKeywordResource.java | 4 + .../warhammer/web/rest/WeaponResource.java | 4 + .../20220421081900_add_dataslates.xml | 97 +++++++ .../resources/config/liquibase/master.xml | 5 +- 24 files changed, 1501 insertions(+), 2 deletions(-) create mode 100644 src/main/java/com/warhammer/domain/Dataslate.java create mode 100644 src/main/java/com/warhammer/domain/UnitKeyword.java create mode 100644 src/main/java/com/warhammer/domain/Weapon.java create mode 100644 src/main/java/com/warhammer/repository/DataslateRepository.java create mode 100644 src/main/java/com/warhammer/repository/UnitKeywordRepository.java create mode 100644 src/main/java/com/warhammer/repository/WeaponRepository.java create mode 100644 src/main/java/com/warhammer/service/DataslateService.java create mode 100644 src/main/java/com/warhammer/service/UnitKeywordService.java create mode 100644 src/main/java/com/warhammer/service/WeaponService.java create mode 100644 src/main/java/com/warhammer/service/dto/DataslateDTO.java create mode 100644 src/main/java/com/warhammer/service/dto/UnitKeywordDTO.java create mode 100644 src/main/java/com/warhammer/service/dto/WeaponDTO.java create mode 100644 src/main/java/com/warhammer/service/impl/DataslateServiceImpl.java create mode 100644 src/main/java/com/warhammer/service/impl/UnitKeywordServiceImpl.java create mode 100644 src/main/java/com/warhammer/service/impl/WeaponServiceImpl.java create mode 100644 src/main/java/com/warhammer/service/mapper/DataslateMapper.java create mode 100644 src/main/java/com/warhammer/service/mapper/UnitKeywordMapper.java create mode 100644 src/main/java/com/warhammer/service/mapper/WeaponMapper.java create mode 100644 src/main/java/com/warhammer/web/rest/DataslateResource.java create mode 100644 src/main/java/com/warhammer/web/rest/UnitKeywordResource.java create mode 100644 src/main/java/com/warhammer/web/rest/WeaponResource.java create mode 100644 src/main/resources/config/liquibase/changelog/20220421081900_add_dataslates.xml diff --git a/src/main/java/com/warhammer/domain/Dataslate.java b/src/main/java/com/warhammer/domain/Dataslate.java new file mode 100644 index 00000000..46f416fc --- /dev/null +++ b/src/main/java/com/warhammer/domain/Dataslate.java @@ -0,0 +1,237 @@ +package com.warhammer.domain; + +import javax.persistence.*; +import java.io.Serializable; +import java.util.HashSet; +import java.util.Set; + +/** + * A dataslate. + */ +@Entity +@Table(name = "dataslate") +public class Dataslate implements Serializable { + + public Long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getMovement() { + return movement; + } + + public void setMovement(String movement) { + this.movement = movement; + } + + public String getWeaponSkill() { + return weaponSkill; + } + + public void setWeaponSkill(String weaponSkill) { + this.weaponSkill = weaponSkill; + } + + public String getBallisticSkill() { + return ballisticSkill; + } + + public void setBallisticSkill(String ballisticSkill) { + this.ballisticSkill = ballisticSkill; + } + + public Long getStrength() { + return strength; + } + + public void setStrength(Long strength) { + this.strength = strength; + } + + public String getToughness() { + return toughness; + } + + public void setToughness(String toughness) { + this.toughness = toughness; + } + + public String getWounds() { + return wounds; + } + + public void setWounds(String wounds) { + this.wounds = wounds; + } + + public String getAttacks() { + return attacks; + } + + public void setAttacks(String attacks) { + this.attacks = attacks; + } + + public Integer getLeadership() { + return leadership; + } + + public void setLeadership(Integer leadership) { + this.leadership = leadership; + } + + public Integer getSave() { + return save; + } + + public void setSave(Integer save) { + this.save = save; + } + + public Integer getInvulnerable() { + return invulnerable; + } + + public void setInvulnerable(Integer invulnerable) { + this.invulnerable = invulnerable; + } + + public Integer getFeelNoPain() { + return feelNoPain; + } + + public void setFeelNoPain(Integer feelNoPain) { + this.feelNoPain = feelNoPain; + } + + public String getWargearOptions() { + return wargearOptions; + } + + public void setWargearOptions(String wargearOptions) { + this.wargearOptions = wargearOptions; + } + + public String getPsyker() { + return psyker; + } + + public void setPsyker(String psyker) { + this.psyker = psyker; + } + + public Set getWeapons() { + return weapons; + } + + public void setWeapons(Set weapons) { + this.weapons = weapons; + } + + public Set getKeywords() { + return keywords; + } + + public void setKeywords(Set keywords) { + this.keywords = keywords; + } + + public UnitArmy getUnitArmy() { + return unitArmy; + } + + public void setUnitArmy(UnitArmy unitArmy) { + this.unitArmy = unitArmy; + } + + public User getOwner() { + return owner; + } + + public void setOwner(User owner) { + this.owner = owner; + } + + public String getOwnerLogin() { + return ownerLogin; + } + + public void setOwnerLogin(String ownerLogin) { + this.ownerLogin = ownerLogin; + } + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + @Column(name = "movement") + private String movement; + + @Column(name = "weapon_skill") + private String weaponSkill; + + @Column(name = "ballistic_skill") + private String ballisticSkill; + + @Column(name = "strength") + private Long strength; + + @Column(name = "toughness") + private String toughness; + + @Column(name = "wounds") + private String wounds; + + @Column(name = "attacks") + private String attacks; + + @Column(name = "leadership") + private Integer leadership; + + @Column(name = "save") + private Integer save; + + @Column(name = "invulnerable") + private Integer invulnerable; + + @Column(name = "feel_no_pain") + private Integer feelNoPain; + + @Lob + @Column(name = "wargear_options") + private String wargearOptions; + + @Lob + @Column(name = "psyker") + private String psyker; + + @ManyToMany + @JoinTable( + name = "dataslate_weapon", + joinColumns = { @JoinColumn(name = "dataslate_id") }, + inverseJoinColumns = { @JoinColumn(name = "weapon_id") } + ) + private Set weapons = new HashSet<>(); + + @ManyToMany + @JoinTable( + name = "dataslate_keyword", + joinColumns = { @JoinColumn(name = "dataslate_id") }, + inverseJoinColumns = { @JoinColumn(name = "keyword_id") } + ) + private Set keywords = new HashSet<>(); + + @ManyToOne + private UnitArmy unitArmy; + + @ManyToOne + private User owner; + + private String ownerLogin; +} diff --git a/src/main/java/com/warhammer/domain/UnitArmy.java b/src/main/java/com/warhammer/domain/UnitArmy.java index b01e92c5..42297446 100644 --- a/src/main/java/com/warhammer/domain/UnitArmy.java +++ b/src/main/java/com/warhammer/domain/UnitArmy.java @@ -354,6 +354,10 @@ public class UnitArmy implements Serializable { return this; } + public Army getArmy() { + return this.army; + } + @Override public boolean equals(Object o) { if (this == o) { diff --git a/src/main/java/com/warhammer/domain/UnitKeyword.java b/src/main/java/com/warhammer/domain/UnitKeyword.java new file mode 100644 index 00000000..095a76a8 --- /dev/null +++ b/src/main/java/com/warhammer/domain/UnitKeyword.java @@ -0,0 +1,59 @@ +package com.warhammer.domain; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +@Entity +@Table(name = "unit_keyword") +public class UnitKeyword implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + @NotNull + @Column(name = "keyword") + private String keyword; + + @NotNull + @Column(name = "isFaction") + private boolean isFaction; + + @ManyToOne + private User owner; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getKeyword() { + return keyword; + } + + public void setKeyword(String keyword) { + this.keyword = keyword; + } + + public boolean isFaction() { + return isFaction; + } + + public void setFaction(boolean faction) { + isFaction = faction; + } + + public User getOwner() { + return owner; + } + + public void setOwner(User owner) { + this.owner = owner; + } +} diff --git a/src/main/java/com/warhammer/domain/Weapon.java b/src/main/java/com/warhammer/domain/Weapon.java new file mode 100644 index 00000000..42fccf9a --- /dev/null +++ b/src/main/java/com/warhammer/domain/Weapon.java @@ -0,0 +1,119 @@ +package com.warhammer.domain; + +import javax.persistence.*; +import javax.validation.constraints.NotNull; +import java.io.Serializable; + +@Entity +@Table(name = "weapon") +public class Weapon implements Serializable { + + private static final long serialVersionUID = 1L; + + @Id + @GeneratedValue(strategy = GenerationType.IDENTITY) + private long id; + + @NotNull + @Column(name = "weapon") + private String weapon; + + @NotNull + @Column(name = "range") + private String range; + + @NotNull + @Column(name = "type") + private String type; + + @NotNull + @Column(name = "strength") + private String strength; + + @NotNull + @Column(name = "armor_penetration") + private String armorPenetration; + + @NotNull + @Column(name = "damage") + private String damage; + + @Lob + @Column(name = "abilities") + private String abilities; + + @ManyToOne + private User owner; + + public long getId() { + return id; + } + + public void setId(long id) { + this.id = id; + } + + public String getWeapon() { + return weapon; + } + + public void setWeapon(String weapon) { + this.weapon = weapon; + } + + public String getRange() { + return range; + } + + public void setRange(String range) { + this.range = range; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getStrength() { + return strength; + } + + public void setStrength(String strength) { + this.strength = strength; + } + + public String getArmorPenetration() { + return armorPenetration; + } + + public void setArmorPenetration(String armorPenetration) { + this.armorPenetration = armorPenetration; + } + + public String getDamage() { + return damage; + } + + public void setDamage(String damage) { + this.damage = damage; + } + + public String getAbilities() { + return abilities; + } + + public void setAbilities(String abilities) { + this.abilities = abilities; + } + + public User getOwner() { + return owner; + } + + public void setOwner(User owner) { + this.owner = owner; + } +} diff --git a/src/main/java/com/warhammer/repository/DataslateRepository.java b/src/main/java/com/warhammer/repository/DataslateRepository.java new file mode 100644 index 00000000..64bc3ab2 --- /dev/null +++ b/src/main/java/com/warhammer/repository/DataslateRepository.java @@ -0,0 +1,13 @@ +package com.warhammer.repository; + +import com.warhammer.domain.Dataslate; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * Spring Data repository for Dataslate entity. + */ +@SuppressWarnings("unused") +@Repository +public interface DataslateRepository extends JpaRepository { +} diff --git a/src/main/java/com/warhammer/repository/UnitKeywordRepository.java b/src/main/java/com/warhammer/repository/UnitKeywordRepository.java new file mode 100644 index 00000000..533bb464 --- /dev/null +++ b/src/main/java/com/warhammer/repository/UnitKeywordRepository.java @@ -0,0 +1,13 @@ +package com.warhammer.repository; + +import com.warhammer.domain.UnitKeyword; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * Spring Data repository for UnitKeyword entity. + */ +@SuppressWarnings("unused") +@Repository +public interface UnitKeywordRepository extends JpaRepository { +} diff --git a/src/main/java/com/warhammer/repository/WeaponRepository.java b/src/main/java/com/warhammer/repository/WeaponRepository.java new file mode 100644 index 00000000..d32c6d93 --- /dev/null +++ b/src/main/java/com/warhammer/repository/WeaponRepository.java @@ -0,0 +1,13 @@ +package com.warhammer.repository; + +import com.warhammer.domain.Weapon; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +/** + * Spring Data repository for Weapon entity. + */ +@SuppressWarnings("unused") +@Repository +public interface WeaponRepository extends JpaRepository { +} diff --git a/src/main/java/com/warhammer/service/DataslateService.java b/src/main/java/com/warhammer/service/DataslateService.java new file mode 100644 index 00000000..92b2a307 --- /dev/null +++ b/src/main/java/com/warhammer/service/DataslateService.java @@ -0,0 +1,54 @@ +package com.warhammer.service; + +import com.warhammer.domain.Dataslate; +import com.warhammer.service.dto.DataslateDTO; + +import java.util.List; +import java.util.Optional; + +public interface DataslateService { + + /** + * Save a dataslate + * + * @param dataslateDTO the entity to save. + * @return the persisted entity + */ + DataslateDTO save(DataslateDTO dataslateDTO); + + /** + * Get all the Dataslates + * + * @return the list of the entities + */ + List findAll(); + + /** + * Get all the Dataslates for a user + * + * @param ownerLogin the owner to search for the dataslates of + * @return List of Dataslates owned by Owner + */ + List findAllByOwner(Optional ownerLogin); + + /** + * Get all the Dataslates for an army + * + * @param id the id of the army + * @return List of Dataslates by army + */ + List findAllByArmy(Long id); + + /** + * + * @param id + * @return + */ + Optional findOne(Long id); + + /** + * + * @param id + */ + void delete(Long id); +} diff --git a/src/main/java/com/warhammer/service/UnitKeywordService.java b/src/main/java/com/warhammer/service/UnitKeywordService.java new file mode 100644 index 00000000..5ee7f973 --- /dev/null +++ b/src/main/java/com/warhammer/service/UnitKeywordService.java @@ -0,0 +1,47 @@ +package com.warhammer.service; + +import com.warhammer.service.dto.UnitKeywordDTO; + +import java.util.List; +import java.util.Optional; + +public interface UnitKeywordService { + + /** + * Save a UnitKeyword + * + * @param unitKeywordDTO the entity to save. + * @return the persisted entity + */ + UnitKeywordDTO save(UnitKeywordDTO unitKeywordDTO); + + /** + * Get all keywords + * + * @return the list of the keywords + */ + List findAll(); + + /** + * Get all the keywords for a user + * + * @param ownerLogin the owner to search for the keywords of + * @return List of keywords owned by Owner + */ + List findAllByOwner(Optional ownerLogin); + + /** + * Get a single keyword + * + * @param id of the keyword + * @return the entity + */ + Optional findOne(Long id); + + /** + * Delete a single keyword + * + * @param id of the entity to delete + */ + void delete(Long id); +} diff --git a/src/main/java/com/warhammer/service/WeaponService.java b/src/main/java/com/warhammer/service/WeaponService.java new file mode 100644 index 00000000..d38e782b --- /dev/null +++ b/src/main/java/com/warhammer/service/WeaponService.java @@ -0,0 +1,47 @@ +package com.warhammer.service; + +import com.warhammer.service.dto.WeaponDTO; + +import java.util.List; +import java.util.Optional; + +public interface WeaponService { + + /** + * Save a weapon + * + * @param weaponDTO + * @return the persisted entity + */ + WeaponDTO save(WeaponDTO weaponDTO); + + /** + * Get all weapons + * + * @return the list of the entities + */ + List findAll(); + + /** + * Get all Weapons for a user + * + * @param ownerLogin the owner to search for the weapons of + * @return List of weapons owned by Owner + */ + List findAllByOwner(Optional ownerLogin); + + /** + * Find a single weapon + * + * @param id the id of the entity + * @return the entity + */ + Optional findOne(Long id); + + /** + * Deletes a weapon + * + * @param id of the weapon + */ + void delete(Long id); +} diff --git a/src/main/java/com/warhammer/service/dto/DataslateDTO.java b/src/main/java/com/warhammer/service/dto/DataslateDTO.java new file mode 100644 index 00000000..d870dc4f --- /dev/null +++ b/src/main/java/com/warhammer/service/dto/DataslateDTO.java @@ -0,0 +1,233 @@ +package com.warhammer.service.dto; + +import com.warhammer.domain.UnitArmy; +import com.warhammer.domain.UnitKeyword; +import com.warhammer.domain.User; +import com.warhammer.domain.Weapon; + +import javax.persistence.Lob; +import java.io.Serializable; +import java.util.HashSet; + +/** + * A DTO for the {@link com.warhammer.domain.Dataslate} entity. + */ +public class DataslateDTO implements Serializable { + + private Long id; + + private String movement; + + private String weapon_skill; + + private String ballistic_skill; + + private String strength; + + private String toughness; + + private String wounds; + + private String attacks; + + private Integer leadership; + + private Integer save; + + private Integer invulnerable; + + private Integer feelNoPain; + + @Lob + private String wargearOptions; + + @Lob + private String psyker; + + private HashSet weapons; + + private HashSet keywords; + + private UnitArmy unitArmy; + + private User owner; + + public String ownerLogin; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getMovement() { + return movement; + } + + public void setMovement(String movement) { + this.movement = movement; + } + + public String getWeapon_skill() { + return weapon_skill; + } + + public void setWeapon_skill(String weapon_skill) { + this.weapon_skill = weapon_skill; + } + + public String getBallistic_skill() { + return ballistic_skill; + } + + public void setBallistic_skill(String ballistic_skill) { + this.ballistic_skill = ballistic_skill; + } + + public String getStrength() { + return strength; + } + + public void setStrength(String strength) { + this.strength = strength; + } + + public String getToughness() { + return toughness; + } + + public void setToughness(String toughness) { + this.toughness = toughness; + } + + public String getWounds() { + return wounds; + } + + public void setWounds(String wounds) { + this.wounds = wounds; + } + + public String getAttacks() { + return attacks; + } + + public void setAttacks(String attacks) { + this.attacks = attacks; + } + + public Integer getLeadership() { + return leadership; + } + + public void setLeadership(Integer leadership) { + this.leadership = leadership; + } + + public Integer getSave() { + return save; + } + + public void setSave(Integer save) { + this.save = save; + } + + public Integer getInvulnerable() { + return invulnerable; + } + + public void setInvulnerable(Integer invulnerable) { + this.invulnerable = invulnerable; + } + + public Integer getFeelNoPain() { + return feelNoPain; + } + + public void setFeelNoPain(Integer feelNoPain) { + this.feelNoPain = feelNoPain; + } + + public String getWargearOptions() { + return wargearOptions; + } + + public void setWargearOptions(String wargearOptions) { + this.wargearOptions = wargearOptions; + } + + public String getPsyker() { + return psyker; + } + + public void setPsyker(String psyker) { + this.psyker = psyker; + } + + public HashSet getWeapons() { + return weapons; + } + + public void setWeapons(HashSet weapons) { + this.weapons = weapons; + } + + public HashSet getKeywords() { + return keywords; + } + + public void setKeywords(HashSet keywords) { + this.keywords = keywords; + } + + public UnitArmy getUnitArmy() { + return unitArmy; + } + + public void setUnitArmy(UnitArmy unitArmy) { + this.unitArmy = unitArmy; + } + + public User getOwner() { + return owner; + } + + public void setOwner(User owner) { + this.owner = owner; + } + + public String getOwnerLogin() { + return ownerLogin; + } + + public void setOwnerLogin(String ownerLogin) { + this.ownerLogin = ownerLogin; + } + + @Override + public String toString() { + return "DataslateDTO{" + + "id=" + getId() + + ", movement='" + getMovement() + "'" + + ", weaponSkill='" + getWeapon_skill() + "'" + + ", ballisticSkill='" + getBallistic_skill() + "'" + + ", strength='" + getStrength() + "'" + + ", toughness='" + getToughness() + "'" + + ", wounds='" + getWounds() + "'" + + ", attacks='" + getAttacks() + "'" + + ", leadership='" + getLeadership() + "'" + + ", save=" + getSave() + + ", invulnerable= " + getInvulnerable() + + ", feelNoPain=" + getFeelNoPain() + + ", wargearOptions='" + getWargearOptions() + "'" + + ", psyker='" + getPsyker() + "'" + + ", weapons='" + getWeapons() + "'" + + ", keywords='" + getKeywords() + "'" + + ", unit=" + getUnitArmy() + + ", owner=" + getOwner() + + "}"; + } + +} diff --git a/src/main/java/com/warhammer/service/dto/UnitKeywordDTO.java b/src/main/java/com/warhammer/service/dto/UnitKeywordDTO.java new file mode 100644 index 00000000..a518e429 --- /dev/null +++ b/src/main/java/com/warhammer/service/dto/UnitKeywordDTO.java @@ -0,0 +1,56 @@ +package com.warhammer.service.dto; + +import com.warhammer.domain.User; + +public class UnitKeywordDTO { + + private Long id; + + private String keyword; + + private boolean isFaction; + + private User owner; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getKeyword() { + return keyword; + } + + public void setKeyword(String keyword) { + this.keyword = keyword; + } + + public boolean isFaction() { + return isFaction; + } + + public void setFaction(boolean faction) { + isFaction = faction; + } + + public User getOwner() { + return owner; + } + + public void setOwner(User owner) { + this.owner = owner; + } + + @Override + public String toString() { + return "UnitKeywordDTO{" + + "id=" + id + + ", keyword='" + keyword + '\'' + + ", isFaction=" + isFaction + + ", owner=" + owner + + '}'; + } +} diff --git a/src/main/java/com/warhammer/service/dto/WeaponDTO.java b/src/main/java/com/warhammer/service/dto/WeaponDTO.java new file mode 100644 index 00000000..cf2034a2 --- /dev/null +++ b/src/main/java/com/warhammer/service/dto/WeaponDTO.java @@ -0,0 +1,113 @@ +package com.warhammer.service.dto; + +import com.warhammer.domain.User; + +import java.io.Serializable; + +public class WeaponDTO implements Serializable { + + private Long id; + + private String weapon; + + private String range; + + private String type; + + private String strength; + + private String armorPenetration; + + private String damage; + + private String abilities; + + private User owner; + + public Long getId() { + return id; + } + + public void setId(Long id) { + this.id = id; + } + + public String getWeapon() { + return weapon; + } + + public void setWeapon(String weapon) { + this.weapon = weapon; + } + + public String getRange() { + return range; + } + + public void setRange(String range) { + this.range = range; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getStrength() { + return strength; + } + + public void setStrength(String strength) { + this.strength = strength; + } + + public String getArmorPenetration() { + return armorPenetration; + } + + public void setArmorPenetration(String armorPenetration) { + this.armorPenetration = armorPenetration; + } + + public String getDamage() { + return damage; + } + + public void setDamage(String damage) { + this.damage = damage; + } + + public String getAbilities() { + return abilities; + } + + public void setAbilities(String abilities) { + this.abilities = abilities; + } + + public User getOwner() { + return owner; + } + + public void setOwner(User owner) { + this.owner = owner; + } + + @Override + public String toString() { + return "WeaponDTO{" + + "id=" + id + + ", weapon='" + weapon + '\'' + + ", range='" + range + '\'' + + ", type='" + type + '\'' + + ", strength='" + strength + '\'' + + ", armorPenetration='" + armorPenetration + '\'' + + ", damage='" + damage + '\'' + + ", abilities='" + abilities + '\'' + + ", owner=" + owner + + '}'; + } +} diff --git a/src/main/java/com/warhammer/service/impl/DataslateServiceImpl.java b/src/main/java/com/warhammer/service/impl/DataslateServiceImpl.java new file mode 100644 index 00000000..ed50d3ee --- /dev/null +++ b/src/main/java/com/warhammer/service/impl/DataslateServiceImpl.java @@ -0,0 +1,81 @@ +package com.warhammer.service.impl; + +import com.warhammer.domain.Dataslate; +import com.warhammer.repository.DataslateRepository; +import com.warhammer.service.DataslateService; +import com.warhammer.service.dto.DataslateDTO; +import com.warhammer.service.mapper.DataslateMapper; + +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +@Service +@Transactional +public class DataslateServiceImpl implements DataslateService { + private final Logger log = LoggerFactory.getLogger(DataslateServiceImpl.class); + + private final DataslateRepository dataslateRepository; + + private final DataslateMapper dataslateMapper; + + public DataslateServiceImpl(DataslateRepository dataslateRepository, DataslateMapper dataslateMapper) { + this.dataslateRepository = dataslateRepository; + this.dataslateMapper = dataslateMapper; + } + + @Override + public DataslateDTO save(DataslateDTO dataslateDTO) { + log.debug("Request to save Dataslate : {}", dataslateDTO); + Dataslate dataslate = dataslateMapper.toEntity(dataslateDTO); + dataslate = dataslateRepository.save(dataslate); + return dataslateMapper.toDto(dataslate); + } + + @Override + @Transactional(readOnly = true) + public List findAll() { + log.debug("Request to get all Dataslates"); + return dataslateRepository.findAll().stream() + .map(dataslateMapper::toDto) + .collect(Collectors.toCollection(LinkedList::new)); + } + + @Override + public List findAllByOwner(Optional ownerLoginOptional) { + log.debug("Request to get all Dataslates by Owner : " + ownerLoginOptional.orElse(null)); + return dataslateRepository.findAll().stream() + .map(dataslateMapper::toDto) + .filter(dataslateDTO -> dataslateDTO.getOwnerLogin().equals(ownerLoginOptional.orElse(null))) + .collect(Collectors.toCollection(LinkedList::new)); + } + + @Override + public List findAllByArmy(Long id) { + log.debug("Request to get all Dataslates by Army : " + id); + return dataslateRepository.findAll().stream() + .map(dataslateMapper::toDto) + .filter(dataslateDTO -> dataslateDTO.getUnitArmy().getArmy().getId().equals(id)) + .collect(Collectors.toCollection(LinkedList::new)); + } + + @Override + @Transactional(readOnly = true) + public Optional findOne(Long id) { + log.debug("Request to get Dataslate : {}", id); + return dataslateRepository.findById(id) + .map(dataslateMapper::toDto); + } + + @Override + public void delete(Long id) { + log.debug("Request to delete Dataslate : {}", id); + dataslateRepository.deleteById(id); + } +} diff --git a/src/main/java/com/warhammer/service/impl/UnitKeywordServiceImpl.java b/src/main/java/com/warhammer/service/impl/UnitKeywordServiceImpl.java new file mode 100644 index 00000000..029d053f --- /dev/null +++ b/src/main/java/com/warhammer/service/impl/UnitKeywordServiceImpl.java @@ -0,0 +1,69 @@ +package com.warhammer.service.impl; + +import com.warhammer.domain.UnitKeyword; +import com.warhammer.repository.UnitKeywordRepository; +import com.warhammer.service.UnitKeywordService; +import com.warhammer.service.dto.UnitKeywordDTO; +import com.warhammer.service.mapper.UnitKeywordMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +@Service +@Transactional +public class UnitKeywordServiceImpl implements UnitKeywordService { + private final Logger log = LoggerFactory.getLogger(UnitKeywordServiceImpl.class); + + private final UnitKeywordRepository unitKeywordRepository; + + private final UnitKeywordMapper unitKeywordMapper; + + public UnitKeywordServiceImpl(UnitKeywordRepository unitKeywordRepository, UnitKeywordMapper unitKeywordMapper) { + this.unitKeywordRepository = unitKeywordRepository; + this.unitKeywordMapper = unitKeywordMapper; + } + + @Override + public UnitKeywordDTO save(UnitKeywordDTO unitKeywordDTO) { + log.debug("Request to save UnitKeyword : {}", unitKeywordDTO); + UnitKeyword unitKeyword = unitKeywordMapper.toEntity(unitKeywordDTO); + unitKeyword = unitKeywordRepository.save(unitKeyword); + return unitKeywordMapper.toDto(unitKeyword); + } + + @Override + public List findAll() { + log.debug("Request to get all UnitKeywords"); + return unitKeywordRepository.findAll().stream() + .map(unitKeywordMapper::toDto) + .collect(Collectors.toCollection(LinkedList::new)); + } + + @Override + public List findAllByOwner(Optional ownerLoginOptional) { + log.debug("Request to get all UnitKeywords by Owner : " + ownerLoginOptional.orElse(null)); + return unitKeywordRepository.findAll().stream() + .map(unitKeywordMapper::toDto) + .filter(unitKeywordDto -> unitKeywordDto.getOwner().equals(ownerLoginOptional.orElse(null))) + .collect(Collectors.toCollection(LinkedList::new)); + } + + @Override + public Optional findOne(Long id) { + log.debug("Request to get UnitKeyword : {}", id); + return unitKeywordRepository.findById(id) + .map(unitKeywordMapper::toDto); + } + + @Override + public void delete(Long id) { + log.debug("Request ot delete UnitKeyword : {}", id); + unitKeywordRepository.deleteById(id); + } +} diff --git a/src/main/java/com/warhammer/service/impl/WeaponServiceImpl.java b/src/main/java/com/warhammer/service/impl/WeaponServiceImpl.java new file mode 100644 index 00000000..17f5323f --- /dev/null +++ b/src/main/java/com/warhammer/service/impl/WeaponServiceImpl.java @@ -0,0 +1,73 @@ +package com.warhammer.service.impl; + +import com.warhammer.domain.Weapon; +import com.warhammer.repository.WeaponRepository; +import com.warhammer.service.WeaponService; +import com.warhammer.service.dto.WeaponDTO; +import com.warhammer.service.mapper.WeaponMapper; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +import java.util.LinkedList; +import java.util.List; +import java.util.Optional; +import java.util.stream.Collectors; + +@Service +@Transactional +public class WeaponServiceImpl implements WeaponService { + + private final Logger log = LoggerFactory.getLogger(WeaponServiceImpl.class); + + private final WeaponRepository weaponRepository; + + private final WeaponMapper weaponMapper; + + public WeaponServiceImpl(WeaponRepository weaponRepository, WeaponMapper weaponMapper) { + this.weaponRepository = weaponRepository; + this.weaponMapper = weaponMapper; + } + + @Override + public WeaponDTO save(WeaponDTO weaponDTO) { + log.debug("Request to save Weapon : {}", weaponDTO); + Weapon weapon = weaponMapper.toEntity(weaponDTO); + weapon = weaponRepository.save(weapon); + return weaponMapper.toDto(weapon); + } + + @Override + @Transactional(readOnly = true) + public List findAll() { + log.debug("Request to get all Weapons"); + return weaponRepository.findAll().stream() + .map(weaponMapper::toDto) + .collect(Collectors.toCollection(LinkedList::new)); + } + + @Override + @Transactional(readOnly = true) + public List findAllByOwner(Optional ownerLoginOptional) { + log.debug("Request to get all Weapons by Owner : " + ownerLoginOptional.orElse(null)); + return weaponRepository.findAll().stream() + .map(weaponMapper::toDto) + .filter(weaponDTO -> weaponDTO.getOwner().equals(ownerLoginOptional.orElse(null))) + .collect(Collectors.toCollection(LinkedList::new)); + } + + @Override + @Transactional(readOnly = true) + public Optional findOne(Long id) { + log.debug("Request to get Dataslate : {}", id); + return weaponRepository.findById(id) + .map(weaponMapper::toDto); + } + + @Override + public void delete(Long id) { + log.debug("Request to delete Weapon : {}", id); + weaponRepository.deleteById(id); + } +} diff --git a/src/main/java/com/warhammer/service/mapper/DataslateMapper.java b/src/main/java/com/warhammer/service/mapper/DataslateMapper.java new file mode 100644 index 00000000..777b5594 --- /dev/null +++ b/src/main/java/com/warhammer/service/mapper/DataslateMapper.java @@ -0,0 +1,24 @@ +package com.warhammer.service.mapper; + +import com.warhammer.domain.Dataslate; +import com.warhammer.service.dto.DataslateDTO; +import org.mapstruct.*; + +@Mapper(componentModel = "spring", uses = {UserMapper.class}) +public interface DataslateMapper extends EntityMapper { + @Mapping(source = "owner.id", target = "owner") + @Mapping(source = "owner.login", target = "ownerLogin") + DataslateDTO toDto(Dataslate dataslate); + + @Mapping(source = "owner", target = "owner") + Dataslate toEntity(DataslateDTO dataslateDTO); + + default Dataslate fromId(Long id) { + if (id == null) { + return null; + } + Dataslate dataslate = new Dataslate(); + dataslate.setId(id); + return dataslate; + } +} diff --git a/src/main/java/com/warhammer/service/mapper/UnitKeywordMapper.java b/src/main/java/com/warhammer/service/mapper/UnitKeywordMapper.java new file mode 100644 index 00000000..7f3b2049 --- /dev/null +++ b/src/main/java/com/warhammer/service/mapper/UnitKeywordMapper.java @@ -0,0 +1,12 @@ +package com.warhammer.service.mapper; + +import com.warhammer.domain.UnitKeyword; +import com.warhammer.service.dto.UnitKeywordDTO; +import org.mapstruct.Mapper; + +@Mapper(componentModel = "spring", uses = {UserMapper.class}) +public interface UnitKeywordMapper extends EntityMapper { + UnitKeywordDTO toDto(UnitKeyword unitKeyword); + + UnitKeyword toEntity(UnitKeywordDTO unitKeywordDTO); +} diff --git a/src/main/java/com/warhammer/service/mapper/WeaponMapper.java b/src/main/java/com/warhammer/service/mapper/WeaponMapper.java new file mode 100644 index 00000000..dc6bac39 --- /dev/null +++ b/src/main/java/com/warhammer/service/mapper/WeaponMapper.java @@ -0,0 +1,15 @@ +package com.warhammer.service.mapper; + +import com.warhammer.domain.Weapon; +import com.warhammer.service.dto.WeaponDTO; +import org.mapstruct.Mapper; +import org.mapstruct.Mapping; + +@Mapper(componentModel = "spring", uses = {UserMapper.class}) +public interface WeaponMapper extends EntityMapper { +// @Mapping(source = "owner.login", target = "owner") + @Mapping(source = "weapon", target = "weapon") + WeaponDTO toDto(Weapon weapon); + + Weapon toEntity(WeaponDTO weaponDTO); +} diff --git a/src/main/java/com/warhammer/web/rest/DataslateResource.java b/src/main/java/com/warhammer/web/rest/DataslateResource.java new file mode 100644 index 00000000..85fd3127 --- /dev/null +++ b/src/main/java/com/warhammer/web/rest/DataslateResource.java @@ -0,0 +1,111 @@ +package com.warhammer.web.rest; + +import com.warhammer.domain.Dataslate; +import com.warhammer.security.SecurityUtils; +import com.warhammer.service.DataslateService; +import com.warhammer.service.dto.DataslateDTO; +import com.warhammer.web.rest.errors.BadRequestAlertException; +import io.github.jhipster.web.util.HeaderUtil; +import io.github.jhipster.web.util.ResponseUtil; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Value; +import org.springframework.http.ResponseEntity; +import org.springframework.web.bind.annotation.*; + +import javax.validation.Valid; +import java.net.URI; +import java.net.URISyntaxException; +import java.util.List; +import java.util.Optional; + +@RestController +@RequestMapping("~/api") +public class DataslateResource { + private final Logger log = LoggerFactory.getLogger(DataslateResource.class); + + private static final String ENTITY_NAME = "dataslate"; + + @Value("crusadetrackerApp") + private String applicationName; + + private final DataslateService dataslateService; + + public DataslateResource(DataslateService dataslateService) { + this.dataslateService = dataslateService; + } + + /** + * {@code POST /dataslates} : Creates a dataslate. + * + * @param dataslateDTO the dataslate to create + * @return the {@link ResponseEntity} with status {@code 201 (Created)} and with body the new dataslate, or with status {@code 400 (Bad Request)} if the dataslate already has an ID. + * @throws URISyntaxException if the Location URI syntax is incorrect. + */ + @PostMapping("/dataslates") + public ResponseEntity createDataslate(@Valid @RequestBody DataslateDTO dataslateDTO) throws URISyntaxException { + log.debug("REST request to save Dataslate : {}", dataslateDTO); + if (dataslateDTO.getId() != null) { + throw new BadRequestAlertException("A new dataslate cannot already have an ID", ENTITY_NAME, "idexists"); + } + DataslateDTO result = dataslateService.save(dataslateDTO); + return ResponseEntity.created(new URI("/api/dataslates/" + result.getId())) + .headers(HeaderUtil.createEntityCreationAlert(applicationName, false, ENTITY_NAME, result.getId().toString())) + .body(result); + } + + /** + * {@code PUT /dataslates} : Updates an existing dataslate. + * + * @param dataslateDTO the dataslate to update + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and with body the updated dataslate, + * or with status {@code 400 (Bad Request)} if the dataslate is not valid, + * or with status {@code 500 (Internal Server Error)} if the dataslate couldn't be updated. + * @throws URISyntaxException if the Location URI syntax is incorrect. + */ + @PutMapping("/dataslates") + public ResponseEntity updateDataSlate(@Valid @RequestBody DataslateDTO dataslateDTO) throws URISyntaxException { + log.debug("REST request to update Dataslate : {}", dataslateDTO); + if (dataslateDTO.getId() == null) { + throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull"); + } + DataslateDTO result = dataslateService.save(dataslateDTO); + return ResponseEntity.ok() + .headers(HeaderUtil.createEntityUpdateAlert(applicationName, false, ENTITY_NAME, + dataslateDTO.getId().toString())) + .body(result); + } + + /** + * {@code GET /dataslates} : get all the dataslates + * + * @return the {@link ResponseEntity} with status {@code 200 (OK)} and the list of dataslates in body. + */ + @GetMapping("/dataslates") + public List getAllDataslates() { + log.debug("REST request to get all dataslates"); + Optional userLogin = SecurityUtils.getCurrentUserLogin(); + return dataslateService.findAllByOwner(userLogin); + } + + /** + * {@code GET /dataslates/get-army/:id} : get all + * @param id + * @return + */ + @GetMapping("/dataslates/get-army/{id}") + public ResponseEntity> getUnitArmy(@PathVariable Long id) { + log.debug("REST request to get Dataslates for army : {}", id); + List dataslateDTO = dataslateService.findAllByArmy(id); + Optional> optionalDataslateDTOS = Optional.of(dataslateDTO); + return ResponseUtil.wrapOrNotFound(optionalDataslateDTOS); + } + + @DeleteMapping("/dataslates/{id}") + public ResponseEntity deleteDataslate(@PathVariable Long id) { + log.debug("REST request to delete Dataslate : {}", id); + dataslateService.delete(id); + return ResponseEntity.noContent().headers(HeaderUtil.createEntityDeletionAlert( + applicationName, false, ENTITY_NAME, id.toString())).build(); + } +} diff --git a/src/main/java/com/warhammer/web/rest/UnitKeywordResource.java b/src/main/java/com/warhammer/web/rest/UnitKeywordResource.java new file mode 100644 index 00000000..a3881e33 --- /dev/null +++ b/src/main/java/com/warhammer/web/rest/UnitKeywordResource.java @@ -0,0 +1,4 @@ +package com.warhammer.web.rest; + +public class UnitKeywordResource { +} diff --git a/src/main/java/com/warhammer/web/rest/WeaponResource.java b/src/main/java/com/warhammer/web/rest/WeaponResource.java new file mode 100644 index 00000000..1be49897 --- /dev/null +++ b/src/main/java/com/warhammer/web/rest/WeaponResource.java @@ -0,0 +1,4 @@ +package com.warhammer.web.rest; + +public class WeaponResource { +} diff --git a/src/main/resources/config/liquibase/changelog/20220421081900_add_dataslates.xml b/src/main/resources/config/liquibase/changelog/20220421081900_add_dataslates.xml new file mode 100644 index 00000000..de9582da --- /dev/null +++ b/src/main/resources/config/liquibase/changelog/20220421081900_add_dataslates.xml @@ -0,0 +1,97 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/src/main/resources/config/liquibase/master.xml b/src/main/resources/config/liquibase/master.xml index 82bd5993..0416b526 100644 --- a/src/main/resources/config/liquibase/master.xml +++ b/src/main/resources/config/liquibase/master.xml @@ -26,6 +26,7 @@ - - + + +