Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
23 changes: 14 additions & 9 deletions src/main/java/io/khasang/pm/config/AppConfig.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,8 @@
package io.khasang.pm.config;

import io.khasang.pm.dao.CatDao;
import io.khasang.pm.dao.ProjectDao;
import io.khasang.pm.dao.DocumentDao;
import io.khasang.pm.dao.impl.CatDaoImpl;
import io.khasang.pm.dao.impl.ProjectDaoImpl;
import io.khasang.pm.dao.impl.DocumentDaoImpl;
import io.khasang.pm.entity.Cat;
import io.khasang.pm.entity.Project;
import io.khasang.pm.entity.Document;
import io.khasang.pm.dao.*;
import io.khasang.pm.dao.impl.*;
import io.khasang.pm.entity.*;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.EnableAspectJAutoProxy;
Expand All @@ -22,6 +16,11 @@ public CatDao catDao() {
return new CatDaoImpl(Cat.class);
}

@Bean
public UserDao userDao() {
return new UserDaoImpl(User.class);
}

@Bean
public ProjectDao projectDao() {return new ProjectDaoImpl(Project.class);
}
Expand All @@ -31,4 +30,10 @@ public DocumentDao documentDao(){
return new DocumentDaoImpl(Document.class);
}

@Bean
public EmployeeDao employeeDao(){
return new EmployeeDaoImpl(Employee.class);
}


}
5 changes: 5 additions & 0 deletions src/main/java/io/khasang/pm/controller/AppController.java
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,11 @@ public String getUserPage() {
return "user";
}

@RequestMapping("/users")
public String getUsersPage() {
return "users";
}

// localhost:8080/password/admin
@RequestMapping("/password/{password}")
public String getEncryptPassword(@PathVariable("password") String password, Model model) {
Expand Down
2 changes: 1 addition & 1 deletion src/main/java/io/khasang/pm/controller/CatController.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ public List<Cat> getAll(){
public void setCatService(CatService catService) {
this.catService = catService;
}
}
}
38 changes: 38 additions & 0 deletions src/main/java/io/khasang/pm/controller/EmployeeController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.khasang.pm.controller;

import io.khasang.pm.entity.Employee;
import io.khasang.pm.service.EmployeeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/employee")
public class EmployeeController {
private EmployeeService employeeService;

@RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
@ResponseBody
public Employee addEmployee(@RequestBody Employee employee) {
return employeeService.add(employee);
}

@RequestMapping(value = "/get/{id}", method = RequestMethod.GET)
@ResponseBody
public Employee getById(@PathVariable("id") long id) {
return employeeService.getById(id);
}

@RequestMapping(value = "/all", method = RequestMethod.GET)
@ResponseBody
public List<Employee> getAll() {
return employeeService.getAll();
}

@Autowired
public void setEmployeeService(EmployeeService employeeService) {
this.employeeService = employeeService;
}
}
38 changes: 38 additions & 0 deletions src/main/java/io/khasang/pm/controller/UserController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package io.khasang.pm.controller;

