Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Finished project. #1

Open
wants to merge 20 commits into
base: master
Choose a base branch
from
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
15 changes: 15 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
# See http://help.github.com/ignore-files/ for more about ignoring files.

API/.idea/
API/API.iml
API/MyBooks.iml
API/target/

client/.idea/
client/dist/
client/client.iml
client/e2e/
client/node_modules/

db/db.iml

5 changes: 5 additions & 0 deletions API/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM maven:3.3.9-jdk-8

WORKDIR /api

EXPOSE 8080
5 changes: 3 additions & 2 deletions API/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,9 @@


<groupId>Library</groupId>
<artifactId>Spring-boot</artifactId>
<version>1.8</version>
<artifactId>BookShop</artifactId>
<version>8</version>

<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<start-class>app.Application</start-class>
Expand Down
8 changes: 2 additions & 6 deletions API/src/main/java/app/config/DataBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public class DataBase {

private String DB_PASSWORD="zabudska1985";

private String DB_URL="jdbc:mysql://127.0.0.1:3306/Library?useSSL=false";
private String DB_URL="jdbc:mysql://db:3306/Library?useSSL=false";

private String DB_USERNAME="root";

Expand Down Expand Up @@ -62,8 +62,4 @@ public HibernateTransactionManager transactionManager() {
return transactionManager;
}

}




}
18 changes: 12 additions & 6 deletions API/src/main/java/app/core/controller/BooksController.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,9 @@ public List<Book> allBooks() {
}

