Raid Group calendar working

This commit is contained in:
2025-03-07 21:54:30 -05:00
parent 18f048bc3b
commit 3e0996c432
9 changed files with 214 additions and 2 deletions

View File

@@ -0,0 +1,18 @@
CREATE TABLE raid_builder.raid_group_calendar_event(
raid_group_calendar_event_id uuid PRIMARY KEY,
raid_group_id uuid REFERENCES raid_builder.raid_group(raid_group_id) NOT NULL,
event_name text NOT NULL,
event_description text,
event_start_date timestamptz NOT NULL,
event_end_date timestamptz NOT NULL,
--Auditing
modified_by uuid,
modified_date timestamptz,
created_by uuid NOT NULL,
created_date timestamptz NOT NULL
);
CREATE INDEX idx_raid_group_calendar_event_raid_group_id ON raid_builder.raid_group_calendar_event(raid_group_id);
GRANT ALL ON TABLE raid_builder.raid_group_calendar_event TO raid_builder;

View File

@@ -1,6 +1,6 @@
CREATE TABLE raid_builder.game_calendar_event(
game_calendar_event_id uuid PRIMARY KEY,
game_id uuid REFERENCES raid_builder.game(game_id),
game_id uuid REFERENCES raid_builder.game(game_id) NOT NULL,
event_name text NOT NULL,
event_description text,
event_start_date timestamptz NOT NULL,

View File

@@ -17,10 +17,14 @@ 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.annotation.RaidGroupAuthorization;
import com.mattrixwv.raidbuilder.entity.GameCalendarEvent;
import com.mattrixwv.raidbuilder.entity.RaidGroupCalendarEvent;
import com.mattrixwv.raidbuilder.service.GameCalendarEventService;
import com.mattrixwv.raidbuilder.service.RaidGroupCalendarEventService;
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.AccountPermissionType;
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.GamePermissionType;
import com.mattrixwv.raidbuilder.util.DatabaseTypeUtil.RaidGroupPermissionType;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@@ -33,6 +37,7 @@ import lombok.extern.slf4j.Slf4j;
public class CalendarController{
private final ObjectMapper mapper;
private final GameCalendarEventService gceService;
private final RaidGroupCalendarEventService rgceService;
@GetMapping("/game/{gameId}")
@@ -90,4 +95,63 @@ public class CalendarController{
return returnNode;
}
//!Calendar
@GetMapping("/raidGroup/{raidGroupId}")
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
@RaidGroupAuthorization(permissions = {RaidGroupPermissionType.ADMIN, RaidGroupPermissionType.LEADER, RaidGroupPermissionType.RAIDER})
public List<RaidGroupCalendarEvent> getGameCalendarEventsByRaidGroup(@PathVariable("raidGroupId") UUID raidGroupId){
log.info("Getting calendar events for raid group {}", raidGroupId);
return rgceService.getByRaidGroupId(raidGroupId);
}
@PostMapping("/raidGroup/{raidGroupId}")
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
@RaidGroupAuthorization(permissions = {RaidGroupPermissionType.ADMIN, RaidGroupPermissionType.LEADER})
public ObjectNode createRaidGroupCalendarEvent(@PathVariable("raidGroupId") UUID raidGroupId, @RequestBody RaidGroupCalendarEvent raidGroupCalendarEvent){
log.info("Creating calendar event for raid group {}", raidGroupId);
raidGroupCalendarEvent.setRaidGroupId(raidGroupId);
rgceService.createRaidGroupCalendarEvent(raidGroupCalendarEvent);
ObjectNode returnNode = mapper.createObjectNode();
returnNode.put("status", "success");
return returnNode;
}
@PutMapping("/raidGroup/{raidGroupId}")
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
@RaidGroupAuthorization(permissions = {RaidGroupPermissionType.ADMIN, RaidGroupPermissionType.LEADER})
public ObjectNode updateRaidGroupCalendarEvent(@PathVariable("raidGroupId") UUID raidGroupId, @RequestBody RaidGroupCalendarEvent raidGroupCalendarEvent){
log.info("Updating calendar event for raid group {}", raidGroupId);
raidGroupCalendarEvent.setRaidGroupId(raidGroupId);
rgceService.updateRaidGroupCalendarEvent(raidGroupCalendarEvent);
ObjectNode returnNode = mapper.createObjectNode();
returnNode.put("status", "success");
return returnNode;
}
@DeleteMapping("/raidGroup/{raidGroupId}/{calendarEventId}")
@AccountAuthorization(permissions = {AccountPermissionType.ADMIN, AccountPermissionType.USER})
@RaidGroupAuthorization(permissions = {RaidGroupPermissionType.ADMIN, RaidGroupPermissionType.LEADER})
public ObjectNode deleteRaidGroupCalendarEvent(@PathVariable("raidGroupId") UUID raidGroupId, @PathVariable("calendarEventId") UUID calendarEventId){
log.info("Deleting calendar event for raid group {}", raidGroupId);
rgceService.deleteRaidGroupCalendarEvent(calendarEventId);
ObjectNode returnNode = mapper.createObjectNode();
returnNode.put("status", "success");
return returnNode;
}
}

View File

@@ -0,0 +1,43 @@
package com.mattrixwv.raidbuilder.entity;
import java.time.ZonedDateTime;
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 = "raid_group_calendar_event", schema = "raid_builder")
@Data
@EqualsAndHashCode(callSuper = false)
@NoArgsConstructor
public class RaidGroupCalendarEvent extends AuditableEntity{
@Id
@Column(name = "raid_group_calendar_event_id")
@GeneratedValue(strategy = GenerationType.UUID)
private UUID raidGroupCalendarEventId;
@Column(name = "raid_group_id")
private UUID raidGroupId;
@Column(name = "event_name")
private String eventName;
@Column(name = "event_description")
private String eventDescription;
@Column(name = "event_start_date")
private ZonedDateTime eventStartDate;
@Column(name = "event_end_date")
private ZonedDateTime eventEndDate;
public UUID getCalendarEventId(){
return raidGroupCalendarEventId;
}
}

