Just updated for demo

This commit is contained in:
Sambo Chea 2020-06-17 20:22:26 +07:00
parent 50d6479c8d
commit 0121fd4bcb
3 changed files with 22 additions and 5 deletions

View File

@ -1,15 +1,14 @@
package com.cubetiqs.demo.rest;
import com.cubetiqs.demo.domain.PostEntity;
import com.cubetiqs.demo.service.PostService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Pageable;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import java.util.List;
@RestController
@RequestMapping(path = {"/posts"})
public class PostController {
@ -21,7 +20,14 @@ public class PostController {
}
@GetMapping
public List<PostEntity> getAllPosts(Pageable pageable) {
return postService.findAll();
public ResponseEntity<Object> getAllPosts(
Pageable pageable,
@RequestParam(value = "view", defaultValue = "list") String viewType,
@RequestParam(value = "q", defaultValue = "") String q
) {
if ("list".equalsIgnoreCase(viewType)) {
return ResponseEntity.ok(postService.findAll());
}
return ResponseEntity.ok(postService.findAll(pageable));
}
}

View File

@ -1,6 +1,8 @@
package com.cubetiqs.demo.service;
import com.cubetiqs.demo.repository.BaseRepository;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.NoRepositoryBean;
import java.io.Serializable;
@ -9,5 +11,7 @@ import java.util.List;
@NoRepositoryBean
public interface BaseService<T, ID extends Serializable> {
BaseRepository<T, ID> getRepository();
Page<T> findAll(Pageable pageable, String q);
Page<T> findAll(Pageable pageable);
List<T> findAll();
}

View File

@ -1,5 +1,7 @@
package com.cubetiqs.demo.service;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.repository.NoRepositoryBean;
import java.io.Serializable;
@ -11,4 +13,9 @@ public abstract class BaseServiceImpl<T, ID extends Serializable> implements Bas
public List<T> findAll() {
return getRepository().findAll();
}
@Override
public Page<T> findAll(Pageable pageable) {
return getRepository().findAll(pageable);
}
}