diff --git a/src/main/java/com/sunbird/serve/need/SearchAndDiscoveryService/controllers/NeedDiscoveryController.java b/src/main/java/com/sunbird/serve/need/SearchAndDiscoveryService/controllers/NeedDiscoveryController.java index 87391f3..243a9fd 100644 --- a/src/main/java/com/sunbird/serve/need/SearchAndDiscoveryService/controllers/NeedDiscoveryController.java +++ b/src/main/java/com/sunbird/serve/need/SearchAndDiscoveryService/controllers/NeedDiscoveryController.java @@ -6,7 +6,9 @@ import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RestController; import com.sunbird.serve.need.models.Need.Need; +import com.sunbird.serve.need.models.Need.Entity; import com.sunbird.serve.need.models.enums.NeedStatus; +import com.sunbird.serve.need.models.enums.EntityStatus; import com.sunbird.serve.need.models.response.NeedEntityAndRequirement; import java.util.List; @@ -56,6 +58,24 @@ public ResponseEntity getNeedById(@PathVariable String needId) { .orElse(ResponseEntity.notFound().build()); } + //Fetch all entities + @Operation(summary = "Fetch all entities", description = "Fetch all entities") + @ApiResponses(value = { + @ApiResponse(responseCode = "200", description = "Successfully Fetched Entities", content = @Content(mediaType = MediaType.APPLICATION_JSON_VALUE)), + @ApiResponse(responseCode = "400", description = "Bad Input"), + @ApiResponse(responseCode = "500", description = "Server Error")} + ) + @GetMapping("/entity/") + public ResponseEntity> getAllEntity( + @RequestParam(defaultValue = "0") @Parameter(description = "Page number (default: 0)") int page, + @RequestParam(defaultValue = "10") @Parameter(description = "Page size (default: 10)") int size, + @RequestParam EntityStatus status) + { + Pageable pageable = PageRequest.of(page, size); + Page allEntity = needDiscoveryService.getAllEntity(status, pageable); + return ResponseEntity.ok(allEntity); + } + //Fetch all needs based on its status @Operation(summary = "Fetch Needs based on Status", description = "Fetch need details based on its status") @ApiResponses(value = { diff --git a/src/main/java/com/sunbird/serve/need/SearchAndDiscoveryService/repositories/EntitySearchRepository.java b/src/main/java/com/sunbird/serve/need/SearchAndDiscoveryService/repositories/EntitySearchRepository.java new file mode 100644 index 0000000..a585c21 --- /dev/null +++ b/src/main/java/com/sunbird/serve/need/SearchAndDiscoveryService/repositories/EntitySearchRepository.java @@ -0,0 +1,21 @@ +package com.sunbird.serve.need; + +import com.sunbird.serve.need.models.Need.Need; +import com.sunbird.serve.need.models.Need.Entity; +import com.sunbird.serve.need.models.enums.EntityStatus; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import org.springframework.data.jpa.repository.JpaRepository; +import org.springframework.stereotype.Repository; + +import java.util.UUID; +import java.util.List; +import org.springframework.data.domain.Page; +import org.springframework.data.domain.Pageable; +import java.util.Optional; + +@Repository +public interface EntitySearchRepository extends JpaRepository { + + Page findAllByStatus(EntityStatus status, Pageable pageable); +} diff --git a/src/main/java/com/sunbird/serve/need/SearchAndDiscoveryService/repositories/NeedDiscoveryRepository.java b/src/main/java/com/sunbird/serve/need/SearchAndDiscoveryService/repositories/NeedDiscoveryRepository.java index 7ba6a76..ae580aa 100644 --- a/src/main/java/com/sunbird/serve/need/SearchAndDiscoveryService/repositories/NeedDiscoveryRepository.java +++ b/src/main/java/com/sunbird/serve/need/SearchAndDiscoveryService/repositories/NeedDiscoveryRepository.java @@ -1,6 +1,7 @@ package com.sunbird.serve.need; import com.sunbird.serve.need.models.Need.Need; +import com.sunbird.serve.need.models.Need.Entity; import com.sunbird.serve.need.models.enums.NeedStatus; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; diff --git a/src/main/java/com/sunbird/serve/need/SearchAndDiscoveryService/services/NeedDiscoveryService.java b/src/main/java/com/sunbird/serve/need/SearchAndDiscoveryService/services/NeedDiscoveryService.java index b5866ef..5e1c91a 100644 --- a/src/main/java/com/sunbird/serve/need/SearchAndDiscoveryService/services/NeedDiscoveryService.java +++ b/src/main/java/com/sunbird/serve/need/SearchAndDiscoveryService/services/NeedDiscoveryService.java @@ -28,6 +28,7 @@ public class NeedDiscoveryService { private final NeedDiscoveryRepository needDiscoveryRepository; private final NeedRequirementRepository needRequirementRepository; private final EntityRepository entityRepository; + private final EntitySearchRepository entitySearchRepository; private final NeedTypeRepository needTypeRepository; private final OccurrenceRepository occurrenceRepository; private final TimeSlotRepository timeSlotRepository; @@ -37,12 +38,14 @@ public NeedDiscoveryService( NeedDiscoveryRepository needDiscoveryRepository, NeedRequirementRepository needRequirementRepository, EntityRepository entityRepository, + EntitySearchRepository entitySearchRepository, NeedTypeRepository needTypeRepository, OccurrenceRepository occurrenceRepository, TimeSlotRepository timeSlotRepository) { this.needDiscoveryRepository = needDiscoveryRepository; this.needRequirementRepository = needRequirementRepository; this.entityRepository = entityRepository; + this.entitySearchRepository = entitySearchRepository; this.needTypeRepository = needTypeRepository; this.occurrenceRepository = occurrenceRepository; this.timeSlotRepository = timeSlotRepository; @@ -53,6 +56,11 @@ public Page getAllNeeds(Pageable pageable) { return needDiscoveryRepository.findAll(pageable); } + //Fetch all the entities + public Page getAllEntity(EntityStatus status,Pageable pageable) { + return entityRepository.findAllByStatus(status, pageable); + } + //Fetch needs based on needId public Optional getNeedById(UUID needId) { return needDiscoveryRepository.findById(needId);