Skip to content

Rainer 13032021 #18

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

Open
wants to merge 4 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
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ build/
!gradle/wrapper/gradle-wrapper.jar
!**/src/main/**
!**/src/test/**
### maven I introduced it 16032020, runs with JDK15 ###
target/

### STS ###
.apt_generated
Expand Down
1 change: 1 addition & 0 deletions db/passwordfile.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
postgres
21 changes: 21 additions & 0 deletions docker-compose-postgres-only.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
version: "3.7"
services:
db:
image: postgres:12
ports:
- "5432:5432"
secrets:
- db-password
volumes:
- db-data:/var/lib/postgresql/data
networks:
- spring-postgres
environment:
- POSTGRES_PASSWORD_FILE=/run/secrets/db-password
volumes:
db-data:
secrets:
db-password:
file: db/passwordfile.txt
networks:
spring-postgres:
30 changes: 30 additions & 0 deletions knowhow-Docker-postgres.rai
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
gradle jedoch nur JDK 11
gradle build clean

oder

maven mit JDK 15
mvn clean
mvn spring-boot:run

docker run -p 5432:5432 -d -e POSTGRES_PASSWORD=postgres -e POSTGRES_USER=postgres -e POSTGRES_DB=postgres -v pgdata:/var/lib/postgresql/data postgres
oder
docker-compose up -f docker-compose-postgres-only.yml

mit heidisql
Verbindung mit port 5432 / postgres / postgres

DROP TABLE IF EXISTS student;
CREATE TABLE "student001" (
"student_id" SERIAL PRIMARY KEY,
"student_branch" VARCHAR(255) NULL,
"student_email" VARCHAR(255) NULL,
"student_name" VARCHAR(255) NULL
)
;

INSERT INTO student001 ( student_branch, student_email, student_name) VALUES
( 'BCA', '[email protected]', 'MDolly'),
( 'B-Tech', '[email protected]', 'rainier'),
('M-Tech', '[email protected]', 'Ula'),
('B-Tech', '[email protected]', 'Ula Habich 29.03.1983 meet 2015 (18.09.2015)),(01.11.2015),(21.12.2015) and 2016 (23.01.2016'));
54 changes: 54 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?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>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.3.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.main</groupId>
<artifactId>Student</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>Student</name>
<description>Demo project for Spring Boot</description>

<properties>
<java.version>15</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.postgresql</groupId>
<artifactId>postgresql</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.circleci.demojavaspring.controller;

import com.circleci.demojavaspring.model.Student;
import com.circleci.demojavaspring.service.Student_Service;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Optional;

@RestController
@CrossOrigin(origins="http://localhost:4200")
@RequestMapping(value="/api")
public class StudentController {

@Autowired
private Student_Service studentservice;

@PostMapping("save-student")
public boolean saveStudent(@RequestBody Student student) {
return studentservice.saveStudent(student);
}

@GetMapping("students-list")
public List<Student> allstudents() {
return studentservice.getStudents();
}


@DeleteMapping("delete-student/{student_id}")
public boolean deleteStudent(@PathVariable("student_id") int student_id,Student student) {
student.setStudent_id(student_id);
return studentservice.deleteStudent(student);
}

@GetMapping("student/{student_id}")
public List<Student> allstudentByID(@PathVariable("student_id") int student_id, Student student) {
student.setStudent_id(student_id);
return studentservice.getStudentByID(student);
}

@PostMapping("update-student/{student_id}")
public boolean updateStudent(@RequestBody Student student,@PathVariable("student_id") int student_id) {
student.setStudent_id(student_id);
return studentservice.updateStudent(student);
}
}
15 changes: 15 additions & 0 deletions src/main/java/com/circleci/demojavaspring/dao/Student_DAO.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package com.circleci.demojavaspring.dao;

import com.circleci.demojavaspring.model.Student;

import java.util.List;
import java.util.Optional;

public interface Student_DAO {

public boolean saveStudent(Student student);
public List<Student> getStudents();
public boolean deleteStudent(Student student);
public Optional<Student> getStudentByID(Student student);
public boolean updateStudent(Student student);
}
63 changes: 63 additions & 0 deletions src/main/java/com/circleci/demojavaspring/dao/Student_DAO_Imp.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.circleci.demojavaspring.dao;

import com.circleci.demojavaspring.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;
import com.circleci.demojavaspring.repository.StudentRepository;

import java.util.List;
import java.util.Optional;

@Repository
public class Student_DAO_Imp implements Student_DAO{

@Autowired
private StudentRepository studentRepository;

@Override
public boolean saveStudent(Student student) {
boolean status=false;
try {
studentRepository.save(student);
status=true;
} catch (Exception e) {
e.printStackTrace();
}
return status;
}

@Override
public List<Student> getStudents() {

return studentRepository.findAll();
}

@Override
public boolean deleteStudent(Student student) {
boolean status=false;
try {
studentRepository.delete(student);
status=true;
} catch (Exception e) {
e.printStackTrace();
}
return status;
}

@Override
public Optional<Student> getStudentByID(Student student) {
return studentRepository.findById(student.getStudent_id());
}

@Override
public boolean updateStudent(Student student) {
boolean status=false;
try {
studentRepository.save(student);
status=true;
} catch (Exception e) {
e.printStackTrace();
}
return status;
}
}
48 changes: 48 additions & 0 deletions src/main/java/com/circleci/demojavaspring/model/Student.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.circleci.demojavaspring.model;

import javax.persistence.*;

@Entity
@Table(name = "student")
public class Student {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private int student_id;
private String student_name;
private String student_email;
private String student_branch;

public int getStudent_id() {
return student_id;
}

public void setStudent_id(int student_id) {
this.student_id = student_id;
}

public String getStudent_name() {
return student_name;
}

public void setStudent_name(String student_name) {
this.student_name = student_name;
}

public String getStudent_email() {
return student_email;
}

public void setStudent_email(String student_email) {
this.student_email = student_email;
}

public String getStudent_branch() {
return student_branch;
}

public void setStudent_branch(String student_branch) {
this.student_branch = student_branch;
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.circleci.demojavaspring.repository;

import com.circleci.demojavaspring.model.Student;
import org.springframework.data.repository.CrudRepository;

import java.util.List;

public interface StudentRepository extends CrudRepository<Student, Integer> {
@Override
List<Student> findAll();
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.circleci.demojavaspring.service;

import com.circleci.demojavaspring.model.Student;

import java.util.List;
import java.util.Optional;

public interface Student_Service {
public boolean saveStudent(Student student);
public List<Student> getStudents();
public boolean deleteStudent(Student student);
public List<Student> getStudentByID(Student student);
public boolean updateStudent(Student student);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package com.circleci.demojavaspring.service;

import com.circleci.demojavaspring.dao.Student_DAO;
import com.circleci.demojavaspring.model.Student;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.ArrayList;
import java.util.List;

@Service
@Transactional
public class Student_Service_Imp implements Student_Service {

@Autowired
private Student_DAO studentdao;

@Override
public boolean saveStudent(Student student) {
return studentdao.saveStudent(student);
}

@Override
public List<Student> getStudents() {
return studentdao.getStudents();
}

@Override
public boolean deleteStudent(Student student) {
return studentdao.deleteStudent(student);
}

@Override
public List<Student> getStudentByID(Student student) {
Student studa = studentdao.getStudentByID(student).get();
ArrayList<Student> studentArrayList = new ArrayList<>();
studentArrayList.add(studa);
return studentArrayList;
}

@Override
public boolean updateStudent(Student student) {
return studentdao.updateStudent(student);
}

}
2 changes: 1 addition & 1 deletion src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=password
spring.datasource.password=postgres

spring.jpa.show-sql=true
spring.jpa.hibernate.ddl-auto=update
Expand Down
9 changes: 7 additions & 2 deletions src/main/resources/test.properties
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
spring.datasource.url=jdbc:postgresql://localhost:5432/circle_test
#spring.datasource.url=jdbc:postgresql://localhost:5432/circle_test
#spring.datasource.username=postgres
spring.datasource.url=jdbc:postgresql://localhost:5432/postgres
spring.datasource.username=postgres
spring.datasource.password=postgres

spring.jpa.hibernate.ddl-auto=create-drop
#spring.jpa.hibernate.ddl-auto=create-drop
spring.jpa.hibernate.ddl-auto=update
spring.jpa.properties.hibernate.jdbc.lob.non_contextual_creation=true
Loading