View File

@@ -0,0 +1,5 @@
package com.mattrixwv.raidbuilder.repository.raid_group_calendar_event;
public interface RaidGroupCalendarEventCustomRepository{
}

View File

@@ -0,0 +1,18 @@
package com.mattrixwv.raidbuilder.repository.raid_group_calendar_event;
import java.util.List;
import java.util.UUID;
import org.springframework.data.jpa.repository.JpaRepository;
import com.mattrixwv.raidbuilder.entity.RaidGroupCalendarEvent;
public interface RaidGroupCalendarEventRepository extends RaidGroupCalendarEventCustomRepository, JpaRepository<RaidGroupCalendarEvent, UUID>{
public void deleteAllByRaidGroupId(UUID raidGroupId);
public void deleteAllByRaidGroupIdIn(Iterable<UUID> raidGroupIds);
public List<RaidGroupCalendarEvent> findAllByRaidGroupId(UUID raidGroupId);
}

View File

@@ -0,0 +1,9 @@
package com.mattrixwv.raidbuilder.repository.raid_group_calendar_event;
import org.springframework.stereotype.Repository;
@Repository
public class RaidGroupCalendarEventRepositoryImpl implements RaidGroupCalendarEventCustomRepository{
}

View File

@@ -0,0 +1,51 @@
package com.mattrixwv.raidbuilder.service;
import java.util.List;
import java.util.UUID;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import com.mattrixwv.raidbuilder.entity.RaidGroupCalendarEvent;
import com.mattrixwv.raidbuilder.repository.raid_group_calendar_event.RaidGroupCalendarEventRepository;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
@Slf4j
@Service
@Transactional(rollbackFor = Exception.class)
@RequiredArgsConstructor
public class RaidGroupCalendarEventService{
private final RaidGroupCalendarEventRepository rgceRepository;
//Write
public RaidGroupCalendarEvent createRaidGroupCalendarEvent(RaidGroupCalendarEvent rgce){
return rgceRepository.save(rgce);
}
public RaidGroupCalendarEvent updateRaidGroupCalendarEvent(RaidGroupCalendarEvent rgce){
return rgceRepository.save(rgce);
}
public void deleteRaidGroupCalendarEvent(UUID rgceId){
rgceRepository.deleteById(rgceId);
}
public void deleteByRaidGroupId(UUID raidGroupId){
rgceRepository.deleteAllByRaidGroupId(raidGroupId);
}
public void deleteByRaidGroupIds(Iterable<UUID> raidGroupIds){
rgceRepository.deleteAllByRaidGroupIdIn(raidGroupIds);
}
//Read
public List<RaidGroupCalendarEvent> getByRaidGroupId(UUID raidGroupId){
return rgceRepository.findAllByRaidGroupId(raidGroupId);
}
}

View File

@@ -32,6 +32,7 @@ import lombok.extern.slf4j.Slf4j;
public class RaidGroupService{
private final RaidGroupRepository raidGroupRepository;
//Related Services
private final RaidGroupCalendarEventService raidGroupCalendarEventService;
private final RaidGroupPermissionService raidGroupPermissionService;
//Values
@Value("${uploadFileDirectory}")
@@ -108,6 +109,7 @@ public class RaidGroupService{
existingFile.delete();
}
}
raidGroupCalendarEventService.deleteByRaidGroupId(raidGroupId);
raidGroupPermissionService.deleteByRaidGroupId(raidGroupId);
raidGroupRepository.flush();
@@ -125,7 +127,9 @@ public class RaidGroupService{
}
}
}
raidGroupPermissionService.deleteByRaidGroupIds(raidGroups.stream().map(RaidGroup::getRaidGroupId).toList());
List<UUID> raidGroupIds = raidGroups.stream().map(RaidGroup::getRaidGroupId).toList();
raidGroupCalendarEventService.deleteByRaidGroupIds(raidGroupIds);
raidGroupPermissionService.deleteByRaidGroupIds(raidGroupIds);
raidGroupRepository.flush();
raidGroupRepository.deleteAll(raidGroups);