feat: add operating hours and blackout date entities

This commit is contained in:
dualfroz committed 2026-08-26 12:11:22 +02:00
1 parent 36ba1b6a83
commit daabc65fee
4 files changed
+164

No files matched your search

@@ -0,0 +1,61 @@
package com.slotline.availability;
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 java.time.LocalDate;
@Entity
@Table(name = "blackout_date")
public class BlackoutDate {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "resource_id", nullable = false)
private Long resourceId;
@Column(name = "start_date", nullable = false)
private LocalDate startDate;
@Column(name = "end_date", nullable = false)
private LocalDate endDate;
@Column(length = 256)
private String reason;
protected BlackoutDate() {
}
public BlackoutDate(Long resourceId, LocalDate startDate, LocalDate endDate, String reason) {
this.resourceId = resourceId;
this.startDate = startDate;
this.endDate = endDate;
this.reason = reason;
}
public Long getId() {
return id;
}
public Long getResourceId() {
return resourceId;
}
public LocalDate getStartDate() {
return startDate;
}
public LocalDate getEndDate() {
return endDate;
}
public String getReason() {
return reason;
}
}
@@ -0,0 +1,23 @@
package com.slotline.availability;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import java.time.LocalDate;
import java.util.List;
public interface BlackoutDateRepository extends JpaRepository<BlackoutDate, Long> {
List<BlackoutDate> findByResourceIdOrderByStartDateAsc(Long resourceId);
@Query("""
select b from BlackoutDate b
where b.resourceId = :resourceId
and b.startDate <= :until
and b.endDate >= :from
""")
List<BlackoutDate> findOverlapping(@Param("resourceId") Long resourceId,
@Param("from") LocalDate from,
@Param("until") LocalDate until);
}
@@ -0,0 +1,65 @@
package com.slotline.availability;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import java.time.DayOfWeek;
import java.time.LocalTime;
@Entity
@Table(name = "operating_hours")
public class OperatingHours {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
@Column(name = "resource_id", nullable = false)
private Long resourceId;
@Enumerated(EnumType.STRING)
@Column(name = "day_of_week", nullable = false, length = 9)
private DayOfWeek dayOfWeek;
@Column(name = "open_time", nullable = false)
private LocalTime openTime;
@Column(name = "close_time", nullable = false)
private LocalTime closeTime;
protected OperatingHours() {
}
public OperatingHours(Long resourceId, DayOfWeek dayOfWeek, LocalTime openTime, LocalTime closeTime) {
this.resourceId = resourceId;
this.dayOfWeek = dayOfWeek;
this.openTime = openTime;
this.closeTime = closeTime;
}
public Long getId() {
return id;
}
public Long getResourceId() {
return resourceId;
}
public DayOfWeek getDayOfWeek() {
return dayOfWeek;
}
public LocalTime getOpenTime() {
return openTime;
}
public LocalTime getCloseTime() {
return closeTime;
}
}
@@ -0,0 +1,15 @@
package com.slotline.availability;
import org.springframework.data.jpa.repository.JpaRepository;
import java.time.DayOfWeek;
import java.util.List;
public interface OperatingHoursRepository extends JpaRepository<OperatingHours, Long> {
List<OperatingHours> findByResourceId(Long resourceId);
List<OperatingHours> findByResourceIdAndDayOfWeek(Long resourceId, DayOfWeek dayOfWeek);
void deleteByResourceId(Long resourceId);
}