Skip to content

Commit

Permalink
Entity Issue Fix
Browse files Browse the repository at this point in the history
  • Loading branch information
Sowmya-Raghuram committed Mar 14, 2024
1 parent 13524f8 commit 1145c98
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -56,6 +58,24 @@ public ResponseEntity<Need> 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<Page<Entity>> 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<Entity> 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 = {
Expand Down
Original file line number Diff line number Diff line change
@@ -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<Entity, UUID> {

Page<Entity> findAllByStatus(EntityStatus status, Pageable pageable);
}
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand All @@ -53,6 +56,11 @@ public Page<Need> getAllNeeds(Pageable pageable) {
return needDiscoveryRepository.findAll(pageable);
}

//Fetch all the entities
public Page<Entity> getAllEntity(EntityStatus status,Pageable pageable) {
return entityRepository.findAllByStatus(status, pageable);
}

//Fetch needs based on needId
public Optional<Need> getNeedById(UUID needId) {
return needDiscoveryRepository.findById(needId);
Expand Down

0 comments on commit 1145c98

Please sign in to comment.