added user file

This commit is contained in:
Ksan 2025-10-17 23:35:17 +02:00
parent 6319556102
commit 5fd15ed820
5 changed files with 67 additions and 35 deletions

3
.gitignore vendored
View File

@ -1,3 +1,6 @@
.db/
HELP.md
.gradle
build/

View File

@ -1,9 +1,12 @@
services:
postgres:
image: 'postgres:latest'
image: 'postgres:16'
container_name: etfo-db
environment:
- 'POSTGRES_DB=mydatabase'
- 'POSTGRES_PASSWORD=secret'
- 'POSTGRES_USER=user'
- 'POSTGRES_DB=etfo-db'
- 'POSTGRES_PASSWORD=test'
- 'POSTGRES_USER=test'
volumes:
- .db:/var/lib/postgresql/data
ports:
- '5432:5432'

View File

@ -1,45 +1,25 @@
package dev.ksan.etfoglasiserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
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
public class EtfoglasiServerApplication {
public static void main(String[] args) {
System.out.println("EtfoglasiServerApplication starting...");
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();
}
}
}

View 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;
}
}

View File

@ -1 +1,5 @@
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