@@ -26,9 +26,16 @@ export class ModuleGalleryService {
2626 * @param params - Optional query params
2727 */
2828 async fetchGalleryItems ( moduleId : string , params ?: Record < string , any > ) : Promise < any [ ] > {
29- // TODO: Implement API call using fetch/axios, etc.
30- // Example: `${this.config.apiBaseUrl}/modules/${moduleId}/gallery`
31- return [ ] ;
29+ const url = new URL ( '/api/v2/rest/mixcore/module-gallery/get-module-gallery' , this . config . apiBaseUrl ) ;
30+ url . searchParams . append ( 'moduleId' , String ( moduleId ) ) ;
31+ if ( params ) {
32+ Object . entries ( params ) . forEach ( ( [ k , v ] ) => url . searchParams . append ( k , String ( v ) ) ) ;
33+ }
34+ const res = await fetch ( url . toString ( ) , {
35+ headers : this . config . apiKey ? { 'Authorization' : `Bearer ${ this . config . apiKey } ` } : undefined ,
36+ } ) ;
37+ if ( ! res . ok ) throw new Error ( `GET ${ url } : ${ res . status } ${ res . statusText } ` ) ;
38+ return res . json ( ) ;
3239 }
3340
3441 /**
@@ -37,9 +44,22 @@ export class ModuleGalleryService {
3744 * @param file - File or data to upload
3845 * @param meta - Optional metadata
3946 */
40- async uploadGalleryItem ( moduleId : string , file : any , meta ?: Record < string , any > ) : Promise < any > {
41- // TODO: Implement upload logic
42- return { } ;
47+ async uploadGalleryItem ( moduleId : string , file : File | Blob , meta ?: Record < string , any > ) : Promise < any > {
48+ const url = new URL ( `/api/v2/rest/mixcore/module-gallery/${ moduleId } /upload` , this . config . apiBaseUrl ) ;
49+ const formData = new FormData ( ) ;
50+ formData . append ( 'file' , file ) ;
51+ if ( meta ) {
52+ Object . entries ( meta ) . forEach ( ( [ k , v ] ) => formData . append ( k , String ( v ) ) ) ;
53+ }
54+ const res = await fetch ( url . toString ( ) , {
55+ method : 'POST' ,
56+ headers : {
57+ ...( this . config . apiKey ? { 'Authorization' : `Bearer ${ this . config . apiKey } ` } : { } ) ,
58+ } ,
59+ body : formData ,
60+ } ) ;
61+ if ( ! res . ok ) throw new Error ( `POST ${ url } : ${ res . status } ${ res . statusText } ` ) ;
62+ return res . json ( ) ;
4363 }
4464
4565 /**
@@ -48,7 +68,12 @@ export class ModuleGalleryService {
4868 * @param itemId - The gallery item identifier
4969 */
5070 async deleteGalleryItem ( moduleId : string , itemId : string ) : Promise < boolean > {
51- // TODO: Implement delete logic
71+ const url = new URL ( `/api/v2/rest/mixcore/module-gallery/${ moduleId } /${ itemId } ` , this . config . apiBaseUrl ) ;
72+ const res = await fetch ( url . toString ( ) , {
73+ method : 'DELETE' ,
74+ headers : this . config . apiKey ? { 'Authorization' : `Bearer ${ this . config . apiKey } ` } : undefined ,
75+ } ) ;
76+ if ( ! res . ok ) throw new Error ( `DELETE ${ url } : ${ res . status } ${ res . statusText } ` ) ;
5277 return true ;
5378 }
5479}
0 commit comments