Skip to content

Commit

Permalink
Cloudinary has been integrated.
Browse files Browse the repository at this point in the history
  • Loading branch information
CerenBdk committed Jun 2, 2021
1 parent e394575 commit 77ba0df
Show file tree
Hide file tree
Showing 7 changed files with 110 additions and 36 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,27 +9,37 @@
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import org.springframework.web.multipart.MultipartFile;

import com.google.common.net.MediaType;

import kodlamaio.hrms.business.abstracts.ImageForCVService;
import kodlamaio.hrms.business.abstracts.JobseekerService;
import kodlamaio.hrms.core.utilities.results.DataResult;
import kodlamaio.hrms.core.utilities.results.Result;
import kodlamaio.hrms.entities.concretes.ImageForCV;
import kodlamaio.hrms.entities.concretes.Jobseeker;

@RestController
@RequestMapping("/api/images")
public class ImagesController {

private ImageForCVService imageForCVService;
private JobseekerService jobseekerService;

@Autowired
public ImagesController(ImageForCVService imageForCVService) {
public ImagesController(ImageForCVService imageForCVService, JobseekerService jobseekerService) {
super();
this.imageForCVService = imageForCVService;
this.jobseekerService = jobseekerService;
}

@PostMapping("/add")
public Result add(@RequestBody ImageForCV imageForCV){
return this.imageForCVService.add(imageForCV);
@PostMapping(value = "/add")
public Result add(@RequestParam(value = "id") int id, @RequestParam(value = "imageFile") MultipartFile imageFile){
Jobseeker jobseeker = this.jobseekerService.getById(id).getData();
ImageForCV imageForCV = new ImageForCV();
imageForCV.setJobseeker(jobseeker);
return this.imageForCVService.add(imageForCV, imageFile);
}

@PostMapping("/update")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@

import java.util.List;

import org.springframework.web.multipart.MultipartFile;

import kodlamaio.hrms.core.utilities.results.DataResult;
import kodlamaio.hrms.core.utilities.results.Result;
import kodlamaio.hrms.entities.concretes.ImageForCV;

public interface ImageForCVService {
Result add(ImageForCV imageForCV);
Result add(ImageForCV imageForCV, MultipartFile imageFile);
Result update(ImageForCV imageForCV);
Result delete(int id);
DataResult<ImageForCV> getById(int id);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,9 +10,9 @@
public interface JobseekerService {

Result add(Jobseeker jobseeker);
// Result update(Jobseeker jobseeker);
// Result delete(int id);
// DataResult<Jobseeker> getById(int id);
Result update(Jobseeker jobseeker);
Result delete(int id);
DataResult<Jobseeker> getById(int id);

DataResult<List<Jobseeker>> getAll();
DataResult<Jobseeker> getJobseekerByNationalId(String nationalId);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,32 +1,44 @@
package kodlamaio.hrms.business.concretes;

import java.util.List;
import java.util.Map;

import javax.swing.plaf.multi.MultiInternalFrameUI;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.cloudinary.Url;

import kodlamaio.hrms.business.abstracts.ImageForCVService;
import kodlamaio.hrms.business.abstracts.JobseekerService;
import kodlamaio.hrms.core.utilities.imageUpload.ImageUploadService;
import kodlamaio.hrms.core.utilities.results.DataResult;
import kodlamaio.hrms.core.utilities.results.Result;
import kodlamaio.hrms.core.utilities.results.SuccessDataResult;
import kodlamaio.hrms.core.utilities.results.SuccessResult;
import kodlamaio.hrms.dataAccess.abstracts.ImageForCVDao;
import kodlamaio.hrms.entities.concretes.ImageForCV;
import kodlamaio.hrms.entities.concretes.Jobseeker;

@Service
public class ImageForCVManager implements ImageForCVService{

private ImageForCVDao imageForCVDao;

@Autowired
private ImageUploadService imageUploadService;

public ImageForCVManager(ImageForCVDao imageForCVDao) {
@Autowired
public ImageForCVManager(ImageForCVDao imageForCVDao, ImageUploadService imageUploadService) {
super();
this.imageForCVDao = imageForCVDao;
this.imageUploadService = imageUploadService;
}

@Override
public Result add(ImageForCV imageForCV) {
public Result add(ImageForCV imageForCV , MultipartFile imageFile) {
Map<String,String> uploadImage = this.imageUploadService.uploadImageFile(imageFile).getData();
imageForCV.setUrl(uploadImage.get("url"));
this.imageForCVDao.save(imageForCV);
return new SuccessResult("Image has been added.");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,8 @@
import kodlamaio.hrms.entities.dtos.JobSeekerCVDto;
import net.bytebuddy.asm.Advice.This;


@Service
public class JobseekerManager implements JobseekerService{
public class JobseekerManager implements JobseekerService {

private JobseekerDao jobseekerDao;
private ExperienceForCVService experienceForCVService;
Expand All @@ -32,8 +31,6 @@ public class JobseekerManager implements JobseekerService{
private LinkForCVService linkForCVService;
private ProgrammingSkillForCVService programmingSkillForCVService;
private SchoolForCVService schoolForCVService;



public JobseekerManager(JobseekerDao jobseekerDao, ExperienceForCVService experienceForCVService,
ForeignLanguageForCVService foreignLanguageForCVService, ImageForCVService imageForCVService,
Expand All @@ -52,25 +49,25 @@ public JobseekerManager(JobseekerDao jobseekerDao, ExperienceForCVService experi
@Override
public Result add(Jobseeker jobseeker) {
this.jobseekerDao.save(jobseeker);
return new SuccessResult("Jobseeker has been added.");
return new SuccessResult("Jobseeker has been added.");
}

@Override
public Result update(Jobseeker jobseeker) {
this.jobseekerDao.save(jobseeker);
return new SuccessResult("Jobseeker has been updated.");
}

@Override
public Result delete(int id) {
this.jobseekerDao.deleteById(id);
return new SuccessResult("Jobseeker has been deleted.");
}

@Override
public DataResult<Jobseeker> getById(int id) {
return new SuccessDataResult<Jobseeker>(this.jobseekerDao.getById(id));
}
//
// @Override
// public Result update(Jobseeker jobseeker) {
// this.jobseekerDao.save(jobseeker);
// return new SuccessResult("Jobseeker has been updated.");
// }
//
// @Override
// public Result delete(int id) {
// this.jobseekerDao.deleteById(id);
// return new SuccessResult("Jobseeker has been deleted.");
// }
//
// @Override
// public DataResult<Jobseeker> getById(int id) {
// return new SuccessDataResult<Jobseeker>(this.jobseekerDao.getById(id));
// }

@Override
public DataResult<List<Jobseeker>> getAll() {
Expand All @@ -93,7 +90,5 @@ public DataResult<JobSeekerCVDto> getJobseekerCVById(int id) {
cv.schools = this.schoolForCVService.getAllByJobseekerId(id).getData();
return new SuccessDataResult<JobSeekerCVDto>(cv);
}



}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
package kodlamaio.hrms.core.utilities.imageUpload;

import java.io.IOException;
import java.util.Map;

import org.springframework.stereotype.Service;
import org.springframework.web.multipart.MultipartFile;

import com.cloudinary.Cloudinary;
import com.cloudinary.utils.ObjectUtils;

import kodlamaio.hrms.core.utilities.results.DataResult;
import kodlamaio.hrms.core.utilities.results.ErrorDataResult;
import kodlamaio.hrms.core.utilities.results.SuccessDataResult;

@Service
public class ImageUploadManager implements ImageUploadService{

private Cloudinary cloudinary;

public ImageUploadManager() {

this.cloudinary = new Cloudinary(ObjectUtils.asMap(
"cloud_name", "dayx2sam5",
"api_key", "699443261618643",
"api_secret", "LaC_8aO4_p-vseLXfpOJGuC-sjI"));
}

@Override
public DataResult<Map> uploadImageFile(MultipartFile imageFile) {
try {
@SuppressWarnings("unchecked")
Map<String, String> resultMap =(Map<String, String>) cloudinary.uploader().upload(imageFile.getBytes(), ObjectUtils.emptyMap());
return new SuccessDataResult<Map>(resultMap);
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();

}
return new ErrorDataResult<Map>();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package kodlamaio.hrms.core.utilities.imageUpload;

import java.util.Map;

import org.springframework.web.multipart.MultipartFile;

import kodlamaio.hrms.core.utilities.results.DataResult;

public interface ImageUploadService {

DataResult<Map> uploadImageFile(MultipartFile imageFile);
}

0 comments on commit 77ba0df

Please sign in to comment.