Game calendar working
This commit is contained in:
@@ -0,0 +1,93 @@
|
||||
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.RequestBody;
|
||||
import org.springframework.web.bind.annotation.RequestMapping;
|
||||
import org.springframework.web.bind.annotation.RestController;
|
||||
|
||||
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.GameCalendarEvent;
|
||||
import com.mattrixwv.raidbuilder.service.GameCalendarEventService;
|
||||
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("/calendar")
|
||||
@RequiredArgsConstructor
|
||||
public class CalendarController{
|
||||
private final ObjectMapper mapper;
|
||||
private final GameCalendarEventService gceService;
|
||||
|
||||
|
||||
@GetMapping("/game/{gameId}")
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
public List<GameCalendarEvent> getGameCalendarEvents(@PathVariable("gameId") UUID gameId){
|
||||
log.info("Getting calendar events for game {}", gameId);
|
||||
|
||||
|
||||
return gceService.getByGameId(gameId);
|
||||
}
|
||||
|
||||
@PostMapping("/game/{gameId}")
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
@GameAuthorization(permissions = {GamePermissionType.ADMIN})
|
||||
public ObjectNode createGameCalendarEvent(@PathVariable("gameId") UUID gameId, @RequestBody GameCalendarEvent gameCalendarEvent){
|
||||
log.info("Creating calendar event for game {}", gameId);
|
||||
|
||||
|
||||
gameCalendarEvent.setGameId(gameId);
|
||||
gceService.createGameCalendarEvent(gameCalendarEvent);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
returnNode.put("status", "success");
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
@PutMapping("/game/{gameId}")
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
@GameAuthorization(permissions = {GamePermissionType.ADMIN})
|
||||
public ObjectNode updateGameCalendarEvent(@PathVariable("gameId") UUID gameId, @RequestBody GameCalendarEvent gameCalendarEvent){
|
||||
log.info("Updating calendar event for game {}", gameId);
|
||||
|
||||
|
||||
gameCalendarEvent.setGameId(gameId);
|
||||
gceService.updateGameCalendarEvent(gameCalendarEvent);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
returnNode.put("status", "success");
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
@DeleteMapping("/game/{gameId}/{calendarEventId}")
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
@GameAuthorization(permissions = {GamePermissionType.ADMIN})
|
||||
public ObjectNode deleteGameCalendarEvent(@PathVariable("gameId") UUID gameId, @PathVariable("calendarEventId") UUID calendarEventId){
|
||||
log.info("Deleting calendar event for game {}", gameId);
|
||||
|
||||
|
||||
gceService.deleteGameCalendarEvent(calendarEventId);
|
||||
|
||||
ObjectNode returnNode = mapper.createObjectNode();
|
||||
returnNode.put("status", "success");
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
}
|
||||
@@ -148,4 +148,44 @@ public class RaidGroupController{
|
||||
|
||||
return returnNode;
|
||||
}
|
||||
|
||||
@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){
|
||||
log.info("Getting raid groups for game {} page {} of size {} with search term {}", gameId, page, pageSize, searchTermString);
|
||||
|
||||
|
||||
List<RaidGroup> raidGroups;
|
||||
if((searchTermString == null) || (searchTermString.isBlank())){
|
||||
raidGroups = raidGroupService.getRaidGroupsByGame(gameId, page, pageSize);
|
||||
}
|
||||
else{
|
||||
raidGroups = raidGroupService.getRaidGroupsByGame(gameId, page, pageSize, searchTermString);
|
||||
}
|
||||
|
||||
|
||||
return raidGroups;
|
||||
}
|
||||
|
||||
@GetMapping("/game/{gameId}/count")
|
||||
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
|
||||
public ObjectNode getRaidGroupsCountByGame(@PathVariable("gameId") UUID gameId, @RequestParam(value = "searchTerm", required = false) String searchTerm){
|
||||
log.info("Getting raid groups count for game {} with search term {}", gameId, searchTerm);
|
||||
|
||||
|
||||
Long raidGroupsCount;
|
||||
if((searchTerm == null) || (searchTerm.isBlank())){
|
||||
raidGroupsCount = raidGroupService.getRaidGroupsCountByGame(gameId);
|
||||
}
|
||||
else{
|
||||
raidGroupsCount = raidGroupService.getRaidGroupsCountByGame(gameId, searchTerm);
|
||||
}
|
||||
|
||||
ObjectNode countNode = mapper.createObjectNode();
|
||||
countNode.put("count", raidGroupsCount);
|
||||
countNode.put("status", "success");
|
||||
|
||||
|
||||
return countNode;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user