-
Notifications
You must be signed in to change notification settings - Fork 4
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
AleeyahAnjola
wants to merge
3
commits into
development
Choose a base branch
from
feat/BE-120-applicant-view-details
base: development
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
40 changes: 17 additions & 23 deletions
40
Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/controller/ApplicantController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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()); | ||
} | ||
} | ||
|
||
|
||
|
8 changes: 8 additions & 0 deletions
8
Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/repository/ApplicantRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
30 changes: 30 additions & 0 deletions
30
...e-Api/src/main/java/com/hydraulic/applyforme/repository/impl/ApplicantRepositoryImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
|
||
} | ||
} |
4 changes: 2 additions & 2 deletions
4
Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/service/ApplicantService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} |
45 changes: 7 additions & 38 deletions
45
...-For-Me-Api/src/main/java/com/hydraulic/applyforme/service/impl/ApplicantServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -122,4 +122,5 @@ public Member update(Long id, UpdateMemberDto body) { | |
|
||
return repository.updateOne(member); | ||
} | ||
|
||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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