Spaces:
Sleeping
Sleeping
Taki Eddine RAHAL
commited on
Commit
·
fc2d12e
1
Parent(s):
0533164
Add project
Browse files
Dockerfile
CHANGED
@@ -3,7 +3,7 @@
|
|
3 |
#
|
4 |
FROM maven:3.8.2-jdk-11 AS build
|
5 |
COPY . .
|
6 |
-
RUN mvn clean package -
|
7 |
|
8 |
#
|
9 |
# Package stage
|
|
|
3 |
#
|
4 |
FROM maven:3.8.2-jdk-11 AS build
|
5 |
COPY . .
|
6 |
+
RUN mvn clean package -DskipTests
|
7 |
|
8 |
#
|
9 |
# Package stage
|
pom.xml
CHANGED
@@ -21,7 +21,6 @@
|
|
21 |
<groupId>org.springframework.boot</groupId>
|
22 |
<artifactId>spring-boot-starter-web</artifactId>
|
23 |
</dependency>
|
24 |
-
|
25 |
<dependency>
|
26 |
<groupId>org.springframework.boot</groupId>
|
27 |
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
|
|
21 |
<groupId>org.springframework.boot</groupId>
|
22 |
<artifactId>spring-boot-starter-web</artifactId>
|
23 |
</dependency>
|
|
|
24 |
<dependency>
|
25 |
<groupId>org.springframework.boot</groupId>
|
26 |
<artifactId>spring-boot-starter-data-jpa</artifactId>
|
src/main/java/com/example/demo/DemoApplication.java
CHANGED
@@ -1,12 +1,42 @@
|
|
1 |
package com.example.demo;
|
2 |
|
|
|
|
|
|
|
3 |
import org.springframework.boot.SpringApplication;
|
4 |
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
|
|
5 |
|
6 |
@SpringBootApplication
|
|
|
7 |
public class DemoApplication {
|
8 |
|
|
|
|
|
|
|
9 |
public static void main(String[] args) {
|
10 |
SpringApplication.run(DemoApplication.class, args);
|
11 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
12 |
}
|
|
|
1 |
package com.example.demo;
|
2 |
|
3 |
+
import com.example.demo.entity.User;
|
4 |
+
import com.example.demo.repository.UserRepository;
|
5 |
+
import org.springframework.beans.factory.annotation.Autowired;
|
6 |
import org.springframework.boot.SpringApplication;
|
7 |
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
8 |
+
import org.springframework.web.bind.annotation.GetMapping;
|
9 |
+
import org.springframework.web.bind.annotation.RestController;
|
10 |
|
11 |
@SpringBootApplication
|
12 |
+
@RestController
|
13 |
public class DemoApplication {
|
14 |
|
15 |
+
@Autowired
|
16 |
+
UserRepository userRepository;
|
17 |
+
|
18 |
public static void main(String[] args) {
|
19 |
SpringApplication.run(DemoApplication.class, args);
|
20 |
}
|
21 |
+
|
22 |
+
|
23 |
+
@GetMapping("list")
|
24 |
+
public String fetchUsers(){
|
25 |
+
final String[] result = {"Hello Render "};
|
26 |
+
userRepository.findAll().stream().forEach(user -> {
|
27 |
+
result[0] += user.getFirstName()+" "+user.getLastName();
|
28 |
+
});
|
29 |
+
return result[0];
|
30 |
+
}
|
31 |
+
|
32 |
+
@GetMapping("add-user")
|
33 |
+
public String addUser(){
|
34 |
+
User user = new User();
|
35 |
+
user.setFirstName("Render");
|
36 |
+
user.setLastName("Spring Boot");
|
37 |
+
userRepository.save(user);
|
38 |
+
return "User added successfully";
|
39 |
+
}
|
40 |
+
|
41 |
+
|
42 |
}
|
src/main/java/com/example/demo/entity/User.java
CHANGED
@@ -3,6 +3,9 @@ package com.example.demo.entity;
|
|
3 |
import javax.persistence.*;
|
4 |
import java.io.Serializable;
|
5 |
|
|
|
|
|
|
|
6 |
public class User implements Serializable {
|
7 |
|
8 |
@Id
|
|
|
3 |
import javax.persistence.*;
|
4 |
import java.io.Serializable;
|
5 |
|
6 |
+
|
7 |
+
@Entity
|
8 |
+
@Table(name="users")
|
9 |
public class User implements Serializable {
|
10 |
|
11 |
@Id
|
src/main/java/com/example/demo/repository/UserRepository.java
CHANGED
@@ -1,4 +1,9 @@
|
|
1 |
package com.example.demo.repository;
|
2 |
|
3 |
-
|
|
|
|
|
|
|
|
|
|
|
4 |
}
|
|
|
1 |
package com.example.demo.repository;
|
2 |
|
3 |
+
import com.example.demo.entity.User;
|
4 |
+
import org.springframework.data.jpa.repository.JpaRepository;
|
5 |
+
import org.springframework.stereotype.Repository;
|
6 |
+
|
7 |
+
@Repository
|
8 |
+
public interface UserRepository extends JpaRepository<User, Long> {
|
9 |
}
|
src/main/resources/application.properties
CHANGED
@@ -1,10 +1,10 @@
|
|
|
|
1 |
server.tomcat.accesslog.enabled=true
|
2 |
|
3 |
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
|
4 |
spring.jpa.hibernate.ddl-auto=update
|
5 |
spring.jpa.hibernate.show-sql=true
|
6 |
|
7 |
-
# Local configuration DB
|
8 |
spring.datasource.url=jdbc:postgresql://localhost:5432/spring-boot-render
|
9 |
spring.datasource.username=postgres
|
10 |
spring.datasource.password=azerty
|
|
|
1 |
+
|
2 |
server.tomcat.accesslog.enabled=true
|
3 |
|
4 |
spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.PostgreSQLDialect
|
5 |
spring.jpa.hibernate.ddl-auto=update
|
6 |
spring.jpa.hibernate.show-sql=true
|
7 |
|
|
|
8 |
spring.datasource.url=jdbc:postgresql://localhost:5432/spring-boot-render
|
9 |
spring.datasource.username=postgres
|
10 |
spring.datasource.password=azerty
|