Raid groups page working
This commit is contained in:
@@ -8,7 +8,7 @@ CREATE TABLE IF NOT EXISTS raid_builder.raid_group_permission(
|
||||
permission raid_builder.raid_group_permission_type NOT NULL,
|
||||
|
||||
--Auditing
|
||||
modified_by uuid NOT NULL,
|
||||
modified_by uuid,
|
||||
modified_date timestamptz,
|
||||
created_by uuid NOT NULL,
|
||||
created_date timestamptz NOT NULL
|
||||
|
||||
@@ -114,6 +114,7 @@ public class RaidGroupController{
|
||||
|
||||
@PutMapping("/{raidGroupId}")
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
@RaidGroupAuthorization(permissions = {RaidGroupPermissionType.ADMIN})
|
||||
public ObjectNode updateRaidGroup(@RequestParam(value = "iconFile", required = false) MultipartFile file, @PathVariable("raidGroupId") UUID raidGroupId, @RequestParam("raidGroupName") String raidGroupName, @RequestParam("gameId") UUID gameId, @RequestParam(value = "raidGroupIcon", required = false) String raidGroupIcon){
|
||||
log.info("Updating raid group {}", raidGroupName);
|
||||
|
||||
@@ -136,6 +137,7 @@ public class RaidGroupController{
|
||||
|
||||
@DeleteMapping("/{raidGroupId}")
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
@RaidGroupAuthorization(permissions = {RaidGroupPermissionType.ADMIN})
|
||||
public ObjectNode deleteRaidGroup(@PathVariable("raidGroupId") UUID raidGroupId){
|
||||
log.info("Deleting raid group {}", raidGroupId);
|
||||
|
||||
@@ -149,6 +151,8 @@ public class RaidGroupController{
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
|
||||
//!Game
|
||||
@GetMapping("/game/{gameId}")
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
public List<RaidGroup> getRaidGroupsByGame(@PathVariable("gameId") UUID gameId, @RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam(value = "searchTerm", required = false) String searchTermString){
|
||||
@@ -186,6 +190,48 @@ public class RaidGroupController{
|
||||
countNode.put("status", "success");
|
||||
|
||||
|
||||
return countNode;
|
||||
}
|
||||
|
||||
|
||||
//!Account
|
||||
@GetMapping("/account/{accountId}")
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
public List<RaidGroup> getRaidGroupsByAccount(@PathVariable("accountId") UUID accountId, @RequestParam("page") int page, @RequestParam("pageSize") int pageSize, @RequestParam(value = "searchTerm", required = false) String searchTermString){
|
||||
log.info("Getting raid groups for account {} page {} of size {} with search term {}", accountId, page, pageSize, searchTermString);
|
||||
|
||||
|
||||
List<RaidGroup> raidGroups;
|
||||
if((searchTermString == null) || (searchTermString.isBlank())){
|
||||
raidGroups = raidGroupService.getRaidGroupsByAccount(accountId, page, pageSize);
|
||||
}
|
||||
else{
|
||||
raidGroups = raidGroupService.getRaidGroupsByAccount(accountId, page, pageSize, searchTermString);
|
||||
}
|
||||
|
||||
|
||||
return raidGroups;
|
||||
}
|
||||
|
||||
@GetMapping("/account/{accountId}/count")
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
public ObjectNode getRaidGroupsCountByAccount(@PathVariable("accountId") UUID accountId, @RequestParam(value = "searchTerm", required = false) String searchTerm){
|
||||
log.info("Getting raid groups count for account {} with search term {}", accountId, searchTerm);
|
||||
|
||||
|
||||
Long raidGroupsCount;
|
||||
if((searchTerm == null) || (searchTerm.isBlank())){
|
||||
raidGroupsCount = raidGroupService.getRaidGroupsCountByAccount(accountId);
|
||||
}
|
||||
else{
|
||||
raidGroupsCount = raidGroupService.getRaidGroupsCountByAccount(accountId, searchTerm);
|
||||
}
|
||||
|
||||
ObjectNode countNode = mapper.createObjectNode();
|
||||
countNode.put("count", raidGroupsCount);
|
||||
countNode.put("status", "success");
|
||||
|
||||
|
||||
return countNode;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,18 @@
|
||||
package com.mattrixwv.raidbuilder.repository.raid_group;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
|
||||
import com.mattrixwv.raidbuilder.entity.RaidGroup;
|
||||
|
||||
|
||||
public interface RaidGroupCustomRepository{
|
||||
public List<RaidGroup> findAllByAccountId(UUID accountId, PageRequest pageRequest);
|
||||
public List<RaidGroup> findAllByAccountIdAndRaidGroupNameContainingIgnoreCase(UUID accountId, String raidGroupName, PageRequest pageRequest);
|
||||
|
||||
public long countAllByAccountId(UUID accountId);
|
||||
public long countAllByAccountIdAndRaidGroupNameContainingIgnoreCase(UUID accountId, String raidGroupName);
|
||||
}
|
||||
|
||||
@@ -1,9 +1,91 @@
|
||||
package com.mattrixwv.raidbuilder.repository.raid_group;
|
||||
|
||||
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.springframework.data.domain.PageRequest;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import com.mattrixwv.raidbuilder.entity.RaidGroup;
|
||||
|
||||
import jakarta.persistence.EntityManager;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
|
||||
|
||||
@Repository
|
||||
@RequiredArgsConstructor
|
||||
public class RaidGroupRepositoryImpl implements RaidGroupCustomRepository{
|
||||
private final EntityManager entityManager;
|
||||
|
||||
|
||||
@Override
|
||||
public List<RaidGroup> findAllByAccountId(UUID accountId, PageRequest pageRequest){
|
||||
String selectString = """
|
||||
SELECT rg FROM RaidGroup rg
|
||||
INNER JOIN RaidGroupPermission rgp ON rg.raidGroupId = rgp.raidGroupId
|
||||
WHERE rgp.accountId = :accountId
|
||||
ORDER BY rg.raidGroupName ASC
|
||||
""";
|
||||
|
||||
List<RaidGroup> raidGroups = entityManager.createQuery(selectString, RaidGroup.class)
|
||||
.setParameter("accountId", accountId)
|
||||
.setFirstResult(pageRequest.getPageNumber() * pageRequest.getPageSize())
|
||||
.setMaxResults(pageRequest.getPageSize())
|
||||
.getResultList();
|
||||
|
||||
return raidGroups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<RaidGroup> findAllByAccountIdAndRaidGroupNameContainingIgnoreCase(UUID accountId, String raidGroupName, PageRequest pageRequest){
|
||||
String selectString = """
|
||||
SELECT rg FROM RaidGroup rg
|
||||
INNER JOIN RaidGroupPermission rgp ON rg.raidGroupId = rgp.raidGroupId
|
||||
WHERE rgp.accountId = :accountId
|
||||
AND LOWER(rg.raidGroupName) LIKE LOWER(:raidGroupName)
|
||||
ORDER BY rg.raidGroupName ASC
|
||||
""";
|
||||
|
||||
List<RaidGroup> raidGroups = entityManager.createQuery(selectString, RaidGroup.class)
|
||||
.setParameter("accountId", accountId)
|
||||
.setParameter("raidGroupName", "%" + raidGroupName + "%")
|
||||
.setFirstResult(pageRequest.getPageNumber() * pageRequest.getPageSize())
|
||||
.setMaxResults(pageRequest.getPageSize())
|
||||
.getResultList();
|
||||
|
||||
return raidGroups;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countAllByAccountId(UUID accountId){
|
||||
String selectString = """
|
||||
SELECT count(rg) FROM RaidGroup rg
|
||||
INNER JOIN RaidGroupPermission rgp ON rg.raidGroupId = rgp.raidGroupId
|
||||
WHERE rgp.accountId = :accountId
|
||||
""";
|
||||
|
||||
Long count = entityManager.createQuery(selectString, Long.class)
|
||||
.setParameter("accountId", accountId)
|
||||
.getSingleResult();
|
||||
|
||||
return count;
|
||||
}
|
||||
|
||||
@Override
|
||||
public long countAllByAccountIdAndRaidGroupNameContainingIgnoreCase(UUID accountId, String raidGroupName) {
|
||||
String selectString = """
|
||||
SELECT count(rg) FROM RaidGroup rg
|
||||
INNER JOIN RaidGroupPermission rgp ON rg.raidGroupId = rgp.raidGroupId
|
||||
WHERE rgp.accountId = :accountId
|
||||
AND LOWER(rg.raidGroupName) LIKE LOWER(:raidGroupName)
|
||||
""";
|
||||
|
||||
Long count = entityManager.createQuery(selectString, Long.class)
|
||||
.setParameter("accountId", accountId)
|
||||
.setParameter("raidGroupName", "%" + raidGroupName + "%")
|
||||
.getSingleResult();
|
||||
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,12 +10,16 @@ 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.security.core.context.SecurityContextHolder;
|
||||
import org.springframework.security.oauth2.jwt.Jwt;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
import org.springframework.web.multipart.MultipartFile;
|
||||
|
||||
import com.mattrixwv.raidbuilder.entity.RaidGroup;
|
||||
import com.mattrixwv.raidbuilder.entity.RaidGroupPermission;
|
||||
import com.mattrixwv.raidbuilder.repository.raid_group.RaidGroupRepository;
|
||||
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.RaidGroupPermissionType;
|
||||
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
@@ -36,6 +40,7 @@ public class RaidGroupService{
|
||||
|
||||
//Write
|
||||
public RaidGroup createRaidGroup(RaidGroup raidGroup, MultipartFile file){
|
||||
//Upload the icon
|
||||
if(file != null){
|
||||
String fileName = UUID.randomUUID().toString() + "--" + file.getOriginalFilename();
|
||||
Path filePath = Paths.get(uploadFileDirectory + "/raidGroupIcons").resolve(fileName);
|
||||
@@ -49,7 +54,20 @@ public class RaidGroupService{
|
||||
throw new RuntimeException("Error uploading file: " + error.getMessage(), error);
|
||||
}
|
||||
}
|
||||
return raidGroupRepository.save(raidGroup);
|
||||
|
||||
//Save the raid group
|
||||
raidGroup = raidGroupRepository.save(raidGroup);
|
||||
|
||||
//Add the current user as an admin of the raid group
|
||||
RaidGroupPermission raidGroupPermission = new RaidGroupPermission();
|
||||
raidGroupPermission.setRaidGroupId(raidGroup.getRaidGroupId());
|
||||
raidGroupPermission.setPermission(RaidGroupPermissionType.ADMIN);
|
||||
UUID accountId = UUID.fromString(((Jwt)SecurityContextHolder.getContext().getAuthentication().getPrincipal()).getClaimAsString("accountId"));
|
||||
raidGroupPermission.setAccountId(accountId);
|
||||
raidGroupPermissionService.createRaidGroupPermission(raidGroupPermission);
|
||||
|
||||
|
||||
return raidGroup;
|
||||
}
|
||||
|
||||
public RaidGroup updateRaidGroup(RaidGroup raidGroup, MultipartFile file){
|
||||
@@ -138,6 +156,15 @@ public class RaidGroupService{
|
||||
return raidGroupRepository.findAllByGameIdAndRaidGroupNameContainingIgnoreCase(gameId, searchTerm, PageRequest.of(page, pageSize, Sort.by("raidGroupName").ascending()));
|
||||
}
|
||||
|
||||
public List<RaidGroup> getRaidGroupsByAccount(UUID accountId, int page, int pageSize){
|
||||
return raidGroupRepository.findAllByAccountId(accountId, PageRequest.of(page, pageSize, Sort.by("raidGroupName").ascending()));
|
||||
}
|
||||
|
||||
public List<RaidGroup> getRaidGroupsByAccount(UUID accountId, int page, int pageSize, String searchTerm){
|
||||
return raidGroupRepository.findAllByAccountIdAndRaidGroupNameContainingIgnoreCase(accountId, searchTerm, PageRequest.of(page, pageSize, Sort.by("raidGroupName").ascending()));
|
||||
}
|
||||
|
||||
//!Count
|
||||
public long getRaidGroupsCount(){
|
||||
return raidGroupRepository.count();
|
||||
}
|
||||
@@ -153,4 +180,12 @@ public class RaidGroupService{
|
||||
public long getRaidGroupsCountByGame(UUID gameId, String searchTerm){
|
||||
return raidGroupRepository.countAllByGameIdAndRaidGroupNameContainingIgnoreCase(gameId, searchTerm);
|
||||
}
|
||||
|
||||
public long getRaidGroupsCountByAccount(UUID accountId){
|
||||
return raidGroupRepository.countAllByAccountId(accountId);
|
||||
}
|
||||
|
||||
public long getRaidGroupsCountByAccount(UUID accountId, String searchTerm){
|
||||
return raidGroupRepository.countAllByAccountIdAndRaidGroupNameContainingIgnoreCase(accountId, searchTerm);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user