From 3f968afac69185c9ac36393cb32419aa46e3941d Mon Sep 17 00:00:00 2001 From: Trisha Anand Date: Tue, 5 Nov 2019 11:36:10 +0000 Subject: [PATCH] Page Controller now can return list of pages by application id and list of page names & ids by application id --- .../server/controllers/PageController.java | 15 +++++++++++++++ .../com/appsmith/server/dtos/PageNameIdDTO.java | 9 +++++++++ .../server/repositories/PageRepository.java | 4 ++++ .../com/appsmith/server/services/PageService.java | 4 ++++ .../appsmith/server/services/PageServiceImpl.java | 7 +++++++ 5 files changed, 39 insertions(+) create mode 100644 app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/PageNameIdDTO.java diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/PageController.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/PageController.java index 166004ae07..bc17782bcb 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/PageController.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/controllers/PageController.java @@ -2,11 +2,20 @@ package com.appsmith.server.controllers; import com.appsmith.server.constants.Url; import com.appsmith.server.domains.Page; +import com.appsmith.server.dtos.PageNameIdDTO; +import com.appsmith.server.dtos.ResponseDTO; import com.appsmith.server.services.PageService; import lombok.extern.slf4j.Slf4j; import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.http.HttpStatus; +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; +import reactor.core.publisher.Flux; +import reactor.core.publisher.Mono; + +import java.util.List; @RestController @RequestMapping(Url.PAGE_URL) @@ -18,4 +27,10 @@ public class PageController extends BaseController { super(service); } + @GetMapping("/application/{applicationId}") + public Mono>> getPageNamesByApplicationId(@PathVariable String applicationId) { + return service.findNamesByApplicationId(applicationId) + .collectList() + .map(resources -> new ResponseDTO<>(HttpStatus.OK.value(), resources, null)); + } } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/PageNameIdDTO.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/PageNameIdDTO.java new file mode 100644 index 0000000000..f70b8fd227 --- /dev/null +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/dtos/PageNameIdDTO.java @@ -0,0 +1,9 @@ +package com.appsmith.server.dtos; + +import lombok.Getter; +import lombok.Setter; + +public interface PageNameIdDTO { + public String getId(); + public String getName(); +} diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/PageRepository.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/PageRepository.java index ceddec1f64..fb254bf51d 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/PageRepository.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/repositories/PageRepository.java @@ -1,7 +1,9 @@ package com.appsmith.server.repositories; import com.appsmith.server.domains.Page; +import com.appsmith.server.dtos.PageNameIdDTO; import org.springframework.stereotype.Repository; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; @Repository @@ -11,4 +13,6 @@ public interface PageRepository extends BaseRepository { Mono findByName(String name); Mono deleteAll(); + + Flux findPageNameIdDtoByApplicationId(String applicationId); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PageService.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PageService.java index 6d05eb1e78..b9d309b258 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PageService.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PageService.java @@ -1,6 +1,8 @@ package com.appsmith.server.services; import com.appsmith.server.domains.Page; +import com.appsmith.server.dtos.PageNameIdDTO; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; public interface PageService extends CrudService { @@ -16,4 +18,6 @@ public interface PageService extends CrudService { Mono findByName(String name); Mono deleteAll(); + + Flux findNamesByApplicationId(String applicationId); } diff --git a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PageServiceImpl.java b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PageServiceImpl.java index 1523ea0764..99239d3bf5 100644 --- a/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PageServiceImpl.java +++ b/app/server/appsmith-server/src/main/java/com/appsmith/server/services/PageServiceImpl.java @@ -4,6 +4,7 @@ import com.appsmith.server.constants.FieldName; import com.appsmith.server.domains.Layout; import com.appsmith.server.domains.Page; import com.appsmith.server.domains.User; +import com.appsmith.server.dtos.PageNameIdDTO; import com.appsmith.server.exceptions.AppsmithError; import com.appsmith.server.exceptions.AppsmithException; import com.appsmith.server.repositories.PageRepository; @@ -13,6 +14,7 @@ import org.springframework.beans.factory.annotation.Autowired; import org.springframework.data.mongodb.core.ReactiveMongoTemplate; import org.springframework.data.mongodb.core.convert.MongoConverter; import org.springframework.stereotype.Service; +import reactor.core.publisher.Flux; import reactor.core.publisher.Mono; import reactor.core.scheduler.Scheduler; @@ -114,4 +116,9 @@ public class PageServiceImpl extends BaseService i public Mono deleteAll() { return repository.deleteAll(); } + + @Override + public Flux findNamesByApplicationId(String applicationId) { + return repository.findPageNameIdDtoByApplicationId(applicationId); + } }