From a197bae0b5385e54d36437c5cc53051352fea3c0 Mon Sep 17 00:00:00 2001 From: Sowmya-Raghuram Date: Wed, 23 Oct 2024 16:51:41 +0530 Subject: [PATCH] Skill Details GET API --- .../NeedRequirementController.java | 27 ++++++++++++++ .../repositories/SkillDetailsRepository.java | 14 +++++++ .../services/NeedRequirementService.java | 19 +++++++++- .../serve/need/models/Need/SkillDetails.java | 37 +++++++++++++++++++ 4 files changed, 96 insertions(+), 1 deletion(-) create mode 100644 src/main/java/com/sunbird/serve/need/NeedService/repositories/SkillDetailsRepository.java create mode 100644 src/main/java/com/sunbird/serve/need/models/Need/SkillDetails.java diff --git a/src/main/java/com/sunbird/serve/need/NeedService/controllers/NeedRequirementController.java b/src/main/java/com/sunbird/serve/need/NeedService/controllers/NeedRequirementController.java index d0b6120..c165575 100644 --- a/src/main/java/com/sunbird/serve/need/NeedService/controllers/NeedRequirementController.java +++ b/src/main/java/com/sunbird/serve/need/NeedService/controllers/NeedRequirementController.java @@ -1,12 +1,17 @@ package com.sunbird.serve.need; import com.sunbird.serve.need.models.Need.NeedRequirement; +import com.sunbird.serve.need.models.Need.SkillDetails; import lombok.RequiredArgsConstructor; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.CrossOrigin; import org.springframework.web.bind.annotation.RestController; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; + import org.springframework.beans.factory.annotation.Autowired; import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; @@ -52,4 +57,26 @@ ResponseEntity getNeedRequirementById( return needRequirement.map(ResponseEntity::ok) .orElse(ResponseEntity.notFound().build()); } + + + @Operation(summary = "Get list of Skills based on Need Type", description = "Get list of Skills based on Need Type") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Successfully fetched Skill Details", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)), + @ApiResponse(responseCode = "400", description = "Bad Input"), + @ApiResponse(responseCode = "500", description = "Server Error")} + ) + @GetMapping("/skilldetails/{needTypeId}") + public ResponseEntity> getSkillDetailsByNeedType( + @PathVariable(required = true) @Parameter(description = "Need Type ID") String needTypeId, + @RequestParam(required = false, defaultValue = "0") Integer page, + @RequestParam(required = false, defaultValue = "10") Integer size) { + + Pageable pageable = PageRequest.of(page, size); + Page skillDetails; + + // Fetch skill details based on needTypeId + skillDetails = needRequirementService.getSkillDetailsByNeedType(needTypeId, pageable); + + return ResponseEntity.ok(skillDetails); +} } diff --git a/src/main/java/com/sunbird/serve/need/NeedService/repositories/SkillDetailsRepository.java b/src/main/java/com/sunbird/serve/need/NeedService/repositories/SkillDetailsRepository.java new file mode 100644 index 0000000..e3a2bd4 --- /dev/null +++ b/src/main/java/com/sunbird/serve/need/NeedService/repositories/SkillDetailsRepository.java @@ -0,0 +1,14 @@ +package com.sunbird.serve.need; + +import com.sunbird.serve.need.models.Need.SkillDetails; +import org.springframework.data.jpa.repository.JpaRepository; +import java.util.UUID; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; + +public interface SkillDetailsRepository extends JpaRepository { + + Page findAllByNeedTypeId(String needTypeId, Pageable pageable ); + +} diff --git a/src/main/java/com/sunbird/serve/need/NeedService/services/NeedRequirementService.java b/src/main/java/com/sunbird/serve/need/NeedService/services/NeedRequirementService.java index 541a1d3..7a19321 100644 --- a/src/main/java/com/sunbird/serve/need/NeedService/services/NeedRequirementService.java +++ b/src/main/java/com/sunbird/serve/need/NeedService/services/NeedRequirementService.java @@ -3,6 +3,10 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; import com.sunbird.serve.need.models.Need.NeedRequirement; +import com.sunbird.serve.need.models.Need.SkillDetails; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.PageRequest; +import org.springframework.data.domain.Pageable; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -14,10 +18,13 @@ public class NeedRequirementService { private static final Logger logger = LoggerFactory.getLogger(NeedRequirementService.class); private final NeedRequirementRepository needRequirementRepository; + private final SkillDetailsRepository skillDetailsRepository; @Autowired - public NeedRequirementService(NeedRequirementRepository needRequirementRepository) { + public NeedRequirementService(NeedRequirementRepository needRequirementRepository, + SkillDetailsRepository skillDetailsRepository) { this.needRequirementRepository = needRequirementRepository; + this.skillDetailsRepository = skillDetailsRepository; } // Fetch needs based on needRequirementId @@ -29,4 +36,14 @@ public Optional getNeedRequirementById(UUID needReqId) { throw new RuntimeException("Error fetching NeedRequirement", e); } } + + // Fetch skills based on needTypeId + public Page getSkillDetailsByNeedType(String needTypeId, Pageable pageable) { + try { + return skillDetailsRepository.findAllByNeedTypeId(needTypeId, pageable); + } catch (Exception e) { + logger.error("Error fetching Skills by NeedTypeId: {}", needTypeId, e); + throw new RuntimeException("Error fetching Skills by NeedTypeId", e); + } + } } diff --git a/src/main/java/com/sunbird/serve/need/models/Need/SkillDetails.java b/src/main/java/com/sunbird/serve/need/models/Need/SkillDetails.java new file mode 100644 index 0000000..fa129cf --- /dev/null +++ b/src/main/java/com/sunbird/serve/need/models/Need/SkillDetails.java @@ -0,0 +1,37 @@ +package com.sunbird.serve.need.models.Need; + +import jakarta.persistence.Entity; +import jakarta.persistence.GeneratedValue; +import jakarta.persistence.GenerationType; +import jakarta.persistence.Id; +import lombok.AllArgsConstructor; +import lombok.Builder; +import lombok.Data; +import lombok.NoArgsConstructor; +import org.hibernate.annotations.CreationTimestamp; +import org.hibernate.annotations.UpdateTimestamp; + +import java.time.Instant; +import java.util.UUID; + +@Builder +@Data +@NoArgsConstructor +@AllArgsConstructor +@Entity +public class SkillDetails { + + @Id + @GeneratedValue(strategy = GenerationType.UUID) + private UUID id; + + private String needTypeId; + private String skillName; + private String skillLevel; + + @CreationTimestamp + private Instant createdAt; + + @UpdateTimestamp + private Instant updatedAt; +}