Game Classes tab working
This commit is contained in:
17
db/1.0.0/10. createGameClass.sql
Normal file
17
db/1.0.0/10. createGameClass.sql
Normal file
@@ -0,0 +1,17 @@
|
|||||||
|
CREATE TABLE raid_builder.game_class(
|
||||||
|
game_class_id uuid PRIMARY KEY,
|
||||||
|
game_id uuid REFERENCES raid_builder.game(game_id),
|
||||||
|
game_class_name text NOT NULL,
|
||||||
|
game_class_icon text,
|
||||||
|
|
||||||
|
--Auditing
|
||||||
|
modified_by uuid,
|
||||||
|
modified_date timestamptz,
|
||||||
|
created_by uuid NOT NULL,
|
||||||
|
created_date timestamptz NOT NULL
|
||||||
|
);
|
||||||
|
|
||||||
|
CREATE INDEX idx_game_class_game_id ON raid_builder.game_class(game_id);
|
||||||
|
CREATE INDEX idx_game_class_game_class_name ON raid_builder.game_class(game_class_name);
|
||||||
|
|
||||||
|
GRANT ALL ON TABLE raid_builder.game_class TO raid_builder;
|
||||||
@@ -0,0 +1,140 @@
|
|||||||
|
package com.mattrixwv.raidbuilder.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.springframework.web.bind.annotation.DeleteMapping;
|
||||||
|
import org.springframework.web.bind.annotation.GetMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PathVariable;
|
||||||
|
import org.springframework.web.bind.annotation.PostMapping;
|
||||||
|
import org.springframework.web.bind.annotation.PutMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestMapping;
|
||||||
|
import org.springframework.web.bind.annotation.RequestParam;
|
||||||
|
import org.springframework.web.bind.annotation.RestController;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||||
|
import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
import com.mattrixwv.raidbuilder.annotation.AccountAuthorization;
|
||||||
|
import com.mattrixwv.raidbuilder.annotation.GameAuthorization;
|
||||||
|
import com.mattrixwv.raidbuilder.entity.GameClass;
|
||||||
|
import com.mattrixwv.raidbuilder.service.GameClassService;
|
||||||
|
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.AccountPermissionType;
|
||||||
|
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.GamePermissionType;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/gameClass")
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GameClassController{
|
||||||
|
private final ObjectMapper mapper;
|
||||||
|
private final GameClassService gameClassService;
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/game/{gameId}")
|
||||||
|
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||||
|
public List<GameClass> getByGameId(@PathVariable("gameId") UUID gameId, @RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam(name = "searchTerm", required = false) String searchTerm){
|
||||||
|
log.info("Getting game classes for game {} with page {} of size {} with search term {}", gameId, page, pageSize, searchTerm);
|
||||||
|
|
||||||
|
|
||||||
|
List<GameClass> gameClasses;
|
||||||
|
if((searchTerm == null) || (searchTerm.isBlank())){
|
||||||
|
gameClasses = gameClassService.getByGameId(gameId, page, pageSize);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
gameClasses = gameClassService.getByGameId(gameId, page, pageSize, searchTerm);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
return gameClasses;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@GetMapping("/game/{gameId}/count")
|
||||||
|
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||||
|
public ObjectNode getByGameCount(@PathVariable("gameId") UUID gameId, @RequestParam(name = "searchTerm", required = false) String searchTerm){
|
||||||
|
log.info("Getting game classes count for game {} with search term {}", gameId, searchTerm);
|
||||||
|
|
||||||
|
|
||||||
|
Long gameClassesCount;
|
||||||
|
if((searchTerm == null) || (searchTerm.isBlank())){
|
||||||
|
gameClassesCount = gameClassService.countByGameId(gameId);
|
||||||
|
}
|
||||||
|
else{
|
||||||
|
gameClassesCount = gameClassService.countByGameId(gameId, searchTerm);
|
||||||
|
}
|
||||||
|
|
||||||
|
ObjectNode countNode = mapper.createObjectNode();
|
||||||
|
countNode.put("count", gameClassesCount);
|
||||||
|
countNode.put("status", "success");
|
||||||
|
|
||||||
|
|
||||||
|
return countNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@PostMapping("/game/{gameId}")
|
||||||
|
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||||
|
@GameAuthorization(permissions = {GamePermissionType.ADMIN})
|
||||||
|
public ObjectNode createGameClass(@PathVariable("gameId") UUID gameId, @RequestParam(value = "iconFile", required = false) MultipartFile file, @RequestParam("gameClassName") String gameClassName){
|
||||||
|
log.info("Creating game class {}", gameClassName);
|
||||||
|
|
||||||
|
|
||||||
|
ObjectNode returnNode = mapper.createObjectNode();
|
||||||
|
GameClass gameClass = new GameClass();
|
||||||
|
gameClass.setGameId(gameId);
|
||||||
|
gameClass.setGameClassName(gameClassName);
|
||||||
|
gameClassService.createGameClass(gameClass, file);
|
||||||
|
|
||||||
|
returnNode.put("gameClassId", gameClass.getGameClassId().toString());
|
||||||
|
returnNode.put("status", "success");
|
||||||
|
|
||||||
|
log.info("Successfully created game class: {}", gameClass.getGameClassId());
|
||||||
|
|
||||||
|
return returnNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{gameClassId}/game/{gameId}")
|
||||||
|
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||||
|
@GameAuthorization(permissions = {GamePermissionType.ADMIN})
|
||||||
|
public ObjectNode updateGameClass(@PathVariable("gameClassId") UUID gameClassId, @PathVariable("gameId") UUID gameId, @RequestParam(value = "iconFile", required = false) MultipartFile file, @RequestParam("gameClassName") String gameClassName, @RequestParam(value = "gameClassIcon", required = false) String gameClassIcon){
|
||||||
|
log.info("Updating game class {}", gameClassName);
|
||||||
|
|
||||||
|
|
||||||
|
ObjectNode returnNode = mapper.createObjectNode();
|
||||||
|
GameClass gameClass = new GameClass();
|
||||||
|
gameClass.setGameClassId(gameClassId);
|
||||||
|
gameClass.setGameId(gameId);
|
||||||
|
gameClass.setGameClassName(gameClassName);
|
||||||
|
gameClass.setGameClassIcon(gameClassIcon);
|
||||||
|
gameClassService.updateGameClass(gameClass, file);
|
||||||
|
|
||||||
|
returnNode.put("gameClassId", gameClass.getGameClassId().toString());
|
||||||
|
returnNode.put("status", "success");
|
||||||
|
|
||||||
|
log.info("Successfully updated game class: {}", gameClass.getGameClassId());
|
||||||
|
|
||||||
|
return returnNode;
|
||||||
|
}
|
||||||
|
|
||||||
|
@DeleteMapping("/{gameClassId}/game/{gameId}")
|
||||||
|
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||||
|
@GameAuthorization(permissions = {GamePermissionType.ADMIN})
|
||||||
|
public ObjectNode deleteGameClass(@PathVariable("gameClassId") UUID gameClassId, @PathVariable("gameId") UUID gameId){
|
||||||
|
log.info("Deleting game class {}", gameClassId);
|
||||||
|
|
||||||
|
|
||||||
|
ObjectNode returnNode = mapper.createObjectNode();
|
||||||
|
gameClassService.deleteById(gameClassId);
|
||||||
|
returnNode.put("status", "success");
|
||||||
|
|
||||||
|
log.info("Successfully deleted game class: {}", gameClassId);
|
||||||
|
|
||||||
|
return returnNode;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -17,6 +17,7 @@ import com.mattrixwv.raidbuilder.annotation.AccountAuthorization;
|
|||||||
import lombok.extern.slf4j.Slf4j;
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
@Slf4j
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping("/icons")
|
@RequestMapping("/icons")
|
||||||
@@ -46,6 +47,18 @@ public class IconController{
|
|||||||
byte[] resource = Files.readAllBytes(Path.of(uploadFileDirectory + "/raidGroupIcons/" + raidGroupIconName));
|
byte[] resource = Files.readAllBytes(Path.of(uploadFileDirectory + "/raidGroupIcons/" + raidGroupIconName));
|
||||||
|
|
||||||
|
|
||||||
|
return ResponseEntity.ok().body(resource);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/gameClassIcons/{gameClassIconName}")
|
||||||
|
@AccountAuthorization(permissions = {})
|
||||||
|
public ResponseEntity<byte[]> getGameClassIcons(@PathVariable("gameClassIconName") String gameClassIconName) throws IOException{
|
||||||
|
log.info("Getting game class icon {}", gameClassIconName);
|
||||||
|
|
||||||
|
|
||||||
|
byte[] resource = Files.readAllBytes(Path.of(uploadFileDirectory + "/gameClassIcons/" + gameClassIconName));
|
||||||
|
|
||||||
|
|
||||||
return ResponseEntity.ok().body(resource);
|
return ResponseEntity.ok().body(resource);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -4,13 +4,21 @@ package com.mattrixwv.raidbuilder.entity;
|
|||||||
import java.time.ZonedDateTime;
|
import java.time.ZonedDateTime;
|
||||||
import java.util.UUID;
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.springframework.security.core.Authentication;
|
||||||
|
import org.springframework.security.core.context.SecurityContextHolder;
|
||||||
|
import org.springframework.security.oauth2.jwt.Jwt;
|
||||||
|
|
||||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||||
|
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.MappedSuperclass;
|
import jakarta.persistence.MappedSuperclass;
|
||||||
|
import jakarta.persistence.PrePersist;
|
||||||
|
import jakarta.persistence.PreUpdate;
|
||||||
import lombok.Data;
|
import lombok.Data;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
@Data
|
@Data
|
||||||
@MappedSuperclass
|
@MappedSuperclass
|
||||||
public abstract class AuditableEntity{
|
public abstract class AuditableEntity{
|
||||||
@@ -26,4 +34,36 @@ public abstract class AuditableEntity{
|
|||||||
@JsonIgnore
|
@JsonIgnore
|
||||||
@Column(name = "created_date", updatable = false)
|
@Column(name = "created_date", updatable = false)
|
||||||
protected ZonedDateTime createdDate;
|
protected ZonedDateTime createdDate;
|
||||||
|
|
||||||
|
|
||||||
|
@PrePersist
|
||||||
|
public void prePersist() throws NoSuchFieldException, IllegalAccessException{
|
||||||
|
this.createdBy = getCurrentUserId();
|
||||||
|
this.createdDate = ZonedDateTime.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
@PreUpdate
|
||||||
|
public void preUpdate(){
|
||||||
|
this.modifiedBy = getCurrentUserId();
|
||||||
|
this.modifiedDate = ZonedDateTime.now();
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private UUID getCurrentUserId(){
|
||||||
|
log.debug("Getting current auditor");
|
||||||
|
|
||||||
|
|
||||||
|
UUID returnUUID;
|
||||||
|
|
||||||
|
try{
|
||||||
|
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
||||||
|
returnUUID = UUID.fromString(((Jwt)auth.getPrincipal()).getClaimAsString("accountId"));
|
||||||
|
}
|
||||||
|
catch(Exception e){
|
||||||
|
returnUUID = new UUID(0, 0);
|
||||||
|
log.debug("No user logged in: {}", returnUUID);
|
||||||
|
}
|
||||||
|
|
||||||
|
return returnUUID;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,52 +0,0 @@
|
|||||||
package com.mattrixwv.raidbuilder.entity;
|
|
||||||
|
|
||||||
|
|
||||||
import java.time.ZonedDateTime;
|
|
||||||
import java.util.UUID;
|
|
||||||
|
|
||||||
import org.springframework.security.core.Authentication;
|
|
||||||
import org.springframework.security.core.context.SecurityContextHolder;
|
|
||||||
import org.springframework.security.oauth2.jwt.Jwt;
|
|
||||||
import org.springframework.stereotype.Component;
|
|
||||||
|
|
||||||
import jakarta.persistence.PrePersist;
|
|
||||||
import jakarta.persistence.PreUpdate;
|
|
||||||
import lombok.RequiredArgsConstructor;
|
|
||||||
import lombok.extern.slf4j.Slf4j;
|
|
||||||
|
|
||||||
|
|
||||||
@Slf4j
|
|
||||||
@Component
|
|
||||||
@RequiredArgsConstructor
|
|
||||||
public class AuditableEntityListener{
|
|
||||||
@PrePersist
|
|
||||||
public void prePersist(AuditableEntity entity) throws NoSuchFieldException, IllegalAccessException{
|
|
||||||
entity.createdBy = getCurrentUserId();
|
|
||||||
entity.createdDate = ZonedDateTime.now();
|
|
||||||
}
|
|
||||||
|
|
||||||
@PreUpdate
|
|
||||||
public void preUpdate(AuditableEntity entity){
|
|
||||||
entity.modifiedBy = getCurrentUserId();
|
|
||||||
entity.modifiedDate = ZonedDateTime.now();
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
private UUID getCurrentUserId(){
|
|
||||||
log.debug("Getting current auditor");
|
|
||||||
|
|
||||||
|
|
||||||
UUID returnUUID;
|
|
||||||
|
|
||||||
try{
|
|
||||||
Authentication auth = SecurityContextHolder.getContext().getAuthentication();
|
|
||||||
returnUUID = UUID.fromString(((Jwt)auth.getPrincipal()).getClaimAsString("accountId"));
|
|
||||||
}
|
|
||||||
catch(Exception e){
|
|
||||||
returnUUID = new UUID(0, 0);
|
|
||||||
log.debug("No user logged in: {}", returnUUID);
|
|
||||||
}
|
|
||||||
|
|
||||||
return returnUUID;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
@@ -5,7 +5,6 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.EntityListeners;
|
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
@@ -17,7 +16,6 @@ import lombok.NoArgsConstructor;
|
|||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "game", schema = "raid_builder")
|
@Table(name = "game", schema = "raid_builder")
|
||||||
@EntityListeners(AuditableEntityListener.class)
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.EntityListeners;
|
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
@@ -18,7 +17,6 @@ import lombok.NoArgsConstructor;
|
|||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "game_calendar_event", schema = "raid_builder")
|
@Table(name = "game_calendar_event", schema = "raid_builder")
|
||||||
@EntityListeners(AuditableEntityListener.class)
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
|||||||
@@ -0,0 +1,33 @@
|
|||||||
|
package com.mattrixwv.raidbuilder.entity;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import jakarta.persistence.Table;
|
||||||
|
import lombok.Data;
|
||||||
|
import lombok.EqualsAndHashCode;
|
||||||
|
import lombok.NoArgsConstructor;
|
||||||
|
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "game_class", schema = "raid_builder")
|
||||||
|
@Data
|
||||||
|
@EqualsAndHashCode(callSuper = false)
|
||||||
|
@NoArgsConstructor
|
||||||
|
public class GameClass extends AuditableEntity{
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.UUID)
|
||||||
|
@Column(name = "game_class_id")
|
||||||
|
private UUID gameClassId;
|
||||||
|
@Column(name = "game_id")
|
||||||
|
private UUID gameId;
|
||||||
|
@Column(name = "game_class_name")
|
||||||
|
private String gameClassName;
|
||||||
|
@Column(name = "game_class_icon")
|
||||||
|
private String gameClassIcon;
|
||||||
|
}
|
||||||
@@ -7,7 +7,6 @@ import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.GamePermissionType;
|
|||||||
|
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.EntityListeners;
|
|
||||||
import jakarta.persistence.EnumType;
|
import jakarta.persistence.EnumType;
|
||||||
import jakarta.persistence.Enumerated;
|
import jakarta.persistence.Enumerated;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
@@ -21,7 +20,6 @@ import lombok.NoArgsConstructor;
|
|||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "game_permission", schema = "raid_builder")
|
@Table(name = "game_permission", schema = "raid_builder")
|
||||||
@EntityListeners(AuditableEntityListener.class)
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
|||||||
@@ -5,7 +5,6 @@ import java.util.UUID;
|
|||||||
|
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.EntityListeners;
|
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
import jakarta.persistence.GenerationType;
|
import jakarta.persistence.GenerationType;
|
||||||
import jakarta.persistence.Id;
|
import jakarta.persistence.Id;
|
||||||
@@ -17,7 +16,6 @@ import lombok.NoArgsConstructor;
|
|||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "raid_group", schema = "raid_builder")
|
@Table(name = "raid_group", schema = "raid_builder")
|
||||||
@EntityListeners(AuditableEntityListener.class)
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
|||||||
@@ -7,7 +7,6 @@ import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.RaidGroupPermissionType;
|
|||||||
|
|
||||||
import jakarta.persistence.Column;
|
import jakarta.persistence.Column;
|
||||||
import jakarta.persistence.Entity;
|
import jakarta.persistence.Entity;
|
||||||
import jakarta.persistence.EntityListeners;
|
|
||||||
import jakarta.persistence.EnumType;
|
import jakarta.persistence.EnumType;
|
||||||
import jakarta.persistence.Enumerated;
|
import jakarta.persistence.Enumerated;
|
||||||
import jakarta.persistence.GeneratedValue;
|
import jakarta.persistence.GeneratedValue;
|
||||||
@@ -21,7 +20,6 @@ import lombok.NoArgsConstructor;
|
|||||||
|
|
||||||
@Entity
|
@Entity
|
||||||
@Table(name = "raid_group_permission", schema = "raid_builder")
|
@Table(name = "raid_group_permission", schema = "raid_builder")
|
||||||
@EntityListeners(AuditableEntityListener.class)
|
|
||||||
@Data
|
@Data
|
||||||
@EqualsAndHashCode(callSuper = false)
|
@EqualsAndHashCode(callSuper = false)
|
||||||
@NoArgsConstructor
|
@NoArgsConstructor
|
||||||
|
|||||||
@@ -0,0 +1,5 @@
|
|||||||
|
package com.mattrixwv.raidbuilder.repository.game_class;
|
||||||
|
|
||||||
|
|
||||||
|
public interface GameClassCustomRepository{
|
||||||
|
}
|
||||||
@@ -0,0 +1,23 @@
|
|||||||
|
package com.mattrixwv.raidbuilder.repository.game_class;
|
||||||
|
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import com.mattrixwv.raidbuilder.entity.GameClass;
|
||||||
|
|
||||||
|
|
||||||
|
public interface GameClassRepository extends GameClassCustomRepository, JpaRepository<GameClass, UUID>{
|
||||||
|
public void deleteByGameId(UUID gameId);
|
||||||
|
|
||||||
|
|
||||||
|
public List<GameClass> findAllByGameId(UUID gameId);
|
||||||
|
public List<GameClass> findAllByGameId(UUID gameId, PageRequest pageRequest);
|
||||||
|
public List<GameClass> findAllByGameIdAndGameClassNameContainingIgnoreCase(UUID gameId, String searchTerm, PageRequest pageRequest);
|
||||||
|
|
||||||
|
public long countByGameId(UUID gameId);
|
||||||
|
public long countByGameIdAndGameClassNameContainingIgnoreCase(UUID gameId, String searchTerm);
|
||||||
|
}
|
||||||
@@ -0,0 +1,9 @@
|
|||||||
|
package com.mattrixwv.raidbuilder.repository.game_class;
|
||||||
|
|
||||||
|
|
||||||
|
import org.springframework.stereotype.Repository;
|
||||||
|
|
||||||
|
|
||||||
|
@Repository
|
||||||
|
public class GameClassRepositoryImpl implements GameClassCustomRepository{
|
||||||
|
}
|
||||||
@@ -0,0 +1,129 @@
|
|||||||
|
package com.mattrixwv.raidbuilder.service;
|
||||||
|
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.nio.file.Path;
|
||||||
|
import java.nio.file.Paths;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
import org.springframework.beans.factory.annotation.Value;
|
||||||
|
import org.springframework.data.domain.PageRequest;
|
||||||
|
import org.springframework.data.domain.Sort;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.transaction.annotation.Transactional;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import com.mattrixwv.raidbuilder.entity.GameClass;
|
||||||
|
import com.mattrixwv.raidbuilder.repository.game_class.GameClassRepository;
|
||||||
|
|
||||||
|
import lombok.RequiredArgsConstructor;
|
||||||
|
import lombok.extern.slf4j.Slf4j;
|
||||||
|
|
||||||
|
|
||||||
|
@Slf4j
|
||||||
|
@Service
|
||||||
|
@Transactional(rollbackFor = Exception.class)
|
||||||
|
@RequiredArgsConstructor
|
||||||
|
public class GameClassService{
|
||||||
|
private final GameClassRepository gameClassRepository;
|
||||||
|
//Values
|
||||||
|
@Value("${uploadFileDirectory}")
|
||||||
|
private String uploadFileDirectory;
|
||||||
|
|
||||||
|
|
||||||
|
//Write
|
||||||
|
public GameClass createGameClass(GameClass gameClass, MultipartFile file){
|
||||||
|
if(file != null){
|
||||||
|
String fileName = UUID.randomUUID().toString() + "--" + file.getOriginalFilename();
|
||||||
|
Path filePath = Paths.get(uploadFileDirectory + "/gameClassIcons").resolve(fileName);
|
||||||
|
|
||||||
|
try{
|
||||||
|
file.transferTo(filePath);
|
||||||
|
gameClass.setGameClassIcon(fileName);
|
||||||
|
}
|
||||||
|
catch(Exception error){
|
||||||
|
log.error("Error uploading file: " + error.getMessage(), error);
|
||||||
|
throw new RuntimeException("Error uploading file: " + error.getMessage(), error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return gameClassRepository.save(gameClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public GameClass updateGameClass(GameClass gameClass, MultipartFile file){
|
||||||
|
GameClass existingGameClass = gameClassRepository.findById(gameClass.getGameClassId()).orElse(null);
|
||||||
|
|
||||||
|
//Delete the old file if one exists
|
||||||
|
if((existingGameClass != null) && (existingGameClass.getGameClassIcon() != null) && (gameClass.getGameClassIcon() == null)){
|
||||||
|
log.debug("Deleting old file: {}", existingGameClass.getGameClassIcon());
|
||||||
|
File existingFile = new File(uploadFileDirectory + "/gameClassIcons/" + existingGameClass.getGameClassIcon());
|
||||||
|
if(existingFile.exists()){
|
||||||
|
existingFile.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if(file != null){
|
||||||
|
//Upload the new file
|
||||||
|
String fileName = UUID.randomUUID().toString() + "--" + file.getOriginalFilename();
|
||||||
|
Path filePath = Paths.get(uploadFileDirectory + "/gameClassIcons").resolve(fileName);
|
||||||
|
try{
|
||||||
|
file.transferTo(filePath);
|
||||||
|
gameClass.setGameClassIcon(fileName);
|
||||||
|
}
|
||||||
|
catch(Exception error){
|
||||||
|
log.error("Error uploading file: " + error.getMessage(), error);
|
||||||
|
throw new RuntimeException("Error uploading file: " + error.getMessage(), error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return gameClassRepository.save(gameClass);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteById(UUID gameClassId){
|
||||||
|
GameClass gameClass = gameClassRepository.findById(gameClassId).orElse(null);
|
||||||
|
if(gameClass != null){
|
||||||
|
if(gameClass.getGameClassIcon() != null){
|
||||||
|
File existingFile = new File(uploadFileDirectory + "/gameClassIcons/" + gameClass.getGameClassIcon());
|
||||||
|
if(existingFile.exists()){
|
||||||
|
existingFile.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gameClassRepository.deleteById(gameClassId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public void deleteByGameId(UUID gameId){
|
||||||
|
List<GameClass> gameClasses = gameClassRepository.findAllByGameId(gameId);
|
||||||
|
for(GameClass gameClass : gameClasses){
|
||||||
|
if(gameClass.getGameClassIcon() != null){
|
||||||
|
File existingFile = new File(uploadFileDirectory + "/gameClassIcons/" + gameClass.getGameClassIcon());
|
||||||
|
if(existingFile.exists()){
|
||||||
|
existingFile.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
gameClassRepository.deleteByGameId(gameId);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Read
|
||||||
|
public List<GameClass> getByGameId(UUID gameId, int page, int pageSize){
|
||||||
|
return gameClassRepository.findAllByGameId(gameId, PageRequest.of(page, pageSize, Sort.by("gameClassName").ascending()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public List<GameClass> getByGameId(UUID gameId, int page, int pageSize, String searchTerm){
|
||||||
|
return gameClassRepository.findAllByGameIdAndGameClassNameContainingIgnoreCase(gameId, searchTerm, PageRequest.of(page, pageSize, Sort.by("gameClassName").ascending()));
|
||||||
|
}
|
||||||
|
|
||||||
|
public long countByGameId(UUID gameId){
|
||||||
|
return gameClassRepository.countByGameId(gameId);
|
||||||
|
}
|
||||||
|
|
||||||
|
public long countByGameId(UUID gameId, String searchTerm){
|
||||||
|
return gameClassRepository.countByGameIdAndGameClassNameContainingIgnoreCase(gameId, searchTerm);
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -29,6 +29,7 @@ public class GameService{
|
|||||||
private final GameRepository gameRepository;
|
private final GameRepository gameRepository;
|
||||||
//Related Services
|
//Related Services
|
||||||
private final GameCalendarEventService gameCalendarEventService;
|
private final GameCalendarEventService gameCalendarEventService;
|
||||||
|
private final GameClassService gameClassService;
|
||||||
private final GamePermissionService gamePermissionService;
|
private final GamePermissionService gamePermissionService;
|
||||||
private final RaidGroupService raidGroupService;
|
private final RaidGroupService raidGroupService;
|
||||||
//Values
|
//Values
|
||||||
@@ -93,6 +94,7 @@ public class GameService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
gameCalendarEventService.deleteByGameId(gameId);
|
gameCalendarEventService.deleteByGameId(gameId);
|
||||||
|
gameClassService.deleteByGameId(gameId);
|
||||||
gamePermissionService.deleteByGameId(gameId);
|
gamePermissionService.deleteByGameId(gameId);
|
||||||
raidGroupService.deleteByGameId(gameId);
|
raidGroupService.deleteByGameId(gameId);
|
||||||
gameRepository.flush();
|
gameRepository.flush();
|
||||||
|
|||||||
@@ -99,6 +99,14 @@ public class RaidGroupService{
|
|||||||
|
|
||||||
public void deleteByGameId(UUID gameId){
|
public void deleteByGameId(UUID gameId){
|
||||||
List<RaidGroup> raidGroups = raidGroupRepository.findAllByGameId(gameId);
|
List<RaidGroup> raidGroups = raidGroupRepository.findAllByGameId(gameId);
|
||||||
|
for(RaidGroup raidGroup : raidGroups){
|
||||||
|
if(raidGroup.getRaidGroupIcon() != null){
|
||||||
|
File existingFile = new File(uploadFileDirectory + "/raidGroupIcons/" + raidGroup.getRaidGroupIcon());
|
||||||
|
if(existingFile.exists()){
|
||||||
|
existingFile.delete();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
raidGroupPermissionService.deleteByRaidGroupIds(raidGroups.stream().map(RaidGroup::getRaidGroupId).toList());
|
raidGroupPermissionService.deleteByRaidGroupIds(raidGroups.stream().map(RaidGroup::getRaidGroupId).toList());
|
||||||
raidGroupRepository.flush();
|
raidGroupRepository.flush();
|
||||||
|
|
||||||
@@ -127,11 +135,7 @@ public class RaidGroupService{
|
|||||||
}
|
}
|
||||||
|
|
||||||
public List<RaidGroup> getRaidGroupsByGame(UUID gameId, int page, int pageSize, String searchTerm){
|
public List<RaidGroup> getRaidGroupsByGame(UUID gameId, int page, int pageSize, String searchTerm){
|
||||||
return raidGroupRepository.findAllByGameIdAndRaidGroupNameContainingIgnoreCase(
|
return raidGroupRepository.findAllByGameIdAndRaidGroupNameContainingIgnoreCase(gameId, searchTerm, PageRequest.of(page, pageSize, Sort.by("raidGroupName").ascending()));
|
||||||
gameId,
|
|
||||||
searchTerm,
|
|
||||||
PageRequest.of(page, pageSize, Sort.by("raidGroupName").ascending())
|
|
||||||
);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public long getRaidGroupsCount(){
|
public long getRaidGroupsCount(){
|
||||||
|
|||||||
Binary file not shown.
|
Before Width: | Height: | Size: 5.2 KiB |
Reference in New Issue
Block a user