diff --git a/db/1.0.0/11. createRaidGroupCalendarEvent.sql b/db/1.0.0/11. createRaidGroupCalendarEvent.sql new file mode 100644 index 0000000..9894a95 --- /dev/null +++ b/db/1.0.0/11. createRaidGroupCalendarEvent.sql @@ -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; diff --git a/db/1.0.0/9. createGameCalendarEvent.sql b/db/1.0.0/9. createGameCalendarEvent.sql index ea615e8..9d44311 100644 --- a/db/1.0.0/9. createGameCalendarEvent.sql +++ b/db/1.0.0/9. createGameCalendarEvent.sql @@ -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, diff --git a/src/main/java/com/mattrixwv/raidbuilder/controller/CalendarController.java b/src/main/java/com/mattrixwv/raidbuilder/controller/CalendarController.java index d8f2374..ce2478b 100644 --- a/src/main/java/com/mattrixwv/raidbuilder/controller/CalendarController.java +++ b/src/main/java/com/mattrixwv/raidbuilder/controller/CalendarController.java @@ -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 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; + } } diff --git a/src/main/java/com/mattrixwv/raidbuilder/entity/RaidGroupCalendarEvent.java b/src/main/java/com/mattrixwv/raidbuilder/entity/RaidGroupCalendarEvent.java new file mode 100644 index 0000000..a85d9ac --- /dev/null +++ b/src/main/java/com/mattrixwv/raidbuilder/entity/RaidGroupCalendarEvent.java @@ -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; + } +} diff --git a/src/main/java/com/mattrixwv/raidbuilder/repository/raid_group_calendar_event/RaidGroupCalendarEventCustomRepository.java b/src/main/java/com/mattrixwv/raidbuilder/repository/raid_group_calendar_event/RaidGroupCalendarEventCustomRepository.java new file mode 100644 index 0000000..b9e626b --- /dev/null +++ b/src/main/java/com/mattrixwv/raidbuilder/repository/raid_group_calendar_event/RaidGroupCalendarEventCustomRepository.java @@ -0,0 +1,5 @@ +package com.mattrixwv.raidbuilder.repository.raid_group_calendar_event; + + +public interface RaidGroupCalendarEventCustomRepository{ +} diff --git a/src/main/java/com/mattrixwv/raidbuilder/repository/raid_group_calendar_event/RaidGroupCalendarEventRepository.java b/src/main/java/com/mattrixwv/raidbuilder/repository/raid_group_calendar_event/RaidGroupCalendarEventRepository.java new file mode 100644 index 0000000..68a7c74 --- /dev/null +++ b/src/main/java/com/mattrixwv/raidbuilder/repository/raid_group_calendar_event/RaidGroupCalendarEventRepository.java @@ -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{ + public void deleteAllByRaidGroupId(UUID raidGroupId); + public void deleteAllByRaidGroupIdIn(Iterable raidGroupIds); + + + public List findAllByRaidGroupId(UUID raidGroupId); +} diff --git a/src/main/java/com/mattrixwv/raidbuilder/repository/raid_group_calendar_event/RaidGroupCalendarEventRepositoryImpl.java b/src/main/java/com/mattrixwv/raidbuilder/repository/raid_group_calendar_event/RaidGroupCalendarEventRepositoryImpl.java new file mode 100644 index 0000000..c2c7369 --- /dev/null +++ b/src/main/java/com/mattrixwv/raidbuilder/repository/raid_group_calendar_event/RaidGroupCalendarEventRepositoryImpl.java @@ -0,0 +1,9 @@ +package com.mattrixwv.raidbuilder.repository.raid_group_calendar_event; + + +import org.springframework.stereotype.Repository; + + +@Repository +public class RaidGroupCalendarEventRepositoryImpl implements RaidGroupCalendarEventCustomRepository{ +} diff --git a/src/main/java/com/mattrixwv/raidbuilder/service/RaidGroupCalendarEventService.java b/src/main/java/com/mattrixwv/raidbuilder/service/RaidGroupCalendarEventService.java new file mode 100644 index 0000000..3c8fe51 --- /dev/null +++ b/src/main/java/com/mattrixwv/raidbuilder/service/RaidGroupCalendarEventService.java @@ -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 raidGroupIds){ + rgceRepository.deleteAllByRaidGroupIdIn(raidGroupIds); + } + + + //Read + public List getByRaidGroupId(UUID raidGroupId){ + return rgceRepository.findAllByRaidGroupId(raidGroupId); + } +} diff --git a/src/main/java/com/mattrixwv/raidbuilder/service/RaidGroupService.java b/src/main/java/com/mattrixwv/raidbuilder/service/RaidGroupService.java index 5a12480..94888da 100644 --- a/src/main/java/com/mattrixwv/raidbuilder/service/RaidGroupService.java +++ b/src/main/java/com/mattrixwv/raidbuilder/service/RaidGroupService.java @@ -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 raidGroupIds = raidGroups.stream().map(RaidGroup::getRaidGroupId).toList(); + raidGroupCalendarEventService.deleteByRaidGroupIds(raidGroupIds); + raidGroupPermissionService.deleteByRaidGroupIds(raidGroupIds); raidGroupRepository.flush(); raidGroupRepository.deleteAll(raidGroups);