Add user service
This commit is contained in:
parent
017e4c1643
commit
9ee0199b50
@ -12,7 +12,7 @@ import java.io.File;
|
|||||||
public class DemoApplication implements CommandLineRunner {
|
public class DemoApplication implements CommandLineRunner {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
SpringApplication.run(DemoApplication.class, args);
|
SpringApplication.run(DemoApplication.class, args);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -2,6 +2,7 @@ package com.cubetiqs.demo.rest;
|
|||||||
|
|
||||||
import com.cubetiqs.demo.domain.UserEntity;
|
import com.cubetiqs.demo.domain.UserEntity;
|
||||||
import com.cubetiqs.demo.repository.UserRepository;
|
import com.cubetiqs.demo.repository.UserRepository;
|
||||||
|
import com.cubetiqs.demo.service.UserService;
|
||||||
import org.springframework.beans.factory.annotation.Autowired;
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
import org.springframework.data.domain.Page;
|
import org.springframework.data.domain.Page;
|
||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
@ -9,21 +10,24 @@ import org.springframework.http.HttpStatus;
|
|||||||
import org.springframework.http.ResponseEntity;
|
import org.springframework.http.ResponseEntity;
|
||||||
import org.springframework.web.bind.annotation.*;
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
@RestController
|
@RestController
|
||||||
@RequestMapping(path = {"/users"})
|
@RequestMapping(path = {"/users"})
|
||||||
public class UserController {
|
public class UserController {
|
||||||
private final UserRepository userRepository;
|
private final UserRepository userRepository;
|
||||||
|
private final UserService userService;
|
||||||
|
|
||||||
@Autowired
|
@Autowired
|
||||||
public UserController(UserRepository userRepository) {
|
public UserController(UserRepository userRepository, UserService userService) {
|
||||||
this.userRepository = userRepository;
|
this.userRepository = userRepository;
|
||||||
|
this.userService = userService;
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping
|
@GetMapping
|
||||||
public Page<UserEntity> getAllUsers(Pageable pageable) {
|
public List<UserEntity> getAllUsers(Pageable pageable) {
|
||||||
return userRepository.findAll(pageable);
|
return userService.findAllUsers();
|
||||||
}
|
}
|
||||||
|
|
||||||
@GetMapping("/{id}")
|
@GetMapping("/{id}")
|
||||||
|
11
src/main/java/com/cubetiqs/demo/service/UserService.java
Normal file
11
src/main/java/com/cubetiqs/demo/service/UserService.java
Normal file
@ -0,0 +1,11 @@
|
|||||||
|
package com.cubetiqs.demo.service;
|
||||||
|
|
||||||
|
import com.cubetiqs.demo.domain.UserEntity;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public interface UserService {
|
||||||
|
List<UserEntity> findAllUsers();
|
||||||
|
}
|
23
src/main/java/com/cubetiqs/demo/service/UserServiceImpl.java
Normal file
23
src/main/java/com/cubetiqs/demo/service/UserServiceImpl.java
Normal file
@ -0,0 +1,23 @@
|
|||||||
|
package com.cubetiqs.demo.service;
|
||||||
|
|
||||||
|
import com.cubetiqs.demo.domain.UserEntity;
|
||||||
|
import com.cubetiqs.demo.repository.UserRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserServiceImpl implements UserService {
|
||||||
|
private final UserRepository userRepository;
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
public UserServiceImpl(UserRepository userRepository) {
|
||||||
|
this.userRepository = userRepository;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public List<UserEntity> findAllUsers() {
|
||||||
|
return userRepository.findAll();
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,5 @@
|
|||||||
server:
|
server:
|
||||||
port: 8080
|
port: 8081
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
jpa:
|
jpa:
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
server:
|
server:
|
||||||
port: 8080
|
port: 8081
|
||||||
|
|
||||||
spring:
|
spring:
|
||||||
jpa:
|
jpa:
|
||||||
|
Loading…
Reference in New Issue
Block a user