diff --git a/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/controller/ApplicantController.java b/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/controller/ApplicantController.java index 0f3e874c..34612eb8 100644 --- a/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/controller/ApplicantController.java +++ b/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/controller/ApplicantController.java @@ -1,38 +1,32 @@ 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 com.hydraulic.applyforme.util.CurrentUserUtil; 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) { - return service.getApplicationList(pageNo, pageSize, sortBy, sortDir); + @GetMapping("/details") + public Member getMyDetails(Long id){ + var authenticatedUser = CurrentUserUtil.getCurrentUser(); + assert authenticatedUser != null; + return applicantService.getDetails(authenticatedUser.getId()); } } + + + diff --git a/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/repository/ApplicantRepository.java b/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/repository/ApplicantRepository.java new file mode 100644 index 00000000..0ebfbec8 --- /dev/null +++ b/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/repository/ApplicantRepository.java @@ -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); +} diff --git a/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/repository/impl/ApplicantRepositoryImpl.java b/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/repository/impl/ApplicantRepositoryImpl.java new file mode 100644 index 00000000..a21f05ac --- /dev/null +++ b/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/repository/impl/ApplicantRepositoryImpl.java @@ -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; + + } +} diff --git a/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/service/ApplicantService.java b/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/service/ApplicantService.java index 2d5a06a8..b2a9b1b4 100644 --- a/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/service/ApplicantService.java +++ b/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/service/ApplicantService.java @@ -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); } diff --git a/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/service/impl/ApplicantServiceImpl.java b/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/service/impl/ApplicantServiceImpl.java index 786203c1..bd2ce85e 100644 --- a/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/service/impl/ApplicantServiceImpl.java +++ b/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/service/impl/ApplicantServiceImpl.java @@ -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 = 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; } } diff --git a/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/service/impl/MemberServiceImpl.java b/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/service/impl/MemberServiceImpl.java index b3aadbc8..519b3048 100644 --- a/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/service/impl/MemberServiceImpl.java +++ b/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/service/impl/MemberServiceImpl.java @@ -122,4 +122,5 @@ public Member update(Long id, UpdateMemberDto body) { return repository.updateOne(member); } + }