@ -6,13 +6,9 @@ import type {
GenerateSlotDefinitionsResponse ,
GenerateSlotDefinitionsResponse ,
CloneSlotDefinitionRequest ,
CloneSlotDefinitionRequest ,
CloneSlotDefinitionResponse ,
CloneSlotDefinitionResponse ,
GetPresetsResponse ,
} from '@/src/types/slot-definitions' ;
} from '@/src/types/slot-definitions' ;
import apiFetch from '@/src/utils/apiFetch' ;
const API_BASE_URL = process . env . NEXT_PUBLIC_PYTHON_API_URL ;
if ( ! API_BASE_URL ) {
throw new Error ( 'NEXT_PUBLIC_PYTHON_API_URL environment variable is not defined' ) ;
}
type ApiResult < T > =
type ApiResult < T > =
| { success : true ; data : T }
| { success : true ; data : T }
@ -29,11 +25,10 @@ export async function getSlotDefinitions(
if ( filters ? . active_on ) params . append ( 'active_on' , filters . active_on ) ;
if ( filters ? . active_on ) params . append ( 'active_on' , filters . active_on ) ;
const queryString = params . toString ( ) ;
const queryString = params . toString ( ) ;
const url = ` ${ API_BASE_URL } /admin/clubs/ ${ clubId } /slot-definitions ${ queryString ? ` ? ${ queryString } ` : '' } ` ;
const endpoint = ` /admin/clubs/ ${ clubId } /slot-definitions ${ queryString ? ` ? ${ queryString } ` : '' } ` ;
const response = await fetch( url , {
const response = await apiFetch( endpoint , {
method : 'GET' ,
method : 'GET' ,
credentials : 'include' ,
headers : {
headers : {
'Content-Type' : 'application/json' ,
'Content-Type' : 'application/json' ,
} ,
} ,
@ -66,9 +61,8 @@ export async function createSlotDefinition(
request : SlotDefinitionRequest
request : SlotDefinitionRequest
) : Promise < ApiResult < SlotDefinition > > {
) : Promise < ApiResult < SlotDefinition > > {
try {
try {
const response = await fetch( ` ${ API_BASE_URL } /admin/clubs/ ${ clubId } /slot-definitions ` , {
const response = await apiFetch( ` /admin/clubs/ ${ clubId } /slot-definitions ` , {
method : 'POST' ,
method : 'POST' ,
credentials : 'include' ,
headers : {
headers : {
'Content-Type' : 'application/json' ,
'Content-Type' : 'application/json' ,
} ,
} ,
@ -103,11 +97,10 @@ export async function updateSlotDefinition(
request : Partial < SlotDefinitionRequest >
request : Partial < SlotDefinitionRequest >
) : Promise < ApiResult < SlotDefinition > > {
) : Promise < ApiResult < SlotDefinition > > {
try {
try {
const response = await f etch(
const response = await apiF etch(
` ${ API_BASE_URL } /admin/clubs/ ${ clubId } /slot-definitions/ ${ slotDefinitionId } ` ,
` /admin/clubs/ ${ clubId } /slot-definitions/ ${ slotDefinitionId } ` ,
{
{
method : 'PATCH' ,
method : 'PATCH' ,
credentials : 'include' ,
headers : {
headers : {
'Content-Type' : 'application/json' ,
'Content-Type' : 'application/json' ,
} ,
} ,
@ -142,11 +135,10 @@ export async function deleteSlotDefinition(
slotDefinitionId : number
slotDefinitionId : number
) : Promise < ApiResult < void > > {
) : Promise < ApiResult < void > > {
try {
try {
const response = await f etch(
const response = await apiF etch(
` ${ API_BASE_URL } /admin/clubs/ ${ clubId } /slot-definitions/ ${ slotDefinitionId } ` ,
` /admin/clubs/ ${ clubId } /slot-definitions/ ${ slotDefinitionId } ` ,
{
{
method : 'DELETE' ,
method : 'DELETE' ,
credentials : 'include' ,
}
}
) ;
) ;
@ -170,15 +162,42 @@ export async function deleteSlotDefinition(
}
}
}
}
// GET /admin/slot-definition-presets
export async function getSlotDefinitionPresets ( ) : Promise < ApiResult < GetPresetsResponse > > {
try {
const response = await apiFetch ( '/admin/slot-definition-presets' , {
method : 'GET' ,
} ) ;
if ( ! response . ok ) {
const error : SlotDefinitionError = await response . json ( ) ;
return { success : false , error } ;
}
const data : GetPresetsResponse = await response . json ( ) ;
return { success : true , data } ;
} catch ( error ) {
return {
success : false ,
error : {
type : 'about:blank' ,
title : 'Network Error' ,
status : 0 ,
detail : 'Failed to fetch slot definition presets. Please check your connection.' ,
code : 'network_error' ,
} ,
} ;
}
}
// POST /admin/clubs/{club_id}/slot-definitions/generate
// POST /admin/clubs/{club_id}/slot-definitions/generate
export async function generateSlotDefinitions (
export async function generateSlotDefinitions (
clubId : number ,
clubId : number ,
request : GenerateSlotDefinitionsRequest
request : GenerateSlotDefinitionsRequest
) : Promise < ApiResult < GenerateSlotDefinitionsResponse > > {
) : Promise < ApiResult < GenerateSlotDefinitionsResponse > > {
try {
try {
const response = await fetch ( ` ${ API_BASE_URL } /admin/clubs/ ${ clubId } /slot-definitions/generate ` , {
const response = await apiFetch( ` /admin/clubs/ ${ clubId } /slot-definitions/generate ` , {
method : 'POST' ,
method : 'POST' ,
credentials : 'include' ,
headers : {
headers : {
'Content-Type' : 'application/json' ,
'Content-Type' : 'application/json' ,
} ,
} ,
@ -213,11 +232,10 @@ export async function cloneSlotDefinition(
request : CloneSlotDefinitionRequest
request : CloneSlotDefinitionRequest
) : Promise < ApiResult < CloneSlotDefinitionResponse > > {
) : Promise < ApiResult < CloneSlotDefinitionResponse > > {
try {
try {
const response = await f etch(
const response = await apiF etch(
` ${ API_BASE_URL } /admin/clubs/ ${ clubId } /slot-definitions/ ${ slotDefinitionId } /clone ` ,
` /admin/clubs/ ${ clubId } /slot-definitions/ ${ slotDefinitionId } /clone ` ,
{
{
method : 'POST' ,
method : 'POST' ,
credentials : 'include' ,
headers : {
headers : {
'Content-Type' : 'application/json' ,
'Content-Type' : 'application/json' ,
} ,
} ,