@@ -6,6 +6,7 @@ import type { CreateProjectInput, UpdateProjectInput } from '@/lib/zod/project.s
66import { getRepoNameFromGithubUrl } from '@/utils/github.js' ;
77import { tagServices } from '@/services/tag.service.js' ;
88import { contributorServices } from '@/services/contributor.service.js' ;
9+ import { uploadImageToCloudinary } from '@/utils/cloudinary.uploader.js' ;
910
1011class ProjectController {
1112 async getAllProjects ( req : Request , res : Response ) {
@@ -159,6 +160,33 @@ class ProjectController {
159160 res . status ( HTTP . INTERNAL ) . json ( ErrorResponse ( HTTP . INTERNAL , 'Internal Server Error' ) ) ;
160161 }
161162 }
163+
164+ async uploadImage ( req : Request , res : Response ) {
165+ try {
166+ if ( ! req . file ) return res
167+ . status ( HTTP . BAD_REQUEST )
168+ . json (
169+ ErrorResponse ( HTTP . BAD_REQUEST , "Image is required" )
170+ )
171+ const image = req . file ;
172+
173+ const uploadResult = await uploadImageToCloudinary ( image ! . path , { folder : "projects" } )
174+ if ( ! uploadResult . success ) {
175+ return res
176+ . status ( HTTP . BAD_REQUEST )
177+ . json (
178+ ErrorResponse ( HTTP . BAD_REQUEST , uploadResult . error || 'Failed to upload image.' )
179+ ) ;
180+ }
181+ return res
182+ . status ( HTTP . OK )
183+ . json (
184+ SuccessResponse ( HTTP . OK , "Uploaded successfully" , uploadResult . url )
185+ ) ;
186+ } catch ( error ) {
187+ console . log ( "Error whole uploading image: " , error )
188+ }
189+ }
162190}
163191
164192export const projectController = new ProjectController ( ) ;
0 commit comments