Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feat/be 33 recruiter view applicant #163

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.hydraulic.applyforme.model.domain.Professional;
import com.hydraulic.applyforme.service.ProfessionalService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.*;

Expand All @@ -24,7 +25,5 @@ public List<Professional> findAll(@RequestParam(required = false, defaultValue =
}

@GetMapping("/detail/{id}")
public Professional findOne(@PathVariable(name ="id") Long id) {
return service.findOne(id);
}
public Professional findOne(@PathVariable(name = "id") Long id) {return service.findOne(id);}
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,7 @@

public interface ProfessionalRepository {

Professional getOne(Long id);
List<Professional> getAll(Integer pageOffset);

boolean remove(Long id);

boolean removeMany(List<Long> ids);

boolean removeAll();
Professional getOne(Long id);
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,67 +2,31 @@

import com.hydraulic.applyforme.model.domain.Professional;
import com.hydraulic.applyforme.repository.ProfessionalRepository;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Repository;

import javax.persistence.*;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import javax.persistence.TypedQuery;
import java.util.List;

@Slf4j
@Repository
public class ProfessionalRepositoryImpl implements ProfessionalRepository {

private static final int DEFAULT_PAGE_SIZE = 11;

@PersistenceContext
private EntityManager entityManager;

@Override
public List<Professional> getAll(Integer pageOffset) {
String queryString = "select p from Professional p order by p.member.updatedOn desc";
TypedQuery<Professional> professionalQuery = entityManager.createQuery(queryString, Professional.class);

professionalQuery.setFirstResult((pageOffset - 1) * DEFAULT_PAGE_SIZE);
professionalQuery.setFirstResult((pageOffset-1) * DEFAULT_PAGE_SIZE);
professionalQuery.setMaxResults(DEFAULT_PAGE_SIZE);
return professionalQuery.getResultList();
}

@Override
public Professional getOne(Long id) {
return entityManager.find(Professional.class, id);
}

@Override
public boolean remove(Long id) {
try {
Professional entity = entityManager.getReference(Professional.class, id);
entityManager.remove(entity);
return true;
}
catch (EntityNotFoundException ex) {
return false;
}
}

@Override
public boolean removeMany(List<Long> ids) {
Query query = entityManager.createQuery("delete from Professional p where p.id in (:ids)");
query.setParameter("ids", ids);
if (query.executeUpdate() > 0) {
return true;
}
else {
return false;
}
}

@Override
public boolean removeAll() {
Query query = entityManager.createQuery("delete from Professional");
if (query.executeUpdate() > 0) {
return true;
} else {
return false;
}
public Professional getOne(Long id) {return entityManager.find(Professional.class, id);
}

}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.hydraulic.applyforme.service.impl;

import com.hydraulic.applyforme.model.domain.Professional;
import com.hydraulic.applyforme.model.exception.ProfessionalNotFoundException;
import com.hydraulic.applyforme.repository.ApplyForMeRepository;
import com.hydraulic.applyforme.repository.ProfessionalRepository;
import com.hydraulic.applyforme.service.ProfessionalService;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

Expand All @@ -19,16 +20,9 @@ public ProfessionalServiceImpl(ProfessionalRepository repository) {
}

@Override
public List<Professional> findAll(Integer pageOffset) { return repository.getAll(pageOffset); }
public List<Professional> findAll(Integer pageOffset) { return repository.getAll(pageOffset);}

@Override
public Professional findOne(Long id) {
Professional professional = repository.getOne(id);
if (professional == null) {
throw new ProfessionalNotFoundException(id);
}
professional.setSubmissions(null);
professional.setProfessionalProfiles(null);
return professional;
public Professional findOne(Long id) {return repository.getOne(id);
}

}