Page Controller now can return list of pages by application id and list of page names & ids by application id

This commit is contained in:
Trisha Anand 2019-11-05 11:36:10 +00:00 committed by Arpit Mohan
parent f493d8c3ae
commit 3f968afac6
5 changed files with 39 additions and 0 deletions

View File

@ -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<PageService, Page, String> {
super(service);
}
@GetMapping("/application/{applicationId}")
public Mono<ResponseDTO<List<PageNameIdDTO>>> getPageNamesByApplicationId(@PathVariable String applicationId) {
return service.findNamesByApplicationId(applicationId)
.collectList()
.map(resources -> new ResponseDTO<>(HttpStatus.OK.value(), resources, null));
}
}

View File

@ -0,0 +1,9 @@
package com.appsmith.server.dtos;
import lombok.Getter;
import lombok.Setter;
public interface PageNameIdDTO {
public String getId();
public String getName();
}

View File

@ -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<Page, String> {
Mono<Page> findByName(String name);
Mono<Void> deleteAll();
Flux<PageNameIdDTO> findPageNameIdDtoByApplicationId(String applicationId);
}

View File

@ -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<Page, String> {
@ -16,4 +18,6 @@ public interface PageService extends CrudService<Page, String> {
Mono<Page> findByName(String name);
Mono<Void> deleteAll();
Flux<PageNameIdDTO> findNamesByApplicationId(String applicationId);
}

View File

@ -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<PageRepository, Page, String> i
public Mono<Void> deleteAll() {
return repository.deleteAll();
}
@Override
public Flux<PageNameIdDTO> findNamesByApplicationId(String applicationId) {
return repository.findPageNameIdDtoByApplicationId(applicationId);
}
}