pierwszy comit

This commit is contained in:
s444461 2020-01-27 12:20:42 +01:00
commit eb67f3cc7a
39 changed files with 2045 additions and 0 deletions

255
pom.xml Normal file
View File

@ -0,0 +1,255 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.pracownia.spring</groupId>
<artifactId>spring</artifactId>
<version>1.0-SNAPSHOT</version>
<packaging>war</packaging>
<name>Spring Boot Web Application</name>
<description>Spring Boot Web Application</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.22.RELEASE</version>
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>2.4.4</version>
</dependency>
<dependency>
<groupId>org.hsqldb</groupId>
<artifactId>hsqldb</artifactId>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger2</artifactId>
<version>2.6.1</version>
</dependency>
<dependency>
<groupId>io.springfox</groupId>
<artifactId>springfox-swagger-ui</artifactId>
<version>2.6.1</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-jsr310</artifactId>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.9.0</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.datatype</groupId>
<artifactId>jackson-datatype-joda</artifactId>
<version>2.9.5</version>
</dependency>
<dependency>
<groupId>joda-time</groupId>
<artifactId>joda-time</artifactId>
<version>2.10.5</version>
</dependency>
<dependency>
<groupId>com.fasterxml.jackson.dataformat</groupId>
<artifactId>jackson-dataformat-xml</artifactId>
<version>2.9.8</version>
</dependency>
<!-- Hibernate resources -->
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-entitymanager</artifactId>
<version>5.2.1.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-core</artifactId>
<version>5.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate</groupId>
<artifactId>hibernate-validator</artifactId>
<version>5.2.0.Final</version>
</dependency>
<dependency>
<groupId>org.hibernate.common</groupId>
<artifactId>hibernate-commons-annotations</artifactId>
<version>4.0.2.Final</version>
<classifier>tests</classifier>
</dependency>
<dependency>
<groupId>org.hibernate.javax.persistence</groupId>
<artifactId>hibernate-jpa-2.0-api</artifactId>
<version>1.0.1.Final</version>
</dependency>
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<!-- Database driver-->
<dependency>
<groupId>org.postgresql</groupId>
<artifactId>postgresql</artifactId>
<version>42.1.1</version>
</dependency>
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- Java Bind -->
<dependency>
<groupId>com.sun.xml.bind</groupId>
<artifactId>jaxb-impl</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.xml.bind</groupId>
<artifactId>jaxb-api</artifactId>
<version>2.2.4</version>
</dependency>
<!-- required for JDK9 -->
<dependency>
<groupId>javax.xml.ws</groupId>
<artifactId>jaxws-api</artifactId>
<version>2.3.0</version>
</dependency>
<dependency>
<groupId>javax.activation</groupId>
<artifactId>activation</artifactId>
<version>1.1.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
<configuration>
<testFailureIgnore>true</testFailureIgnore>
</configuration>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<version>2.19.1</version>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-assembly-plugin</artifactId>
<version>2.4.1</version>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>2.4.4</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-jar-plugin</artifactId>
<version>3.0.0</version>
<dependencies>
<dependency>
<groupId>org.codehaus.plexus</groupId>
<artifactId>plexus-archiver</artifactId>
<version>2.4.4</version>
</dependency>
</dependencies>
</plugin>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-war-plugin</artifactId>
<version>3.2.2</version>
</plugin>
</plugins>
</build>
<!-- Add Spring repositories -->
<!-- (you don't need this if you are using a .RELEASE version) -->
<repositories>
<repository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
<snapshots><enabled>true</enabled></snapshots>
</repository>
<repository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</repository>
</repositories>
<pluginRepositories>
<pluginRepository>
<id>spring-snapshots</id>
<url>http://repo.spring.io/snapshot</url>
</pluginRepository>
<pluginRepository>
<id>spring-milestones</id>
<url>http://repo.spring.io/milestone</url>
</pluginRepository>
</pluginRepositories>
</project>

View File

@ -0,0 +1,51 @@
package com.pracownia.spring;
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.fasterxml.jackson.databind.SerializationFeature;
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.boot.web.support.SpringBootServletInitializer;
import org.springframework.context.annotation.Bean;
import org.springframework.data.jpa.repository.config.EnableJpaRepositories;
import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;
@SpringBootApplication
@EnableJpaRepositories("com.pracownia.spring.repositories")
@EnableSwagger2
public class SpringBootWebApplication extends SpringBootServletInitializer {
@Override
protected SpringApplicationBuilder configure(SpringApplicationBuilder application) {
return application.sources(SpringBootWebApplication.class);
}
@Bean
public MappingJackson2HttpMessageConverter mappingJackson2HttpMessageConverter() {
MappingJackson2HttpMessageConverter jsonConverter = new MappingJackson2HttpMessageConverter();
ObjectMapper objectMapper = new ObjectMapper();
objectMapper.registerModule(new JavaTimeModule());
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
jsonConverter.setObjectMapper(objectMapper);
return jsonConverter;
}
@Bean
public Docket productApi() {
return new Docket(DocumentationType.SWAGGER_2)
.select().apis(RequestHandlerSelectors.basePackage("com.pracownia.spring.controllers"))
.build();
}
public static void main(String[] args) {
SpringApplication.run(SpringBootWebApplication.class, args);
}
}

View File

@ -0,0 +1,90 @@
package com.pracownia.spring.controllers;
import com.pracownia.spring.entities.Product;
import com.pracownia.spring.entities.Seller;
import com.pracownia.spring.services.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;
import java.math.BigDecimal;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZonedDateTime;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.UUID;
/**
* Homepage controller.
*/
@RestController
@RequestMapping("/")
public class IndexController {
@Autowired
private ProductService productService;
@Autowired
private SellerService sellerService;
@Autowired
private parentService parentService;
@Autowired
private com.pracownia.spring.services.schoolSubjectService schoolSubjectService;
@Autowired
private schoolRoomService schoolRoomService;
@Autowired
private studentService studentService;
@Autowired
private teacherService teacherService;
@RequestMapping(value = "", method = RequestMethod.GET)
String index() {
return "index";
}
@RequestMapping(value = "generateModel", method = RequestMethod.POST, produces = MediaType.TEXT_PLAIN_VALUE)
public String generateModel() {
LocalDateTime localtDateAndTime = LocalDateTime.now();
ZoneId zoneId = ZoneId.systemDefault();
ZonedDateTime dateAndTime = ZonedDateTime.of(localtDateAndTime, zoneId);
Product p1 = new Product(UUID.randomUUID().toString(),"Jajko", new BigDecimal(2.50), dateAndTime.plusDays(7));
Product p2 = new Product(UUID.randomUUID().toString(),"Masło", new BigDecimal(3.50), dateAndTime.plusDays(7));
Product p3 = new Product(UUID.randomUUID().toString(),"Mąka", new BigDecimal(1.50), dateAndTime.plusDays(7));
productService.saveProduct(p1);
productService.saveProduct(p2);
productService.saveProduct(p3);
Seller seller = new Seller("Biedra", "Poznan", Arrays.asList(p1.getProductId(), p2.getProductId(), p3.getProductId()));
Seller seller2 = new Seller("Lidl", "Krosno", Arrays.asList(p1.getProductId(), p2.getProductId()));
sellerService.saveSeller(seller);
sellerService.saveSeller(seller2);
p1.getSellers().add(seller);
p2.getSellers().add(seller);
p3.getSellers().add(seller);
p1.getSellers().add(seller2);
p2.getSellers().add(seller2);
productService.saveProduct(p1);
productService.saveProduct(p2);
productService.saveProduct(p3);
return "Model Generated";
}
}

View File

@ -0,0 +1,111 @@
package com.pracownia.spring.controllers;
import com.pracownia.spring.entities.Product;
import com.pracownia.spring.entities.Seller;
import com.pracownia.spring.services.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.http.HttpEntity;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.RedirectView;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Objects;
import java.util.Optional;
import java.util.UUID;
/**
* Product controller.
*/
@RestController
@RequestMapping("/api")
public class ProductController {
@Autowired
private ProductService productService;
/**
* List all products.
*
*/
@RequestMapping(value = "/products", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<Product> list(Model model) {
return productService.listAllProducts();
}
// Only for redirect!
@ApiIgnore
@RequestMapping(value = "/products", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<Product> redirect(Model model) {
return productService.listAllProducts();
}
@RequestMapping(value = "/products/{page}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<Product> list(@PathVariable("page") Integer pageNr,@RequestParam("size") Optional<Integer> howManyOnPage) {
return productService.listAllProductsPaging(pageNr, howManyOnPage.orElse(2));
}
/**
* View a specific product by its id.
*
*/
@RequestMapping(value = "/product/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Product getByPublicId(@PathVariable("id") Integer publicId) {
return productService.getProductById(publicId);
}
/**
* View a specific product by its id.
*
*/
@RequestMapping(value = "/product", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Product getByParamPublicId(@RequestParam("id") Integer publicId) {
return productService.getProductById(publicId);
}
/**
* Save product to database.
*
*/
@RequestMapping(value = "/product", method = RequestMethod.POST)
public ResponseEntity<Product> create(@RequestBody @Valid @NotNull Product product) {
product.setProductId(UUID.randomUUID().toString());
productService.saveProduct(product);
return ResponseEntity.ok().body(product);
}
/**
* Edit product in database.
*
*/
@RequestMapping(value = "/product", method = RequestMethod.PUT)
public ResponseEntity<Void> edit(@RequestBody @Valid @NotNull Product product) {
if(!productService.checkIfExist(product.getId()))
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
else {
productService.saveProduct(product);
return new ResponseEntity<>(HttpStatus.CREATED);
}
}
/**
* Delete product by its id.
*
*/
@RequestMapping(value = "/product/{id}", method = RequestMethod.DELETE)
public RedirectView delete(HttpServletResponse response, @PathVariable Integer id) {
productService.deleteProduct(id);
return new RedirectView("/api/sellers", true);
}
}

View File

@ -0,0 +1,84 @@
package com.pracownia.spring.controllers;
import com.pracownia.spring.entities.Product;
import com.pracownia.spring.entities.Seller;
import com.pracownia.spring.services.ProductService;
import com.pracownia.spring.services.SellerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.RedirectView;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Objects;
import java.util.UUID;
@RestController
@RequestMapping("/api")
public class SellerController {
@Autowired
private SellerService sellerService;
@RequestMapping(value = "/sellers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<Seller> list(Model model) {
return sellerService.listAllSellers();
}
// Only for redirect!
@ApiIgnore
@RequestMapping(value = "/sellers", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<Seller> redirect(Model model) {
return sellerService.listAllSellers();
}
@RequestMapping(value = "/seller/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_ATOM_XML_VALUE)
@ResponseBody
public Seller getByPublicId(@PathVariable("id") Integer publicId) {
return sellerService.getSellerById(publicId);
}
@RequestMapping(value = "/seller", method = RequestMethod.POST)
public ResponseEntity<Seller> create(@RequestBody @Valid @NotNull Seller seller) {
sellerService.saveSeller(seller);
return ResponseEntity.ok().body(seller);
}
@RequestMapping(value = "/seller", method = RequestMethod.PUT)
public ResponseEntity<Void> edit(@RequestBody @Valid @NotNull Seller seller) {
Seller sellerFromData = sellerService.getSellerById(seller.getId());
if(Objects.nonNull(sellerFromData)) {
sellerService.saveSeller(seller);
return new ResponseEntity<>(HttpStatus.CREATED);
} else
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
@RequestMapping(value = "/seller/{id}", method = RequestMethod.DELETE)
public RedirectView delete(HttpServletResponse response, @PathVariable Integer id) {
sellerService.deleteSeller(id);
return new RedirectView("/api/sellers", true);
}
@RequestMapping(value = "/seller/{name}", method = RequestMethod.GET)
public List<Seller> getByName(@PathVariable String name) {
return sellerService.getByName(name);
}
@RequestMapping(value = "/seller/products/{id}", method = RequestMethod.GET)
public Integer getProductsSize(@PathVariable Integer id) {
return sellerService.getNumberOfProducts(id);
}
@RequestMapping(value = "/seller/best", method = RequestMethod.GET)
public Seller getBestSeller() {
return sellerService.getBestSeller();
}
}

View File

@ -0,0 +1,71 @@
package com.pracownia.spring.controllers;
import com.pracownia.spring.entities.parent;
import io.swagger.models.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.RedirectView;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Objects;
@RestController
@RequestMapping("/api")
public class parentController {
@Autowired
private com.pracownia.spring.services.parentService parentService;
@RequestMapping(value = "/parents", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<parent> list(Model model) {
return parentService.listAllparents();
}
// Only for redirect!
@ApiIgnore
@RequestMapping(value = "/parents", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<parent> redirect(Model model) {
return parentService.listAllparents();
}
@RequestMapping(value = "/parent/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_ATOM_XML_VALUE)
@ResponseBody
public parent getByPublicId(@PathVariable("id") Integer publicId) {
return parentService.getparentById(publicId);
}
@RequestMapping(value = "/parent", method = RequestMethod.POST)
public ResponseEntity<parent> create(@RequestBody @Valid @NotNull parent parent) {
parentService.saveparent(parent);
return ResponseEntity.ok().body(parent);
}
@RequestMapping(value = "/parent", method = RequestMethod.PUT)
public ResponseEntity<Void> edit(@RequestBody @Valid @NotNull parent parent) {
parent parentFromData = parentService.getparentById(parent.getId());
if(Objects.nonNull(parentFromData)) {
parentService.saveparent(parent);
return new ResponseEntity<>(HttpStatus.CREATED);
} else
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
@RequestMapping(value = "/parent/{id}", method = RequestMethod.DELETE)
public RedirectView delete(HttpServletResponse response, @PathVariable Integer id) {
parentService.deleteparent(id);
return new RedirectView("/api/parents", true);
}
@RequestMapping(value = "/parent/{name}", method = RequestMethod.GET)
public List<parent> getByName(@PathVariable String name) {
return parentService.getByName(name);
}
}

View File

@ -0,0 +1,77 @@
package com.pracownia.spring.controllers;
import com.pracownia.spring.entities.schoolRoom;
import io.swagger.models.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.RedirectView;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Objects;
@RestController
@RequestMapping("/api")
public class schoolRoomController {
@Autowired
private com.pracownia.spring.services.schoolRoomService schoolRoomService;
@RequestMapping(value = "/schoolRooms", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<schoolRoom> list(Model model) {
return schoolRoomService.listAllschoolRooms();
}
// Only for redirect!
@ApiIgnore
@RequestMapping(value = "/schoolRooms", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<schoolRoom> redirect(Model model) {
return schoolRoomService.listAllschoolRooms();
}
@RequestMapping(value = "/schoolRoom/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_ATOM_XML_VALUE)
@ResponseBody
public schoolRoom getByPublicId(@PathVariable("id") Integer publicId) {
return schoolRoomService.getschoolRoomById(publicId);
}
@RequestMapping(value = "/schoolRoom", method = RequestMethod.POST)
public ResponseEntity<schoolRoom> create(@RequestBody @Valid @NotNull schoolRoom schoolRoom) {
schoolRoomService.saveschoolRoom(schoolRoom);
return ResponseEntity.ok().body(schoolRoom);
}
@RequestMapping(value = "/schoolRoom", method = RequestMethod.PUT)
public ResponseEntity<Void> edit(@RequestBody @Valid @NotNull schoolRoom schoolRoom) {
schoolRoom schoolRoomFromData = schoolRoomService.getschoolRoomById(schoolRoom.getId());
if(Objects.nonNull(schoolRoomFromData)) {
schoolRoomService.saveschoolRoom(schoolRoom);
return new ResponseEntity<>(HttpStatus.CREATED);
} else
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
@RequestMapping(value = "/schoolRoom/{id}", method = RequestMethod.DELETE)
public RedirectView delete(HttpServletResponse response, @PathVariable Integer id) {
schoolRoomService.deleteschoolRoom(id);
return new RedirectView("/api/schoolRooms", true);
}
@RequestMapping(value = "/schoolRoom/{number}", method = RequestMethod.GET)
public List<schoolRoom> getByNumber(@PathVariable Integer number) {
return schoolRoomService.getByNumber(number);
}
//@RequestMapping(value = "/schoolRoom/schoolSubjects/{id}", method = RequestMethod.GET)
// public Integer getschoolRoomsSize(@PathVariable Integer id) {
// return schoolRoomService.getNumberOfschoolSubjects(id);
// }
}

View File

@ -0,0 +1,71 @@
package com.pracownia.spring.controllers;
import com.pracownia.spring.entities.schoolSubject;
import io.swagger.models.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.RedirectView;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Objects;
@RestController
@RequestMapping("/api")
public class schoolSubjectController {
@Autowired
private com.pracownia.spring.services.schoolSubjectService schoolSubjectService;
@RequestMapping(value = "/schoolSubjects", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<schoolSubject> list(Model model) {
return schoolSubjectService.listAllschoolSubjects();
}
// Only for redirect!
@ApiIgnore
@RequestMapping(value = "/schoolSubjects", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<schoolSubject> redirect(Model model) {
return schoolSubjectService.listAllschoolSubjects();
}
@RequestMapping(value = "/schoolSubject/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_ATOM_XML_VALUE)
@ResponseBody
public schoolSubject getByPublicId(@PathVariable("id") Integer publicId) {
return schoolSubjectService.getschoolSubjectById(publicId);
}
@RequestMapping(value = "/schoolSubject", method = RequestMethod.POST)
public ResponseEntity<schoolSubject> create(@RequestBody @Valid @NotNull schoolSubject schoolSubject) {
schoolSubjectService.saveschoolSubject(schoolSubject);
return ResponseEntity.ok().body(schoolSubject);
}
@RequestMapping(value = "/schoolSubject", method = RequestMethod.PUT)
public ResponseEntity<Void> edit(@RequestBody @Valid @NotNull schoolSubject schoolSubject) {
schoolSubject schoolSubjectFromData = schoolSubjectService.getschoolSubjectById(schoolSubject.getId());
if(Objects.nonNull(schoolSubjectFromData)) {
schoolSubjectService.saveschoolSubject(schoolSubject);
return new ResponseEntity<>(HttpStatus.CREATED);
} else
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
@RequestMapping(value = "/schoolSubject/{id}", method = RequestMethod.DELETE)
public RedirectView delete(HttpServletResponse response, @PathVariable Integer id) {
schoolSubjectService.deleteschoolSubject(id);
return new RedirectView("/api/schoolSubjects", true);
}
@RequestMapping(value = "/schoolSubject/{name}", method = RequestMethod.GET)
public List<schoolSubject> getByName(@PathVariable String name) {
return schoolSubjectService.getByName(name);
}
}

View File

@ -0,0 +1,97 @@
package com.pracownia.spring.controllers;
import com.pracownia.spring.entities.student;
import com.pracownia.spring.entities.student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.RedirectView;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.Optional;
import java.util.Random;
import java.util.UUID;
/**
* student controller.
*/
@RestController
@RequestMapping("/api")
public class studentController {
@Autowired
private com.pracownia.spring.services.studentService studentService;
//List all students.
@RequestMapping(value = "/students", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<student> list(Model model) {
return studentService.listAllStudents();
}
// Only for redirect!
@ApiIgnore
@RequestMapping(value = "/students", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<student> redirect(Model model) {
return studentService.listAllStudents();
}
@RequestMapping(value = "/students/{page}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<student> list(@PathVariable("page") Integer pageNr,@RequestParam("size") Optional<Integer> howManyOnPage) {
return studentService.listAllStudentsPaging(pageNr, howManyOnPage.orElse(2));
}
//View a specific students by its id.
@RequestMapping(value = "/student/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public student getByPublicId(@PathVariable("id") Integer publicId) {
return studentService.getStudentById(publicId);
}
//View a specific student by its id.
@RequestMapping(value = "/student", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public student getByParamPublicId(@RequestParam("id") Integer publicId) {
return studentService.getStudentById(publicId);
}
//Save student to database.
@RequestMapping(value = "/student", method = RequestMethod.POST)
public ResponseEntity<student> create(@RequestBody @Valid @NotNull student student) {
Random random = new Random();
student.setId(random.nextInt());
studentService.saveStudent(student);
return ResponseEntity.ok().body(student);
}
/**
* Edit student in database.
*
*/
@RequestMapping(value = "/student", method = RequestMethod.PUT)
public ResponseEntity<Void> edit(@RequestBody @Valid @NotNull student student) {
if(!studentService.checkIfExist(student.getId()))
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
else {
studentService.saveStudent(student);
return new ResponseEntity<>(HttpStatus.CREATED);
}
}
/**
* Delete student by its id.
*
*/
@RequestMapping(value = "/student/{id}", method = RequestMethod.DELETE)
public RedirectView delete(HttpServletResponse response, @PathVariable Integer id) {
studentService.deleteStudent(id);
return new RedirectView("/api/teachers", true);
}
}

View File

@ -0,0 +1,77 @@
package com.pracownia.spring.controllers;
import com.pracownia.spring.entities.Seller;
import com.pracownia.spring.entities.teacher;
import io.swagger.models.Model;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.view.RedirectView;
import springfox.documentation.annotations.ApiIgnore;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;
import java.util.Objects;
@RestController
@RequestMapping("/api")
public class teacherController {
@Autowired
private com.pracownia.spring.services.teacherService teacherService;
@RequestMapping(value = "/teachers", method = RequestMethod.GET, produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<teacher> list(Model model) {
return teacherService.listAllTeachers();
}
// Only for redirect!
@ApiIgnore
@RequestMapping(value = "/teachers", method = RequestMethod.DELETE, produces = MediaType.APPLICATION_JSON_VALUE)
public Iterable<teacher> redirect(Model model) {
return teacherService.listAllTeachers();
}
@RequestMapping(value = "/teacher/{id}", method = RequestMethod.GET, produces = MediaType.APPLICATION_ATOM_XML_VALUE)
@ResponseBody
public teacher getByPublicId(@PathVariable("id") Integer publicId) {
return teacherService.getTeacherById(publicId);
}
@RequestMapping(value = "/teacher", method = RequestMethod.POST)
public ResponseEntity<teacher> create(@RequestBody @Valid @NotNull teacher teacher) {
teacherService.saveTeacher(teacher);
return ResponseEntity.ok().body(teacher);
}
@RequestMapping(value = "/teacher", method = RequestMethod.PUT)
public ResponseEntity<Void> edit(@RequestBody @Valid @NotNull teacher teacher) {
teacher teacherFromData = teacherService.getTeacherById(teacher.getId());
if(Objects.nonNull(teacherFromData)) {
teacherService.saveTeacher(teacher);
return new ResponseEntity<>(HttpStatus.CREATED);
} else
return new ResponseEntity<>(HttpStatus.BAD_REQUEST);
}
@RequestMapping(value = "/teacher/{id}", method = RequestMethod.DELETE)
public RedirectView delete(HttpServletResponse response, @PathVariable Integer id) {
teacherService.deleteTeacher(id);
return new RedirectView("/api/teachers", true);
}
@RequestMapping(value = "/teacher/{name}", method = RequestMethod.GET)
public List<teacher> getByName(@PathVariable String name) {
return teacherService.getByName(name);
}
@RequestMapping(value = "/teacher/products/{id}", method = RequestMethod.GET)
public Integer getProductsSize(@PathVariable Integer id) {
return teacherService.getNumberOfStudents(id);
}
}

View File

@ -0,0 +1,99 @@
package com.pracownia.spring.entities;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import javax.persistence.*;
import java.math.BigDecimal;
import java.time.ZonedDateTime;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
/**
* Product entity.
*/
@Entity
@JsonIdentityInfo(generator=ObjectIdGenerators.IntSequenceGenerator.class,
property="refId", scope=Product.class)
public class Product {
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
private Integer id;
@Column
private String productId;
@Column
private String name;
@Column
private BigDecimal price;
@Column
private ZonedDateTime bestBeforeDate;
@ManyToMany(mappedBy = "productsOb")
private Set<Seller> sellers = new HashSet<>();
//required by Hibernate
public Product(){
}
public Product(String productId, String name, BigDecimal price, ZonedDateTime date) {
this.productId = productId;
this.name = name;
this.price = price;
this.bestBeforeDate = date;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public Integer getId() {
return id;
}
public void setId(Integer id) {
this.id = id;
}
public String getProductId() {
return productId;
}
public void setProductId(String productId) {
this.productId = productId;
}
public BigDecimal getPrice() {
return price;
}
public void setPrice(BigDecimal price) {
this.price = price;
}
public ZonedDateTime getBestBeforeDate() {
return bestBeforeDate;
}
public void setBestBeforeDate(ZonedDateTime bestBeforeDate) {
this.bestBeforeDate = bestBeforeDate;
}
public Set<Seller> getSellers() {
return sellers;
}
public void setSellers(Set<Seller> sellers) {
this.sellers = sellers;
}
}

View File

@ -0,0 +1,72 @@
package com.pracownia.spring.entities;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Entity
public class Seller {
@Id
@GeneratedValue(generator = "gen")
@SequenceGenerator(name = "gen", sequenceName = "seller_seq")
@Column(name = "id")
private int id;
@Column
private String name;
@Column
private String city;
@ElementCollection
@CollectionTable(name = "products")
@Column(name = "product_id")
private List<String> products = new ArrayList<>();
@ManyToMany(fetch = FetchType.LAZY)
private List<Product> productsOb;
//required by Hibernate
public Seller(){
}
public Seller(String name, String city, List<String> products) {
this.name = name;
this.city = city;
this.products = products;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
public String getName() {
return name;
}
public void setName(String name) {
this.name = name;
}
public String getCity() {
return city;
}
public void setCity(String city) {
this.city = city;
}
public List<String> getProducts() {
return products;
}
public void setProducts(List<String> products) {
this.products = products;
}
}

View File

@ -0,0 +1,46 @@
package com.pracownia.spring.entities;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import javax.persistence.*;
@Entity
@JsonIdentityInfo(generator= ObjectIdGenerators.IntSequenceGenerator.class,
property="refId", scope=parent.class)
public class parent {
@Id
@GeneratedValue
@Column(name = "id_parent")
private int id;
@Column(name="first_name_parent")
private String firstName;
@Column(name="last_name_parent")
private String lastName;
@Column(name="number")
private String number;
@OneToOne(mappedBy ="parent")
student student;
public parent()
{
}
public parent(int id, String firstName, String lastName, String number)
{
this.id=id;
this.firstName=firstName;
this.lastName=lastName;
this.number=number;
}
public int getId() { return id;}
public void setId( int id ) { this.id = id; }
public String getFirstName(){return firstName;}
public void setFirstName(String firstName) {this.firstName=firstName;}
public String getLastName() {return lastName;}
public void setLastName(String lastName) {this.lastName=lastName;}
public String getNumber() { return number;}
public void setNumber(String number) {this.number=number;}
}

View File

@ -0,0 +1,39 @@
package com.pracownia.spring.entities;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Entity
@JsonIdentityInfo(generator= ObjectIdGenerators.IntSequenceGenerator.class,
property="refId", scope=schoolRoom.class)
public class schoolRoom {
@Id
@GeneratedValue
@Column(name = "id_school_room")
private int id;
@Column(name="school_room_number")
private int schoolRoomNumber;
@ManyToMany(cascade = CascadeType.ALL)
private List<schoolSubject> schoolSubjects = new ArrayList<>();
public schoolRoom()
{
}
public schoolRoom(int id, int schoolRoomNumber)
{
this.id=id;
this.schoolRoomNumber=schoolRoomNumber;
}
public List<schoolSubject> getSchoolSubjects() { return schoolSubjects; }
public void setSchoolSubjects(List<schoolSubject> schoolSubjects) { this.schoolSubjects = schoolSubjects; }
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public int getSchoolRoomNumber() { return schoolRoomNumber; }
public void setSchoolRoomNumber(int schoolRoomNumber) { this.schoolRoomNumber = schoolRoomNumber; }
}

View File

@ -0,0 +1,44 @@
package com.pracownia.spring.entities;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Entity
@JsonIdentityInfo(generator= ObjectIdGenerators.IntSequenceGenerator.class,
property="refId", scope=schoolSubject.class)
public class schoolSubject {
@Id
@GeneratedValue
@Column(name = "id_school_subject")
private int id;
@Column(name="school_subject_name")
private String schoolSubjectName;
@OneToOne(mappedBy ="schoolSubject")
teacher teacher;
@ManyToMany(mappedBy = "schoolSubjects", cascade = CascadeType.ALL)
private List<schoolRoom> schoolRooms = new ArrayList<>();
public schoolSubject()
{
}
public schoolSubject(int id, String schoolSubjectName)
{
this.id=id;
this.schoolSubjectName=schoolSubjectName;
}
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getSchoolSubjectName() { return schoolSubjectName; }
public void setSchoolSubjectName(String schoolSubjectName) { this.schoolSubjectName = schoolSubjectName; }
public com.pracownia.spring.entities.teacher getTeacher() { return teacher; }
public void setTeacher(com.pracownia.spring.entities.teacher teacher) { this.teacher = teacher; }
public List<schoolRoom> getSchoolRooms() { return schoolRooms; }
public void setSchoolRooms(List<schoolRoom> schoolRooms) { this.schoolRooms = schoolRooms; }
}

View File

@ -0,0 +1,88 @@
package com.pracownia.spring.entities;
import com.fasterxml.jackson.annotation.JsonFormat;
import com.fasterxml.jackson.annotation.JsonIdentityInfo;
import com.fasterxml.jackson.annotation.JsonProperty;
import com.fasterxml.jackson.annotation.ObjectIdGenerators;
import org.joda.time.DateTime;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
import java.util.UUID;
@Entity
@JsonIdentityInfo(generator= ObjectIdGenerators.IntSequenceGenerator.class,
property="refId", scope=student.class)
public class student {
@Id
@GeneratedValue
@Column(name = "id_student")
private int id;
@Column(name="first_name")
private String firstName;
@Column(name="last_name")
private String lastName;
@JsonFormat(shape = JsonFormat.Shape.STRING, pattern = "yyyy-MM-dd")
@Column(name="birth")
private DateTime birth;
@Column(name="place_of_birth")
private String place_of_birth;
@Column(name="class")
private String clas;
@JsonProperty("student")
@Column(name="if_student")
private boolean status; //true for student false for graduate
//uczen do rodzica
@OneToOne(cascade = CascadeType.PERSIST)
@JoinColumn(name="id_parent", referencedColumnName = "id_parent")
com.pracownia.spring.entities.parent parent;
//uczen do nauczyciela
@ManyToMany(cascade = CascadeType.ALL)
private List<teacher> teachers = new ArrayList<>();
//potrzebny do hibernate?
public student()
{
}
public student(int id, String firstName, String lastName, DateTime birth, String place_of_birth, String clas)
{
this.id=id;
this.firstName=firstName;
this.lastName=lastName;
this.birth=birth;
this.place_of_birth=place_of_birth;
this.clas=clas;
}
public int getId() { return id;}
public void setId(int id ) { this.id = id; }
public String getFirstName(){return firstName;}
public void setFirstName(String firstName) {this.firstName=firstName;}
public String getLastName() {return lastName;}
public void setLastName(String lastName) {this.lastName=lastName;}
public DateTime getBirth() {return birth;}
public void setBirth(DateTime birth) {this.birth=birth;}
public String getPlace_of_birth (){return place_of_birth;}
public void setPlace_of_birth (String place_of_birth){this.place_of_birth=place_of_birth;}
public String getClas() {return clas;}
public void setClas (String clas){this.clas=clas;}
public boolean getStatus (){return status;}
public void setStatus (boolean status){this.status=status;}
public com.pracownia.spring.entities.parent getParent() {
return parent;
}
public void setParent(com.pracownia.spring.entities.parent parent) {
this.parent = parent;
}
public List<teacher> getTeachers() { return teachers; }
public void setTeachers(List<teacher> teachers) { this.teachers = teachers; }
}

View File

@ -0,0 +1,47 @@
package com.pracownia.spring.entities;
import javax.persistence.*;
import java.util.ArrayList;
import java.util.List;
@Entity
@Table(name = "teacher")
public class teacher {
@Id
@GeneratedValue
@Column(name = "id_teacher")
private int id;
@Column(name = "first_name")
private String firstName;
@Column(name="last_name")
private String lastName;
@ManyToMany(mappedBy = "teachers", cascade = CascadeType.ALL)
private List<student> students =new ArrayList<student>();
@OneToOne(cascade = CascadeType.PERSIST)
@JoinColumn(name="school_subject_name", referencedColumnName = "school_subject_name")
schoolSubject schoolSubject;
public teacher(){
}
public teacher(int id, String firstName, String lastName)
{
this.id=id;
this.firstName=firstName;
this.lastName=lastName;
}
public int getId() { return id; }
public void setId(int id) { this.id = id; }
public String getFirstName() { return firstName; }
public void setFirstName(String firstName) { this.firstName = firstName; }
public String getLastName() { return lastName; }
public void setLastName(String lastName) { this.lastName = lastName; }
public List<student> getStudents() { return students; }
public void setStudents(List<student> students) { this.students = students; }
public void setSchoolSubject(com.pracownia.spring.entities.schoolSubject schoolSubject) { this.schoolSubject = schoolSubject; }
public com.pracownia.spring.entities.schoolSubject getSchoolSubject() { return schoolSubject; }
}

View File

@ -0,0 +1,17 @@
package com.pracownia.spring.repositories;
import com.pracownia.spring.entities.Product;
import org.springframework.data.domain.Sort;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import org.springframework.stereotype.Repository;
public interface ProductRepository extends CrudRepository<Product, Integer>, PagingAndSortingRepository<Product, Integer> {
Product findByProductId(String productId);
@Query("select count(*) from Product p where p.id = ?1")
Integer checkIfExist(Integer id);
}

View File

@ -0,0 +1,19 @@
package com.pracownia.spring.repositories;
import com.pracownia.spring.entities.Product;
import com.pracownia.spring.entities.Seller;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import java.util.List;
public interface SellerRepository extends CrudRepository<Seller, Integer> {
List<Seller> findByName(String name);
@Query("select count(*) from Seller s join s.products p where s.id = ?1")
Integer countProductsById(Integer id);
@Query("select p from Seller s join s.productsOb p where s.id = ?1")
List<Product> getProductsById(Integer id);
}

View File

@ -0,0 +1,23 @@
package com.pracownia.spring.repositories;
import com.pracownia.spring.entities.student;
import com.pracownia.spring.entities.parent;
import com.pracownia.spring.entities.parent;
import com.pracownia.spring.entities.parent;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface parentRepository extends CrudRepository<parent, Integer>, PagingAndSortingRepository<parent, Integer> {
List<parent> findByName(String name);
//@Query("select count(*) from parent s join s.students p where s.id = ?1")
//Integer countStudentsById(Integer id);
//@Query("select p from parent s join s.studentsOb p where s.id = ?1")
//List<student> getStudentsById(Integer id);
}

View File

@ -0,0 +1,22 @@
package com.pracownia.spring.repositories;
import com.pracownia.spring.entities.schoolSubject;
import com.pracownia.spring.entities.student;
import com.pracownia.spring.entities.schoolRoom;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface schoolRoomRepository extends CrudRepository<schoolRoom, Integer>, PagingAndSortingRepository<schoolRoom, Integer> {
List<schoolRoom> findByNumber(Integer id);
@Query("select count(*) from schoolRoom s join s.schoolSubjects p where s.id = ?1")
List<schoolRoom> countschoolSubjectsByNumber(Integer id);
@Query("select p from schoolRoom s join s.schoolSubjectsOb p where s.id = ?1")
List<schoolSubject> getschoolSubjectByNumber(Integer id);
}

View File

@ -0,0 +1,20 @@
package com.pracownia.spring.repositories;
import com.pracownia.spring.entities.schoolSubject;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface schoolSubjectRepository extends CrudRepository<schoolSubject, Integer>, PagingAndSortingRepository<schoolSubject, Integer> {
List<schoolSubject> findByName(String name);
//@Query("select count(*) from schoolSubject s join s.students p where s.id = ?1")
//Integer countStudentsById(Integer id);
//@Query("select p from schoolSubject s join s.studentsOb p where s.id = ?1")
//List<student> getStudentsById(Integer id);
}

View File

@ -0,0 +1,15 @@
package com.pracownia.spring.repositories;
import com.pracownia.spring.entities.student;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface studentRepository extends CrudRepository<student, Integer>, PagingAndSortingRepository<student, Integer> {
student findByStudentId(String productId);
@Query("select count(*) from Product p where p.id = ?1")
Integer checkIfExist(Integer id);
}

View File

@ -0,0 +1,23 @@
package com.pracownia.spring.repositories;
import com.pracownia.spring.entities.Product;
import com.pracownia.spring.entities.Seller;
import com.pracownia.spring.entities.student;
import com.pracownia.spring.entities.teacher;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.CrudRepository;
import org.springframework.data.repository.PagingAndSortingRepository;
import java.util.List;
public interface teacherRepository extends CrudRepository<teacher, Integer>, PagingAndSortingRepository<teacher, Integer> {
List<teacher> findByName(String name);
@Query("select count(*) from teacher s join s.students p where s.id = ?1")
Integer countStudentsById(Integer id);
@Query("select p from teacher s join s.studentsOb p where s.id = ?1")
List<student> getStudentsById(Integer id);
}

View File

@ -0,0 +1,20 @@
package com.pracownia.spring.services;
import com.pracownia.spring.entities.Product;
import java.util.Optional;
public interface ProductService {
Iterable<Product> listAllProducts();
Product getProductById(Integer id);
Product saveProduct(Product product);
void deleteProduct(Integer id);
Boolean checkIfExist(Integer id);
public Iterable<Product> listAllProductsPaging(Integer pageNr, Integer howManyOnPage);
}

View File

@ -0,0 +1,54 @@
package com.pracownia.spring.services;
import com.pracownia.spring.entities.Product;
import com.pracownia.spring.repositories.ProductRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
import java.util.Optional;
/**
* Product service implement.
*/
@Service
public class ProductServiceImpl implements ProductService {
@Autowired
private ProductRepository productRepository;
@Override
public Iterable<Product> listAllProductsPaging(Integer pageNr, Integer howManyOnPage) {
return productRepository.findAll(new PageRequest(pageNr,howManyOnPage));
}
@Override
public Iterable<Product> listAllProducts() {
return productRepository.findAll();
}
@Override
public Product getProductById(Integer id) {
return productRepository.findOne(id);
}
@Override
public Product saveProduct(Product product) {
return productRepository.save(product);
}
@Override
public void deleteProduct(Integer id) {
productRepository.delete(id);
}
@Override
public Boolean checkIfExist(Integer id) {
if (productRepository.checkIfExist(id) > 0)
return true;
else
return false;
}
}

View File

@ -0,0 +1,23 @@
package com.pracownia.spring.services;
import com.pracownia.spring.entities.Product;
import com.pracownia.spring.entities.Seller;
import java.util.List;
public interface SellerService {
Iterable<Seller> listAllSellers();
Seller getSellerById(Integer id);
Seller saveSeller(Seller seller);
void deleteSeller(Integer id);
List<Seller> getByName(String name);
Integer getNumberOfProducts(Integer id);
Seller getBestSeller();
}

View File

@ -0,0 +1,68 @@
package com.pracownia.spring.services;
import com.pracownia.spring.entities.Product;
import com.pracownia.spring.entities.Seller;
import com.pracownia.spring.repositories.ProductRepository;
import com.pracownia.spring.repositories.SellerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.math.BigDecimal;
import java.util.List;
@Service
public class SellerServiceImpl implements SellerService {
@Autowired
private SellerRepository sellerRepository;
@Override
public Iterable<Seller> listAllSellers() {
return sellerRepository.findAll();
}
@Override
public Seller getSellerById(Integer id) {
return sellerRepository.findOne(id);
}
@Override
public Seller saveSeller(Seller seller) {
return sellerRepository.save(seller);
}
@Override
public void deleteSeller(Integer id) {
sellerRepository.delete(id);
}
@Override
public List<Seller> getByName(String name) {
return sellerRepository.findByName(name);
}
@Override
public Integer getNumberOfProducts(Integer id) {
return sellerRepository.countProductsById(id);
}
@Override
public Seller getBestSeller() {
double max = 0;
int maxId = 0;
Iterable<Seller> sellers = sellerRepository.findAll();
for(Seller s : sellers) {
double sum = 0.0;
List<Product> products = sellerRepository.getProductsById(s.getId());
for(Product pid : products) {
sum += pid.getPrice().doubleValue();
}
if (sum > max) {
max = sum;
maxId = s.getId();
}
}
return sellerRepository.findOne(maxId);
}
}

View File

@ -0,0 +1,21 @@
package com.pracownia.spring.services;
import com.pracownia.spring.entities.parent;
import java.util.List;
public interface parentService {
Iterable<parent> listAllparents();
parent getparentById(Integer id);
parent saveparent(parent parent);
void deleteparent(Integer id);
List<parent> getByName(String name);
//Integer getNumberOfStudents(Integer id);
}

View File

@ -0,0 +1,36 @@
package com.pracownia.spring.services;
import com.pracownia.spring.entities.parent;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class parentServiceImpl implements parentService {
@Autowired
private com.pracownia.spring.repositories.parentRepository parentRepository;
@Override
public Iterable<parent> listAllparents() { return parentRepository.findAll(); }
@Override
public parent getparentById(Integer id) {
return parentRepository.findOne(id);
}
@Override
public parent saveparent(parent parent) {
return parentRepository.save(parent);
}
@Override
public void deleteparent(Integer id) {
parentRepository.delete(id);
}
@Override
public List<parent> getByName(String name) {
return parentRepository.findByName(name);
}
}

View File

@ -0,0 +1,20 @@
package com.pracownia.spring.services;
import com.pracownia.spring.entities.schoolRoom;
import java.util.List;
public interface schoolRoomService {
Iterable<schoolRoom> listAllschoolRooms();
schoolRoom getschoolRoomById(Integer id);
schoolRoom saveschoolRoom(schoolRoom schoolRoom);
void deleteschoolRoom(Integer id);
List<schoolRoom> getByNumber(Integer id);
// Integer getNumberOfschoolSubjects(Integer id);
}

View File

@ -0,0 +1,45 @@
package com.pracownia.spring.services;
import com.pracownia.spring.entities.schoolRoom;
import com.pracownia.spring.repositories.schoolRoomRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class schoolRoomServiceImpl implements schoolRoomService {
@Autowired
private com.pracownia.spring.repositories.schoolRoomRepository schoolRoomRepository;
@Override
public Iterable<schoolRoom> listAllschoolRooms() {
return schoolRoomRepository.findAll();
}
@Override
public schoolRoom getschoolRoomById(Integer id) {
return schoolRoomRepository.findOne(id);
}
@Override
public schoolRoom saveschoolRoom(schoolRoom schoolRoom) {
return schoolRoomRepository.save(schoolRoom);
}
@Override
public void deleteschoolRoom(Integer id) {
schoolRoomRepository.delete(id);
}
@Override
public List<schoolRoom> getByNumber(Integer id) {
return schoolRoomRepository.findByNumber(id);
}
// @Override
//public Integer getNumberOfschoolSubjects(Integer id) {
// return schoolRoomRepository.countschoolSubjectsByNumber(id);
// }
}

View File

@ -0,0 +1,17 @@
package com.pracownia.spring.services;
import com.pracownia.spring.entities.schoolSubject;
import java.util.List;
public interface schoolSubjectService {
Iterable<schoolSubject> listAllschoolSubjects();
schoolSubject getschoolSubjectById(Integer id);
schoolSubject saveschoolSubject(schoolSubject schoolSubject);
void deleteschoolSubject(Integer id);
List<schoolSubject> getByName(String name);
}

View File

@ -0,0 +1,41 @@
package com.pracownia.spring.services;
import com.pracownia.spring.entities.schoolSubject;
import com.pracownia.spring.repositories.schoolSubjectRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class schoolSubjectServiceImpl implements schoolSubjectService{
@Autowired
private com.pracownia.spring.repositories.schoolSubjectRepository schoolSubjectRepository;
@Override
public Iterable<schoolSubject> listAllschoolSubjects() {
return schoolSubjectRepository.findAll();
}
@Override
public schoolSubject getschoolSubjectById(Integer id) {
return schoolSubjectRepository.findOne(id);
}
@Override
public schoolSubject saveschoolSubject(schoolSubject schoolSubject) {
return schoolSubjectRepository.save(schoolSubject);
}
@Override
public void deleteschoolSubject(Integer id) {
schoolSubjectRepository.delete(id);
}
@Override
public List<schoolSubject> getByName(String name) {
return schoolSubjectRepository.findByName(name);
}
}

View File

@ -0,0 +1,19 @@
package com.pracownia.spring.services;
import com.pracownia.spring.entities.student;
public interface studentService {
Iterable<student> listAllStudents();
student getStudentById(Integer id);
student saveStudent(student student);
void deleteStudent(Integer id);
Boolean checkIfExist(Integer id);
public Iterable<student> listAllStudentsPaging(Integer pageNr, Integer howManyOnPage);
}

View File

@ -0,0 +1,47 @@
package com.pracownia.spring.services;
import com.pracownia.spring.entities.student;
import com.pracownia.spring.repositories.studentRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.PageRequest;
import org.springframework.stereotype.Service;
@Service
public class studentServicelmpl implements studentService{
@Autowired
com.pracownia.spring.repositories.studentRepository studentRepository;
@Override
public Iterable<student> listAllStudents() {
return studentRepository.findAll();
}
@Override
public student getStudentById(Integer id) {
return studentRepository.findOne(id);
}
@Override
public student saveStudent(student student) {
return studentRepository.save(student);
}
@Override
public void deleteStudent(Integer id) {
studentRepository.delete(id);
}
@Override
public Boolean checkIfExist(Integer id) {
if(studentRepository.checkIfExist(id)>0)
return true;
else
return false;
}
@Override
public Iterable<student> listAllStudentsPaging(Integer pageNr, Integer howManyOnPage) {
return studentRepository.findAll(new PageRequest(pageNr, howManyOnPage));
}
}

View File

@ -0,0 +1,22 @@
package com.pracownia.spring.services;
import com.pracownia.spring.entities.student;
import com.pracownia.spring.entities.teacher;
import java.util.List;
public interface teacherService {
Iterable<teacher> listAllTeachers();
teacher getTeacherById(Integer id);
teacher saveTeacher(teacher teacher);
void deleteTeacher(Integer id);
List<teacher> getByName(String name);
Integer getNumberOfStudents(Integer id);
}

View File

@ -0,0 +1,37 @@
package com.pracownia.spring.services;
import com.pracownia.spring.entities.student;
import com.pracownia.spring.entities.teacher;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import java.util.List;
@Service
public class teacherServiceImpl implements teacherService {
@Autowired
private com.pracownia.spring.repositories.teacherRepository teacherRepository;
@Override
public Iterable<teacher> listAllTeachers() {
return teacherRepository.findAll();
}
@Override
public teacher getTeacherById(Integer id) { return teacherRepository.findOne(id); }
@Override
public teacher saveTeacher(teacher teacher) { return teacherRepository.save(teacher); }
@Override
public void deleteTeacher(Integer id) { teacherRepository.delete(id); }
@Override
public List<teacher> getByName(String name) {
return teacherRepository.findByName(name);
}
@Override
public Integer getNumberOfStudents(Integer id) { return teacherRepository.countStudentsById(id); }
}

View File

@ -0,0 +1,17 @@
## Spring DATASOURCE (DataSourceAutoConfiguration & DataSourceProperties)
spring.jpa.show-sql=true
spring.database.driverClassName=org.postgresql.Driver
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=s444461
spring.datasource.password=evespenracesier
## Hibernate Properties
# The SQL dialect makes Hibernate generate better SQL for the chosen database
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQL94Dialect
# Hibernate ddl auto (create, create-drop, validate, update)
spring.jpa.hibernate.ddl-auto = create