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 120 applicant view details #284

Open
wants to merge 3 commits into
base: development
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 2 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
@@ -1,38 +1,29 @@
package com.hydraulic.applyforme.controller;

import com.hydraulic.applyforme.model.response.base.ApplyForMeResponse;
import com.hydraulic.applyforme.service.ApplicantService;
import org.springframework.beans.factory.annotation.Autowired;
import com.hydraulic.applyforme.model.domain.Member;
import com.hydraulic.applyforme.service.impl.ApplicantServiceImpl;
import org.springframework.http.MediaType;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import static com.hydraulic.applyforme.constants.PagingConstants.*;
import static com.hydraulic.applyforme.constants.PagingConstants.DEFAULT_SORT_DIRECTION;

@RestController
@RequestMapping(
value = "applicant",
produces = { MediaType.APPLICATION_JSON_VALUE }
)
value = "applicant/member",
produces = { MediaType.APPLICATION_JSON_VALUE })
public class ApplicantController {
private final ApplicantServiceImpl applicantService;

private final ApplicantService service;

@Autowired
public ApplicantController(ApplicantService service) {
this.service = service;
public ApplicantController(ApplicantServiceImpl applicantService) {
this.applicantService = applicantService;
}


@GetMapping("/entries")
public ApplyForMeResponse getAllSubmission(
@RequestParam(value = "pageNo", defaultValue = DEFAULT_PAGE_NUMBER, required = false) int pageNo,
@RequestParam(value = "pageSize", defaultValue = DEFAULT_PAGE_SIZE, required = false) int pageSize,
@RequestParam(value = "sortBy", defaultValue = DEFAULT_SORT_BY, required = false) String sortBy,
@RequestParam(value = "sortDir", defaultValue = DEFAULT_SORT_DIRECTION, required = false) String sortDir) {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove the id in the url, we do not need to specify the id of an existing user, instead we fetch the user from the security context. so use the security context to get the id of the user and pass that into the service method

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've implemented that and it works

return service.getApplicationList(pageNo, pageSize, sortBy, sortDir);
@GetMapping("/details/{id}")
public Member getMyDetails(@PathVariable(value = "id") Long id){
return applicantService.getDetails(id);
}
}



Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.hydraulic.applyforme.repository;

import com.hydraulic.applyforme.model.domain.Member;
import org.springframework.data.jpa.repository.Query;

public interface ApplicantRepository{
Member getMyDetailsById(Long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.hydraulic.applyforme.repository.impl;

import com.hydraulic.applyforme.model.domain.Member;
import com.hydraulic.applyforme.model.exception.ApplyForMeDuplicateEntityException;
import com.hydraulic.applyforme.model.exception.MemberNotFoundException;
import com.hydraulic.applyforme.repository.ApplicantRepository;
import org.springframework.stereotype.Repository;

import javax.persistence.EntityExistsException;
import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;

@Repository
public class ApplicantRepositoryImpl implements ApplicantRepository {

private static final int DEFAULT_PAGE_SIZE = 11;
@PersistenceContext
private EntityManager entityManager;

@Override
public Member getMyDetailsById(Long id) {
Member member = entityManager.find(Member.class, id);

if (member == null){
throw new MemberNotFoundException(id);
}
return member;

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

import com.hydraulic.applyforme.model.response.base.ApplyForMeResponse;
import com.hydraulic.applyforme.model.domain.Member;

public interface ApplicantService {
Member getDetails(Long id);

ApplyForMeResponse getApplicationList(int pageNo, int pageSize, String sortBy, String sortDir);
}
Original file line number Diff line number Diff line change
@@ -1,53 +1,22 @@
package com.hydraulic.applyforme.service.impl;

import com.hydraulic.applyforme.model.dto.applicant.ApplicantResponse;
import com.hydraulic.applyforme.model.response.base.ApplyForMeResponse;
import com.hydraulic.applyforme.repository.jpa.JobSubmissionRepository;
import com.hydraulic.applyforme.model.domain.Member;
import com.hydraulic.applyforme.repository.ApplicantRepository;
import com.hydraulic.applyforme.service.ApplicantService;
import com.hydraulic.applyforme.util.ApplyForMeUtil;
import org.modelmapper.ModelMapper;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;

import java.util.Collection;
import java.util.stream.Collectors;

@Service
public class ApplicantServiceImpl implements ApplicantService {

private final ApplicantRepository repository;

private final JobSubmissionRepository jobSubmissionRepository;

private final ModelMapper modelMapper;

public ApplicantServiceImpl(JobSubmissionRepository jobSubmissionRepository, ModelMapper modelMapper) {
this.jobSubmissionRepository = jobSubmissionRepository;
this.modelMapper = modelMapper;
public ApplicantServiceImpl(ApplicantRepository repository) {
this.repository = repository;
}


@Override
public ApplyForMeResponse getApplicationList(int pageNo, int pageSize, String sortBy, String sortDir) {
Pageable pageable = ApplyForMeUtil.createPageable(pageNo, pageSize, sortBy, sortDir);
var result = jobSubmissionRepository.findAll(pageable);
public Member getDetails(Long id) {
return repository.getMyDetailsById(id);

Collection<ApplicantResponse> applicantResponse = result.getContent().stream().map(x -> ApplicantResponse.builder()
.id(x.getId())
.date(x.getCreatedOn())
.jobLocation(x.getJobLocation())
.jobTitle(x.getJobTitle())
.jobType(x.getJobLocationType().getValue())
.jobCompany(x.getJobCompany())
.salaryRange("I don't know where to find it, I can't even do a join table")
.build()
).collect(Collectors.toList());
ApplyForMeResponse applyForMeResponse = new ApplyForMeResponse();
applyForMeResponse.setContent(applicantResponse);
applyForMeResponse.setPageSize(result.getSize());
applyForMeResponse.setTotalElements(result.getTotalElements());
applyForMeResponse.setPageNo(result.getNumber());
applyForMeResponse.setTotalPages(result.getTotalPages());
applyForMeResponse.setLast(result.isLast());
return applyForMeResponse;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,4 +122,5 @@ public Member update(Long id, UpdateMemberDto body) {

return repository.updateOne(member);
}

}