Compare commits
No commits in common. "master" and "day7" have entirely different histories.
|
@ -5,9 +5,6 @@ build/
|
|||
!**/src/main/**
|
||||
!**/src/test/**
|
||||
|
||||
application-mysql.yml
|
||||
application-postgres.yml
|
||||
|
||||
### STS ###
|
||||
.apt_generated
|
||||
.classpath
|
||||
|
|
|
@ -13,8 +13,6 @@ repositories {
|
|||
}
|
||||
|
||||
dependencies {
|
||||
implementation 'org.springframework.boot:spring-boot-starter-thymeleaf'
|
||||
|
||||
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
|
||||
implementation 'org.springframework.boot:spring-boot-starter-web'
|
||||
implementation 'io.springfox:springfox-swagger2:2.9.2'
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package com.cubetiqs.demo.domain.view;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonPropertyOrder;
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
|
||||
import java.io.Serializable;
|
||||
|
||||
@Data
|
||||
@NoArgsConstructor
|
||||
@AllArgsConstructor
|
||||
@JsonPropertyOrder(value = {
|
||||
"email",
|
||||
"id"
|
||||
})
|
||||
public class UserView implements Serializable {
|
||||
private Long id;
|
||||
private String email;
|
||||
}
|
|
@ -1,23 +1,9 @@
|
|||
package com.cubetiqs.demo.repository;
|
||||
|
||||
import com.cubetiqs.demo.domain.UserEntity;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.data.jpa.repository.Query;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Repository
|
||||
public interface UserRepository extends BaseRepository<UserEntity, Long> {
|
||||
Optional<UserEntity> findFirstByEmail(String email);
|
||||
|
||||
@Query(value = "select * from users u where u.email = ?1", nativeQuery = true)
|
||||
Optional<UserEntity> fetchFirstByEmail(String email);
|
||||
|
||||
@Query(value = "select * from users u", nativeQuery = true)
|
||||
Page<UserEntity> fetchAllUsers(Pageable pageable);
|
||||
|
||||
@Query(value = "select * from users u where lower(u.email) like ?1", nativeQuery = true)
|
||||
Page<UserEntity> searchByEmail(String likeEmail, Pageable pageable);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
package com.cubetiqs.demo.rest;
|
||||
|
||||
import com.cubetiqs.demo.domain.UserEntity;
|
||||
import com.cubetiqs.demo.domain.view.UserView;
|
||||
import com.cubetiqs.demo.repository.UserRepository;
|
||||
import com.cubetiqs.demo.service.UserNotFoundException;
|
||||
import com.cubetiqs.demo.service.UserService;
|
||||
import com.cubetiqs.demo.util.StringUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.http.HttpStatus;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
|
@ -16,7 +12,6 @@ import org.springframework.web.bind.annotation.*;
|
|||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
@RestController
|
||||
@RequestMapping(path = {"/users"})
|
||||
public class UserController {
|
||||
|
@ -34,30 +29,6 @@ public class UserController {
|
|||
return userService.findAllActives();
|
||||
}
|
||||
|
||||
@GetMapping("/searchByEmail")
|
||||
public Page<UserView> searchByEmail(
|
||||
Pageable pageable,
|
||||
@RequestParam(value = "q", defaultValue = "") String q
|
||||
) {
|
||||
return userService.searchByEmailAsView(StringUtils.stringQuery(q), pageable);
|
||||
}
|
||||
|
||||
@GetMapping("/allUsers")
|
||||
public Page<UserEntity> fetchAllUsers(Pageable pageable) {
|
||||
return userRepository.fetchAllUsers(Pageable.unpaged());
|
||||
}
|
||||
|
||||
@GetMapping("/findByEmail/{email}")
|
||||
public ResponseEntity<Object> getUserById(
|
||||
@PathVariable String email
|
||||
) {
|
||||
try {
|
||||
return ResponseEntity.ok(userService.findByEmail(email));
|
||||
} catch (UserNotFoundException ex) {
|
||||
return ResponseEntity.status(HttpStatus.NOT_FOUND).body(ex.getMessage());
|
||||
}
|
||||
}
|
||||
|
||||
@GetMapping("/{id}")
|
||||
public UserEntity getUserById(
|
||||
@PathVariable Long id
|
||||
|
|
|
@ -1,7 +0,0 @@
|
|||
package com.cubetiqs.demo.service;
|
||||
|
||||
public class UserNotFoundException extends Exception {
|
||||
public UserNotFoundException(String message) {
|
||||
super(message);
|
||||
}
|
||||
}
|
|
@ -1,14 +1,9 @@
|
|||
package com.cubetiqs.demo.service;
|
||||
|
||||
import com.cubetiqs.demo.domain.UserEntity;
|
||||
import com.cubetiqs.demo.domain.view.UserView;
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
@Service
|
||||
public interface UserService extends BaseService<UserEntity, Long> {
|
||||
UserEntity findByEmail(String email) throws UserNotFoundException;
|
||||
Page<UserEntity> searchByEmail(String email, Pageable pageable);
|
||||
Page<UserView> searchByEmailAsView(String email, Pageable pageable);
|
||||
|
||||
}
|
||||
|
|
|
@ -1,7 +1,6 @@
|
|||
package com.cubetiqs.demo.service;
|
||||
|
||||
import com.cubetiqs.demo.domain.UserEntity;
|
||||
import com.cubetiqs.demo.domain.view.UserView;
|
||||
import com.cubetiqs.demo.repository.BaseRepository;
|
||||
import com.cubetiqs.demo.repository.UserRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
@ -10,7 +9,6 @@ import org.springframework.data.domain.Pageable;
|
|||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
public class UserServiceImpl extends BaseServiceImpl<UserEntity, Long> implements UserService {
|
||||
|
@ -35,25 +33,4 @@ public class UserServiceImpl extends BaseServiceImpl<UserEntity, Long> implement
|
|||
public List<UserEntity> findAllActives() {
|
||||
return userRepository.findAllActives();
|
||||
}
|
||||
|
||||
@Override
|
||||
public UserEntity findByEmail(String email) throws UserNotFoundException {
|
||||
Optional<UserEntity> opt = userRepository.fetchFirstByEmail(email);
|
||||
if (opt.isPresent()) {
|
||||
return opt.get();
|
||||
}
|
||||
|
||||
throw new UserNotFoundException("user does not exists");
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<UserEntity> searchByEmail(String email, Pageable pageable) {
|
||||
return userRepository.searchByEmail(email, pageable);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Page<UserView> searchByEmailAsView(String email, Pageable pageable) {
|
||||
Page<UserEntity> users = userRepository.searchByEmail(email, pageable);
|
||||
return users.map(s -> new UserView(s.getId(), s.getEmail()));
|
||||
}
|
||||
}
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
package com.cubetiqs.demo.ui;
|
||||
|
||||
import org.springframework.stereotype.Controller;
|
||||
import org.springframework.ui.Model;
|
||||
import org.springframework.web.bind.annotation.GetMapping;
|
||||
|
||||
@Controller
|
||||
public class HomeController {
|
||||
@GetMapping(value = {"/index", "", "/", "/index.php"})
|
||||
public String index(Model model) {
|
||||
model.addAttribute("myname", "Sambo");
|
||||
return "index";
|
||||
}
|
||||
|
||||
@GetMapping(value = {"/admin/users"})
|
||||
public String user(Model model) {
|
||||
model.addAttribute("myname", "Sambo");
|
||||
return "admin/users/index";
|
||||
}
|
||||
}
|
|
@ -1,8 +0,0 @@
|
|||
package com.cubetiqs.demo.util;
|
||||
|
||||
public final class StringUtils {
|
||||
public static String stringQuery(String q) {
|
||||
return "%" + q.toLowerCase() + "%";
|
||||
}
|
||||
}
|
||||
|
|
@ -7,6 +7,6 @@ spring:
|
|||
ddl-auto: update
|
||||
datasource:
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
username: root
|
||||
password: root
|
||||
username: cubetiq
|
||||
password: Root$
|
||||
url: jdbc:mysql://192.168.0.150:3306/demo
|
|
@ -7,6 +7,6 @@ spring:
|
|||
ddl-auto: update
|
||||
datasource:
|
||||
driver-class-name: org.postgresql.Driver
|
||||
username: root
|
||||
password: root
|
||||
username: cubetiq
|
||||
password: Root$
|
||||
url: jdbc:postgresql://${POSTGRES_HOST:192.168.0.150}:5432/demo
|
|
@ -1 +0,0 @@
|
|||
console.log("hello")
|
|
@ -1,13 +0,0 @@
|
|||
<!doctype html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Document</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>Users</h1>
|
||||
</body>
|
||||
</html>
|
|
@ -1,13 +0,0 @@
|
|||
<!doctype html>
|
||||
<html lang="en" xmlns:th="http://www.thymeleaf.org">
|
||||
<head>
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport"
|
||||
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
|
||||
<meta http-equiv="X-UA-Compatible" content="ie=edge">
|
||||
<title>Index</title>
|
||||
</head>
|
||||
<body>
|
||||
<h1 th:text="${myname}"></h1>
|
||||
</body>
|
||||
</html>
|
Loading…
Reference in New Issue
Block a user