@ResponseBody
@RequestMapping(value = "/", method = RequestMethod.POST)
public void addBook(@RequestBody Book book) {
service.addBook(book);
@RequestMapping(value = "", method = RequestMethod.POST)
public Book addBook(@RequestBody Book book) {
return service.addBook(book);
}

@ResponseBody
Expand All @@ -34,10 +34,16 @@ public void updateBook(@RequestBody Book upBook) {
service.updateBook(upBook);
}

@ResponseBody
@RequestMapping(value = {"/{id}"}, method = RequestMethod.DELETE)
public void deleteBook(@PathVariable("id") Integer id) {

@RequestMapping(value = "/{id}", method = RequestMethod.DELETE)
@ResponseBody void deleteBook(@PathVariable("id") Integer id) {
service.deleteBook(id);
}

@ResponseBody
@RequestMapping(value = "/search/{name}", method = RequestMethod.GET)
public List<Book> searchBook(@PathVariable("name") String name) {
return service.searchBook(name);
}

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package app.core.controller;

import app.core.model.Book;
import app.core.model.Categories;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
Expand All @@ -8,17 +9,17 @@

import app.core.service.CategoriesServiceImpl;


@RestController
@RequestMapping(value = "/api/categories")
public class CategoriesController {

@Autowired
CategoriesServiceImpl service;

@ResponseBody
@RequestMapping(value = "/api/categories", method = RequestMethod.GET)
@RequestMapping(value = "", method = RequestMethod.GET)
public List<Categories> allCategories() {

System.out.println(service.getCategories());
return service.getCategories();
}

Expand Down
3 changes: 2 additions & 1 deletion API/src/main/java/app/core/controller/ShopController.java
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,14 @@
import app.core.service.ShopServiceImpl;

@RestController
@RequestMapping(value = "/api/shops")
public class ShopController {

@Autowired
ShopServiceImpl service;

@ResponseBody
@RequestMapping(value = "/api/shops", method = RequestMethod.GET)
@RequestMapping(value = "", method = RequestMethod.GET)
public List<Shop> allShops() {
return service.getShops();
}
Expand Down
7 changes: 5 additions & 2 deletions API/src/main/java/app/core/dao/BooksDao.java
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
package app.core.dao;

import app.core.model.Book;
import org.hibernate.Criteria;

import java.util.List;

interface BooksDao {

public List<Book> getBooks();
public List getBooks();

public void deleteBook(Integer id);

public void addBook(Book book);
public Book addBook(Book book);

public void updateBook(Book upBook);

public List<Book> searchBook(String name);

public Criteria createCriteria();
}
27 changes: 19 additions & 8 deletions API/src/main/java/app/core/dao/BooksDaoImpl.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
package app.core.dao;

import app.core.model.Book;
import org.hibernate.Criteria;
import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.criterion.Restrictions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

Expand All @@ -15,27 +17,36 @@ public class BooksDaoImpl implements BooksDao {
@Autowired
SessionFactory sessionFactory;

public List<Book> getBooks() {
return sessionFactory.getCurrentSession().createCriteria(Book.class).list();
public Criteria createCriteria(){
return sessionFactory.getCurrentSession().createCriteria(Book.class);
}

public void addBook(Book book) {
public List<Book> getBooks() {return createCriteria().setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
}

public List<Book> searchBook(String name){
String searchName = name + "%";
List<Book> book = (List<Book>) createCriteria()
.add(Restrictions.like("name", searchName)).list();
return book;
}

public Book addBook(Book book) {
sessionFactory.getCurrentSession().save(book);
return book;
}

public void updateBook(Book upBook) {
Book book = (Book) sessionFactory.getCurrentSession().createCriteria(Book.class)
Book book = (Book) createCriteria()
.add(eq("id", upBook.getId())).uniqueResult();
book.setName(upBook.getName());
sessionFactory.getCurrentSession().update(book);
}

public void deleteBook(Integer id) {
System.out.println(id);
Session currentSession = sessionFactory.getCurrentSession();
Book book = (Book) currentSession.createCriteria(Book.class)
Book book = (Book) createCriteria()
.add(eq("id", id)).uniqueResult();
currentSession.delete(book);
sessionFactory.getCurrentSession().delete(book);
}

}
5 changes: 4 additions & 1 deletion API/src/main/java/app/core/dao/CategoriesDaoImpl.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package app.core.dao;

import app.core.model.Categories;
import org.hibernate.Criteria;
import org.hibernate.SessionFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
Expand All @@ -14,6 +15,8 @@ public class CategoriesDaoImpl implements CategoriesDao {
SessionFactory sessionFactory;

public List<Categories> getCategories() {
return sessionFactory.getCurrentSession().createCriteria(Categories.class).list();
return sessionFactory.getCurrentSession()
.createCriteria(Categories.class)
.setResultTransformer(Criteria.DISTINCT_ROOT_ENTITY).list();
}
}
30 changes: 29 additions & 1 deletion API/src/main/java/app/core/model/Book.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,18 @@
package app.core.model;

import com.fasterxml.jackson.annotation.JsonIgnore;
import org.hibernate.annotations.Fetch;
import org.hibernate.annotations.FetchMode;
import org.hibernate.annotations.LazyCollection;
import org.hibernate.annotations.LazyCollectionOption;

import javax.persistence.*;

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


import static javax.persistence.GenerationType.IDENTITY;

@Entity
Expand All @@ -25,12 +34,30 @@ public class Book {
@Column(name = "category")
private Integer category;


@JsonIgnore
@ManyToOne(fetch = FetchType.EAGER)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "category", insertable = false, updatable = false)
private Categories categories;


@ManyToMany(fetch = FetchType.EAGER, cascade = CascadeType.MERGE)
@JoinTable(name = "book_shops", catalog = "Library",
joinColumns = {
@JoinColumn( name = "idBook", referencedColumnName = "id")
},
inverseJoinColumns = {@JoinColumn(name = "idShop", referencedColumnName = "id" )})
private List<Shop> shops = new ArrayList();

public List<Shop> getShops() {
return this.shops;
}

public void setShops(List<Shop> shops) {
this.shops = shops;
}


public Book() {
}

Expand All @@ -44,6 +71,7 @@ public Book(String name, String author, Integer category) {
this.category = category;
}


public Integer getId() {
return this.id;
}
Expand Down
14 changes: 0 additions & 14 deletions API/src/main/java/app/core/model/Categories.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,6 @@ public class Categories {
@Column(name = "name")
public String name;

@JsonIgnore
@OneToMany(fetch = FetchType.LAZY, mappedBy = "categories")
@Cascade({org.hibernate.annotations.CascadeType.DELETE})
public List<Book> categories = new ArrayList();

public Categories() {
}

Expand Down Expand Up @@ -51,13 +46,4 @@ public void setName(String name) {
this.name = name;
}

public List<Book> getCategories() {
return categories;
}

public void setCategories(List<Book> categories) {
this.categories = categories;
}


}
16 changes: 16 additions & 0 deletions API/src/main/java/app/core/model/Shop.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import javax.persistence.*;

import java.awt.print.*;
import java.util.ArrayList;
import java.util.List;

import static javax.persistence.GenerationType.IDENTITY;
Expand All @@ -19,5 +21,19 @@ public class Shop {
@Column(name = "name")
public String name;

public Integer getId() {
return this.id;
}

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

public String getName() {
return this.name;
}

public void setName(String name) {
this.name = name;
}
}
8 changes: 6 additions & 2 deletions API/src/main/java/app/core/service/BookServiceImpl.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,12 @@ public List<Book> getBooks() {
return dao.getBooks();
}

public void addBook(Book book) {
dao.addBook(book);
public List<Book> searchBook(String name) {
return dao.searchBook(name);
}

public Book addBook(Book book) {
return dao.addBook(book);
}

public void updateBook(Book upBook) {
Expand Down
5 changes: 5 additions & 0 deletions API/start.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
#!/usr/bin/env bash

mvn package

java -jar /api/target/BookShop-8.jar
9 changes: 0 additions & 9 deletions client/BooksFront.iml

This file was deleted.

7 changes: 1 addition & 6 deletions client/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,10 +1,5 @@
FROM node:4.4

RUN npm install -g npm

RUN mkdir /client
WORKDIR /client

COPY src ./

EXPOSE 3000:3001
CMD["npm", "run", "api"]
3 changes: 2 additions & 1 deletion client/angular-cli.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,8 @@
"prefix": "app",
"mobile": false,
"styles": [
"styles.css"
"styles.css",
"../node_modules/bootstrap/dist/css/bootstrap.min.css"
],
"scripts": [],
"environments": {
Expand Down
Loading