added user file
This commit is contained in:
parent
6319556102
commit
5fd15ed820
3
.gitignore
vendored
3
.gitignore
vendored
@ -1,3 +1,6 @@
|
|||||||
|
.db/
|
||||||
|
|
||||||
|
|
||||||
HELP.md
|
HELP.md
|
||||||
.gradle
|
.gradle
|
||||||
build/
|
build/
|
||||||
|
|||||||
11
compose.yaml
11
compose.yaml
@ -1,9 +1,12 @@
|
|||||||
services:
|
services:
|
||||||
postgres:
|
postgres:
|
||||||
image: 'postgres:latest'
|
image: 'postgres:16'
|
||||||
|
container_name: etfo-db
|
||||||
environment:
|
environment:
|
||||||
- 'POSTGRES_DB=mydatabase'
|
- 'POSTGRES_DB=etfo-db'
|
||||||
- 'POSTGRES_PASSWORD=secret'
|
- 'POSTGRES_PASSWORD=test'
|
||||||
- 'POSTGRES_USER=user'
|
- 'POSTGRES_USER=test'
|
||||||
|
volumes:
|
||||||
|
- .db:/var/lib/postgresql/data
|
||||||
ports:
|
ports:
|
||||||
- '5432:5432'
|
- '5432:5432'
|
||||||
|
|||||||
@ -1,45 +1,25 @@
|
|||||||
package dev.ksan.etfoglasiserver;
|
package dev.ksan.etfoglasiserver;
|
||||||
|
|
||||||
import org.springframework.boot.SpringApplication;
|
|
||||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
||||||
|
|
||||||
import java.sql.Connection;
|
import java.sql.Connection;
|
||||||
import java.sql.DriverManager;
|
import java.sql.DriverManager;
|
||||||
import java.sql.PreparedStatement;
|
import java.sql.PreparedStatement;
|
||||||
import java.sql.SQLException;
|
import java.sql.SQLException;
|
||||||
|
import java.time.LocalDate;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
import org.springframework.boot.CommandLineRunner;
|
||||||
|
import org.springframework.boot.SpringApplication;
|
||||||
|
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||||
|
import org.springframework.context.annotation.Bean;
|
||||||
|
import org.springframework.jdbc.core.JdbcTemplate;
|
||||||
|
|
||||||
@SpringBootApplication
|
@SpringBootApplication
|
||||||
public class EtfoglasiServerApplication {
|
public class EtfoglasiServerApplication {
|
||||||
|
|
||||||
public static void main(String[] args) {
|
public static void main(String[] args) {
|
||||||
System.out.println("EtfoglasiServerApplication starting...");
|
SpringApplication.run(EtfoglasiServerApplication.class, args);
|
||||||
SpringApplication.run(EtfoglasiServerApplication.class, args);
|
|
||||||
|
|
||||||
|
|
||||||
String url = "jdbc:postgresql://localhost:5432/mydatabase"; // Update with your database info
|
}
|
||||||
String user = "user"; // Your PostgreSQL username
|
|
||||||
String password = "secret"; // Your PostgreSQL password
|
|
||||||
|
|
||||||
// SQL INSERT query
|
|
||||||
String sql = "INSERT INTO employees (id, name, position) VALUES (?, ?, ?)";
|
|
||||||
|
|
||||||
// Try-with-resources to ensure automatic resource management
|
|
||||||
try (Connection conn = DriverManager.getConnection(url, user, password);
|
|
||||||
PreparedStatement stmt = conn.prepareStatement(sql)) {
|
|
||||||
|
|
||||||
// Set parameters for the INSERT statement
|
|
||||||
stmt.setInt(1, 3); // id
|
|
||||||
stmt.setString(2, "Jane Doe"); // name
|
|
||||||
stmt.setString(3, "Who knows"); // position
|
|
||||||
|
|
||||||
// Execute the insert
|
|
||||||
int rowsAffected = stmt.executeUpdate();
|
|
||||||
|
|
||||||
System.out.println(rowsAffected + " row(s) inserted.");
|
|
||||||
|
|
||||||
} catch (SQLException e) {
|
|
||||||
e.printStackTrace();
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|||||||
42
src/main/java/dev/ksan/etfoglasiserver/model/User.java
Normal file
42
src/main/java/dev/ksan/etfoglasiserver/model/User.java
Normal file
@ -0,0 +1,42 @@
|
|||||||
|
package dev.ksan.etfoglasiserver.model;
|
||||||
|
|
||||||
|
import jakarta.persistence.Column;
|
||||||
|
import jakarta.persistence.Entity;
|
||||||
|
import jakarta.persistence.GeneratedValue;
|
||||||
|
import jakarta.persistence.GenerationType;
|
||||||
|
import jakarta.persistence.Id;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
public class User {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.AUTO)
|
||||||
|
private UUID id;
|
||||||
|
|
||||||
|
@Column(nullable = false, unique = true)
|
||||||
|
private String email;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String password;
|
||||||
|
|
||||||
|
public UUID getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getEmail() {
|
||||||
|
return email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setEmail(String email) {
|
||||||
|
this.email = email;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getPassword() {
|
||||||
|
return password;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setPassword(String password) {
|
||||||
|
this.password = password;
|
||||||
|
}
|
||||||
|
}
|
||||||
@ -1 +1,5 @@
|
|||||||
spring.application.name=etfoglasi-server
|
spring.application.name=etfoglasi-server
|
||||||
|
spring.datasource.url=jdbc:postgresql://localhost:5432/etfo-db
|
||||||
|
spring.datasource.username=test
|
||||||
|
spring.datasource.password=test
|
||||||
|
spring.jpa.show-sql=true
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user