import io.khasang.pm.entity.User;
import io.khasang.pm.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Controller
@RequestMapping("/users")
public class UserController {
private UserService userService;

@RequestMapping(value = "/add", method = RequestMethod.POST, produces = "application/json;charset=utf-8")
@ResponseBody
public User addUser(@RequestBody User user) {
return userService.add(user);
}

@RequestMapping(value = "/get/{login}", method = RequestMethod.GET)
@ResponseBody
public User getByLogin(@PathVariable("login") String login) {
return userService.getByLogin(login);
}

@RequestMapping(value = "/all", method = RequestMethod.GET)
@ResponseBody
public List<User> getAll(){
return userService.getAll();
}

@Autowired
public void setUserService(UserService userService) {
this.userService = userService;
}
}
8 changes: 8 additions & 0 deletions src/main/java/io/khasang/pm/dao/BasicDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,14 @@ public interface BasicDao<T> {
*/
T getById(long id);

/**
* getting specify entity by ID
*
* @param login entity's login for receiving
* @return entity by login
*/
T getByLogin(String login);

/**
* getting all entities
*
Expand Down
7 changes: 7 additions & 0 deletions src/main/java/io/khasang/pm/dao/EmployeeDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package io.khasang.pm.dao;

import io.khasang.pm.entity.Cat;
import io.khasang.pm.entity.Employee;

public interface EmployeeDao extends BasicDao<Employee> {
}
8 changes: 8 additions & 0 deletions src/main/java/io/khasang/pm/dao/UserDao.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package io.khasang.pm.dao;

import io.khasang.pm.entity.User;
import org.springframework.context.annotation.Bean;
import org.springframework.stereotype.Service;

public interface UserDao extends BasicDao<User> {
}
5 changes: 5 additions & 0 deletions src/main/java/io/khasang/pm/dao/impl/BasicDaoImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,11 @@ public T getById(long id) {
return getSession().get(entityClass, id);
}

@Override
public T getByLogin(String login) {
return getSession().get(entityClass, login);
}

@Override
public List<T> getAll() {
// select * from table
Expand Down
13 changes: 13 additions & 0 deletions src/main/java/io/khasang/pm/dao/impl/EmployeeDaoImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package io.khasang.pm.dao.impl;

import io.khasang.pm.dao.BasicDao;
import io.khasang.pm.dao.CatDao;
import io.khasang.pm.dao.EmployeeDao;
import io.khasang.pm.entity.Cat;
import io.khasang.pm.entity.Employee;

public class EmployeeDaoImpl extends BasicDaoImpl<Employee> implements EmployeeDao {
public EmployeeDaoImpl(Class<Employee> entityClass) {
super(entityClass);
}
}
10 changes: 10 additions & 0 deletions src/main/java/io/khasang/pm/dao/impl/UserDaoImpl.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package io.khasang.pm.dao.impl;

import io.khasang.pm.dao.UserDao;
import io.khasang.pm.entity.User;

public class UserDaoImpl extends BasicDaoImpl<User> implements UserDao {
public UserDaoImpl(Class<User> entityClass) {
super(entityClass);
}
}
52 changes: 52 additions & 0 deletions src/main/java/io/khasang/pm/entity/Car.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
package io.khasang.pm.entity;

import com.fasterxml.jackson.annotation.JsonIgnore;
import jdk.nashorn.internal.ir.annotations.Ignore;

import javax.persistence.*;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name="cars")
public class Car {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String model;
private LocalDate year;

//@JsonIgnore
@ManyToMany(fetch = FetchType.EAGER, mappedBy = "carList")
private List<Employee> employees = new ArrayList<>();

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getModel() {
return model;
}

public void setModel(String model) {
this.model = model;
}

public LocalDate getYear() {
return year;
}

public void setYear(LocalDate year) {
this.year = year;
}

public void setEmployees(List<Employee> employees) {
this.employees = employees;
}
}
51 changes: 51 additions & 0 deletions src/main/java/io/khasang/pm/entity/Employee.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package io.khasang.pm.entity;

import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;

@Entity
@Table(name = "employees")
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Long id;

private String name;
private String title;

@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.ALL)
private List<Car> carList= new ArrayList<>();

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getTitle() {
return title;
}

public void setTitle(String title) {
this.title = title;
}

public List<Car> getCarList() {
return carList;
}

public void setCarList(List<Car> carList) {
this.carList = carList;
}
}
47 changes: 47 additions & 0 deletions src/main/java/io/khasang/pm/entity/User.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package io.khasang.pm.entity;

import javax.persistence.*;

@Entity
@Table(name = "users")
public class User {
private String name;

@Id
@Column(unique = true, nullable = false)
private String login;
private String password;
private String function;

public String getName() {
return name;
}

public void setName(String name) {
this.name = name;
}

public String getLogin() {
return login;
}

public void setLogin(String login) {
this.login = login;
}

public String getPassword() {
return password;
}

public void setPassword(String password) {
this.password = password;
}

public String getFunction() {
return function;
}

public void setFunction(String function) {
this.function = function;
}
}
30 changes: 30 additions & 0 deletions src/main/java/io/khasang/pm/service/EmployeeService.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package io.khasang.pm.service;

import io.khasang.pm.entity.Employee;

import java.util.List;

public interface EmployeeService {
/**
* required for adding employee to db
*
* @param employee - employee for adding
* @return added employee
*/
Employee add(Employee employee);

/**
* getting specify employee by ID
*
* @param id - employee's id for receiving
* @return employee by id
*/
Employee getById(long id);

/**
* getting all employees
*
* @return all employees from DB
*/
List<Employee> getAll();
}
Loading