Skip to content

Commit

Permalink
Merge pull request #7 from Sunbird-Serve/release-need-2.1.0.1
Browse files Browse the repository at this point in the history
Skill Details GET API
  • Loading branch information
Sowmya-Raghuram authored Oct 23, 2024
2 parents ba99902 + a197bae commit 735b635
Show file tree
Hide file tree
Showing 4 changed files with 96 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -52,4 +57,26 @@ ResponseEntity<NeedRequirement> 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<Page<SkillDetails>> 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> skillDetails;

// Fetch skill details based on needTypeId
skillDetails = needRequirementService.getSkillDetailsByNeedType(needTypeId, pageable);

return ResponseEntity.ok(skillDetails);
}
}
Original file line number Diff line number Diff line change
@@ -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<SkillDetails, UUID> {

Page<SkillDetails> findAllByNeedTypeId(String needTypeId, Pageable pageable );

}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand All @@ -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
Expand All @@ -29,4 +36,14 @@ public Optional<NeedRequirement> getNeedRequirementById(UUID needReqId) {
throw new RuntimeException("Error fetching NeedRequirement", e);
}
}

// Fetch skills based on needTypeId
public Page<SkillDetails> 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);
}
}
}
37 changes: 37 additions & 0 deletions src/main/java/com/sunbird/serve/need/models/Need/SkillDetails.java
Original file line number Diff line number Diff line change
@@ -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;
}

0 comments on commit 735b635

Please sign in to comment.