From c2c3181d2dc0378b2f84763417d5788f60e7e4ac Mon Sep 17 00:00:00 2001 From: #Lay <82811450+AleeyahAnjola@users.noreply.github.com> Date: Sun, 4 Dec 2022 15:20:47 +0100 Subject: [PATCH 1/2] feat:applicant-view-profile --- .../controller/ApplicantController.java | 27 +++++++++++++++++ .../repository/ApplicantRepository.java | 8 +++++ .../impl/ApplicantRepositoryImpl.java | 30 +++++++++++++++++++ .../applyforme/service/ApplicantService.java | 7 +++++ .../service/impl/ApplicantServiceImpl.java | 21 +++++++++++++ .../service/impl/MemberServiceImpl.java | 1 + 6 files changed, 94 insertions(+) create mode 100644 Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/controller/ApplicantController.java create mode 100644 Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/repository/ApplicantRepository.java create mode 100644 Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/repository/impl/ApplicantRepositoryImpl.java create mode 100644 Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/service/ApplicantService.java create mode 100644 Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/service/impl/ApplicantServiceImpl.java 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 new file mode 100644 index 00000000..7f3c41b6 --- /dev/null +++ b/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/controller/ApplicantController.java @@ -0,0 +1,27 @@ +package com.hydraulic.applyforme.controller; + +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.RestController; + +@RestController +@RequestMapping( + value = "applicant/member", + produces = { MediaType.APPLICATION_JSON_VALUE }) +public class ApplicantController { + private final ApplicantServiceImpl applicantService; + + public ApplicantController(ApplicantServiceImpl applicantService) { + this.applicantService = applicantService; + } + + @GetMapping("/details/{id}") + public Member getMyDetails(@PathVariable(value = "id") Long id){ + return applicantService.getDetails(id); + } +} + 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 new file mode 100644 index 00000000..dced46c2 --- /dev/null +++ b/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/service/ApplicantService.java @@ -0,0 +1,7 @@ +package com.hydraulic.applyforme.service; + +import com.hydraulic.applyforme.model.domain.Member; + +public interface ApplicantService { + Member getDetails(Long id); +} 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 new file mode 100644 index 00000000..c869dcfe --- /dev/null +++ b/Apply-For-Me-Api/src/main/java/com/hydraulic/applyforme/service/impl/ApplicantServiceImpl.java @@ -0,0 +1,21 @@ +package com.hydraulic.applyforme.service.impl; + +import com.hydraulic.applyforme.model.domain.Member; +import com.hydraulic.applyforme.repository.ApplicantRepository; +import com.hydraulic.applyforme.service.ApplicantService; +import org.springframework.stereotype.Service; + +@Service +public class ApplicantServiceImpl implements ApplicantService { + + private final ApplicantRepository repository; + + public ApplicantServiceImpl(ApplicantRepository repository) { + this.repository = repository; + } + + @Override + public Member getDetails(Long id) { + return repository.getMyDetailsById(id); + } +} 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); } + } From 1051302576d5d976c255b14728d79a95f78ed8d8 Mon Sep 17 00:00:00 2001 From: #Lay <82811450+AleeyahAnjola@users.noreply.github.com> Date: Sun, 4 Dec 2022 16:15:44 +0100 Subject: [PATCH 2/2] Made changes to my controller implementation --- .../applyforme/controller/ApplicantController.java | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) 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 6db84f33..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 @@ -2,6 +2,7 @@ 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; @@ -19,9 +20,11 @@ public ApplicantController(ApplicantServiceImpl applicantService) { this.applicantService = applicantService; } - @GetMapping("/details/{id}") - public Member getMyDetails(@PathVariable(value = "id") Long id){ - return applicantService.getDetails(id); + @GetMapping("/details") + public Member getMyDetails(Long id){ + var authenticatedUser = CurrentUserUtil.getCurrentUser(); + assert authenticatedUser != null; + return applicantService.getDetails(authenticatedUser.getId()); } }