Skip to content
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

add flyway migration-v1; add hibernate mapping #11

Open
wants to merge 1 commit into
base: main
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
34 changes: 19 additions & 15 deletions backend_module/Docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,27 +1,31 @@
version: '3.5'
networks:
lan:
driver: bridge
services:
mysql:
docker-mysql:
image: mysql:8
command: --default-authentication-plugin=mysql_native_password
restart: always
hostname: localhost
ports:
- 5432:5432
- '3308:3306'
volumes:
- mysql-data:/var/lib/mysql
environment:
MYSQL_ROOT_PASSWORD: rootpass
MYSQL_USER: testuser
MYSQL_PASSWORD: testpass
MYSQL_DB: teste
server:
MYSQL_ROOT_PASSWORD: password
MYSQL_DATABASE: test_db
MYSQL_USER: root
MYSQL_PASSWORD: password
networks:
- lan
docker-server:
image: spring-mysql
build:
context: ./
dockerfile: Dockerfile
networks:
- lan
depends_on:
- mysql
- docker-mysql
ports:
- 8080:8080
environment:
- DATABASE_HOST=localhost
- DATABASE_USER=testuser
- DATABASE_NAME=teste
- DATABASE_PORT=5432
- '8091:8091'
19 changes: 16 additions & 3 deletions backend_module/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,18 +21,31 @@
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>

<dependency>
<groupId>mysql</groupId>
<artifactId>mysql-connector-java</artifactId>
<scope>runtime</scope>
</dependency>

<dependency>
<groupId>org.flywaydb</groupId>
<artifactId>flyway-core</artifactId>
<version>5.2.4</version>
</dependency>

<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
package com.natlex.backend_module.model;

import javax.persistence.*;
import java.util.Date;

@Entity
@Table (name = "DatePoint")
public class DatePoint {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(nullable = false)
private Long id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

can you create parent class for id


private String description;
private String photo;
private Date date;
private String links;
private Long point_id;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@OnetoOne and fetch - lazy


public DatePoint(Long id, String description, String photo, Date date, String links, Long point_id) {
this.id = id;
this.description = description;
this.photo = photo;
this.date = date;
this.links = links;
this.point_id = point_id;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getDescription() {
return description;
}

public void setDescription(String description) {
this.description = description;
}

public String getPhoto() {
return photo;
}

public void setPhoto(String photo) {
this.photo = photo;
}

public Date getDate() {
return date;
}

public void setDate(Date date) {
this.date = date;
}

public String getLinks() {
return links;
}

public void setLinks(String links) {
this.links = links;
}

public Long getPoint_id() {
return point_id;
}

public void setPoint_id(Long point_id) {
this.point_id = point_id;
}

public DatePoint() {
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.natlex.backend_module.model;

import javax.persistence.*;

@Entity

@Table (name = "Point")
public class Point {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(nullable = false)
private Long id;

@Column(name = "coordinates", nullable = false)
private org.springframework.data.geo.Point coordinates;

private int count;
private String adress;

public Point() {
}

public Point(Long id, org.springframework.data.geo.Point coordinates, int count, String adress) {
this.id = id;
this.coordinates = coordinates;
this.count = count;
this.adress = adress;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public org.springframework.data.geo.Point getCoordinates() {
return coordinates;
}

public void setCoordinates(org.springframework.data.geo.Point coordinates) {
this.coordinates = coordinates;
}

public int getCount() {
return count;
}

public void setCount(int count) {
this.count = count;
}

public String getAdress() {
return adress;
}

public void setAdress(String adress) {
this.adress = adress;
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,59 @@
package com.natlex.backend_module.model;

import javax.persistence.*;

@Entity
@Table (name = "User")
public class User {

@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(nullable = false)
private Long id;

private String email;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

email validation, you can check already exist validator

private boolean inAdmin;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is

private String authData;

public User() {
}

public User(Long id, String email, boolean inAdmin, String authData) {
this.id = id;
this.email = email;
this.inAdmin = inAdmin;
this.authData = authData;
}

public Long getId() {
return id;
}

public void setId(Long id) {
this.id = id;
}

public String getEmail() {
return email;
}

public void setEmail(String email) {
this.email = email;
}

public boolean isInAdmin() {
return inAdmin;
}

public void setInAdmin(boolean inAdmin) {
this.inAdmin = inAdmin;
}

public String getAuthData() {
return authData;
}

public void setAuthData(String authData) {
this.authData = authData;
}
}
5 changes: 5 additions & 0 deletions backend_module/src/main/resources/application.properties
Original file line number Diff line number Diff line change
@@ -1 +1,6 @@
#spring.datasource.url=jdbc:mysql://docker-mysql:3308/test_db?createDatabaseIfNotExist=true&autoReconnect=true&useSSL=false
spring.datasource.username=root
spring.datasource.password=password
spring.datasource.driver-class-name=com.mysql.cj.jdbc.Driver

spring.datasource.url=jdbc:mysql://127.0.0.1:3306/test_db?serverTimezone=Europe/Moscow&autoReconnect=true&useSSL=false
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
CREATE TABLE Point (id INT AUTO_INCREMENT NOT NULL,
coordinates POINT NOT NULL,
count INT,
adress VARCHAR(200),
PRIMARY KEY(id));

CREATE TABLE DatePoint (id INT AUTO_INCREMENT NOT NULL,
description VARCHAR(300),
photo VARCHAR(300),
date DATE,
links VARCHAR(200),
point_id INT,
PRIMARY KEY (id),
FOREIGN KEY (point_id) REFERENCES Point(id));

CREATE TABLE User (id INT AUTO_INCREMENT NOT NULL,
email VARCHAR(200),
inAdmin BOOL,
authData VARCHAR(300),
PRIMARY KEY (id));