Добавление базы данных

This commit is contained in:
Shilyaev_Dmitry 2025-02-19 10:43:04 +03:00
parent 09b8a191cc
commit ef69abccec
23 changed files with 287 additions and 58 deletions

38
pom.xml
View File

@ -5,7 +5,7 @@
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>NTO-2024</artifactId>
<artifactId>Android-Bootcamp-2025-Backend</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
@ -14,6 +14,9 @@
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<!-- Spring-boot-starter-parent - это специальный стартер, который обеспечивает значения по умолчанию Maven.
Он также предоставляет раздел dependency-management (управления зависимостями),
так что вы можете опустить теги version для общераспространенных зависимостей. -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
@ -22,36 +25,47 @@
<dependencies>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>com.h2database</groupId>
<artifactId>h2</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springdoc</groupId>
<artifactId>springdoc-openapi-ui</artifactId>
<version>1.7.0</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
<artifactId>spring-boot-starter-security</artifactId>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,5 @@
package com.example.nto.config;
public class WebSecurityConfig {
}

View File

@ -0,0 +1,10 @@
package com.example.nto.dto;
import lombok.Data;
@Data
public class EmployeeRegisterDTO {
private String login;
private String name;
private String password;
}

View File

@ -7,7 +7,6 @@ import javax.persistence.*;
@Data
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Getter
public class Code {

View File

@ -1,18 +1,14 @@
package com.example.nto.entity;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import javax.persistence.*;
import java.time.LocalDateTime;
@Data
@Entity
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Table(name="employee")
public class Employee {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@ -22,10 +18,12 @@ public class Employee {
private String login;
@Column(name = "name")
private String name;
@Column(name = "photo")
private String photo;
@Column(name="password")
private String password;
@Column(name = "photo_url")
private String photoUrl;
@Column(name = "position")
private String position;
@Column(name = "lastVisit")
@Column(name = "last_visit")
private LocalDateTime lastVisit;
}

View File

@ -4,7 +4,5 @@ import com.example.nto.entity.Code;
import com.example.nto.entity.Employee;
public interface EmployeeService {
String getAuth(String login);
Employee getInfo(String login);
String patchOpen(String login, long value);
}

View File

@ -41,7 +41,7 @@ public class EmployeeServiceImpl implements EmployeeService {
}
@Override
public String patchOpen(String login, long value) {
public String patchOpen(String login, long value) { // Сделать возвращение статуса, а не строчки
Employee employeeLogin=employeeRepository.findByLogin(login);
Code codeValue=codeRepository.findByValue(value);
if(employeeLogin==null) {

View File

@ -0,0 +1,17 @@
package com.example.nto.util;
import com.example.nto.dto.EmployeeRegisterDTO;
import com.example.nto.entity.Employee;
import lombok.experimental.UtilityClass;
@UtilityClass
public class EmployeeMapper {
public EmployeeRegisterDTO convertToRegisterDTO(Employee employee){
EmployeeRegisterDTO employeeRegisterDTO = new EmployeeRegisterDTO();
employeeRegisterDTO.setLogin(employee.getLogin());
employeeRegisterDTO.setPassword(employee.getPassword());
employeeRegisterDTO.setName(employee.getName());
return employeeRegisterDTO;
}
}

View File

@ -1,28 +1,17 @@
spring:
datasource:
datasourse:
url: jdbc:h2:mem:testdb
h2:
console:
#enabled: false
enabled: true
liquibase:
enabled: true
change-log: classpath:db.changelog/1.0/db.changelog-master.xml
jpa:
#generate-ddl: false
generate-ddl: true
generate-ddl: false
hibernate:
#ddl-auto: none
ddl-auto: create-drop
# Показываем запросы
ddl-auto: none
show-sql: true
# Своевременный запуск data.sql
defer-datasource-initialization: true
spring-doc:
swagger-ui:
path: /swagger-ui.html
operationsSorter: method

View File

@ -1,14 +0,0 @@
INSERT INTO employee (id, login, name, photo, position, last_visit)
VALUES
(1, 'pivanov', 'Иванов Петр Федорович', 'https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg', 'Разработчик', '2024-02-12T08:30'),
(2, 'ipetrov', 'Петров Иван Константинович', 'https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg', 'Аналитик', '2024-02-13T08:35'),
(3, 'asemenov', 'Семенов Анатолий Анатольевич', 'https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg', 'Разработчик', '2024-02-13T08:31'),
(4, 'afedorov', 'Федоров Александр Сергеевич', 'https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg', 'Тестировщик', '2024-02-12T08:36');
INSERT INTO code (value)
VALUES
(1234567890123456789),
(9223372036854775807),
(1122334455667788990),
(998877665544332211),
(5566778899001122334);

View File

@ -0,0 +1,35 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog-ext.xsd">
<changeSet id="2025-02-18-employee" author="dshilyaev">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="employee"/>
</not>
</preConditions>
<createTable tableName="employee">
<column name="id" type="BIGINT" autoIncrement="true" >
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="login" type="VARCHAR(50)">
<constraints nullable="false" unique="true"/>
</column>
<column name="name" type="VARCHAR(50)">
<constraints nullable="false"/>
</column>
<column name="password" type="VARCHAR(100)">
<constraints nullable="false"/>
</column>
<column name="position" type="VARCHAR(50)"/>
<column name="photo_url" type="VARCHAR(300)"/>
<column name="last_visit" type="DATETIME()"/>
</createTable>
</changeSet>
</databaseChangeLog>

View File

@ -0,0 +1,27 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog-ext.xsd">
<changeSet id="2025-02-18-0002-code" author="dshilyaev">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="code"/>
</not>
</preConditions>
<createTable tableName="code">
<column name="id" type="BIGINT" autoIncrement="true" >
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="value" type="BIGINT">
<constraints unique="true" nullable="false"/>
</column>
</createTable>
</changeSet>
</databaseChangeLog>

View File

@ -0,0 +1,26 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog-ext.xsd">
<changeSet id="2025-02-18-0003-authority" author="dshilyaev">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="authority"/>
</not>
</preConditions>
<createTable tableName="authority">
<column name="id" type="BIGINT" autoIncrement="true" >
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="authorities" type="VARCHAR(20)">
<constraints unique="true" nullable="false"/>
</column>
</createTable>
</changeSet>
</databaseChangeLog>

View File

@ -0,0 +1,28 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog-ext.xsd">
<changeSet id="2025-02-18-0004-employee-authority" author="dshilyaev">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="employee_authorities"/>
</not>
</preConditions>
<createTable tableName="employee_authorities">
<column name="id" type="BIGINT" autoIncrement="true" >
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="employee_id" type="BIGINT">
<constraints foreignKeyName="fk_authorities_employee" referencedTableName="employee" referencedColumnNames="id"/>
</column>
<column name="authority_id" type="BIGINT">
<constraints foreignKeyName="fk_authorities_authority" referencedTableName="authority" referencedColumnNames="id"/>
</column>
</createTable>
</changeSet>
</databaseChangeLog>

View File

@ -0,0 +1,14 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog-ext.xsd">
<changeSet id="2025-02-18-0001-employee.xml" author="dshilyaev">
<loadData tableName="employee" file="db.changelog/1.0/data/csv/2025-02-18-0001-employee-data.csv"
separator=";"
quotchar='*'
encoding="UTF-8"/>
</changeSet>
</databaseChangeLog>

View File

@ -0,0 +1,14 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog-ext.xsd">
<changeSet id="2025-02-18-0002-code.xml" author="dshilyaev">
<loadData tableName="code" file="db.changelog/1.0/data/csv/2025-02-18-0002-code-data.csv"
separator=";"
quotchar='*'
encoding="UTF-8"/>
</changeSet>
</databaseChangeLog>

View File

@ -0,0 +1,14 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog-ext.xsd">
<changeSet id="2025-02-18-0003-authority.xml" author="dshilyaev">
<loadData tableName="authority" file="db.changelog/1.0/data/csv/2025-02-18-0003-authority-data.csv"
separator=";"
quotchar='*'
encoding="UTF-8"/>
</changeSet>
</databaseChangeLog>

View File

@ -0,0 +1,14 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog-ext.xsd">
<changeSet id="2025-02-18-0004-employee_authority.xml" author="dshilyaev">
<loadData tableName="employee_authorities" file="db.changelog/1.0/data/csv/2025-02-18-0004-employee-authority-data.csv"
separator=";"
quotchar='*'
encoding="UTF-8"/>
</changeSet>
</databaseChangeLog>

View File

@ -0,0 +1,8 @@
login;name;password;position;photo_url;last_visit
pivanov;Иванов Петр Федорович;abcd;Разработчик;https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg;2024-02-12T08:30:21
ipetrov;Петров Иван Константинович;abcd;Аналитик;https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg;2024-02-13T08:35:44
asemenov;Семенов Анатолий Анатольевич;abcd;Разработчик;https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg;2024-02-13T08:31:33
afedorov;Федоров Александр Сергеевич;abcd;Тестировщик;https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg;2024-02-12T08:36:09
1 login name password position photo_url last_visit
2 pivanov Иванов Петр Федорович abcd Разработчик https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg 2024-02-12T08:30:21
3 ipetrov Петров Иван Константинович abcd Аналитик https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg 2024-02-13T08:35:44
4 asemenov Семенов Анатолий Анатольевич abcd Разработчик https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg 2024-02-13T08:31:33
5 afedorov Федоров Александр Сергеевич abcd Тестировщик https://funnyducks.ru/upload/iblock/0cd/0cdeb7ec3ed6fddda0f90fccee05557d.jpg 2024-02-12T08:36:09

View File

@ -0,0 +1,8 @@
value
1234567890123456789
9223372036854775807
1122334455667788990
998877665544332211
5566778899001122334
1 value
2 1234567890123456789
3 9223372036854775807
4 1122334455667788990
5 998877665544332211
6 5566778899001122334

View File

@ -0,0 +1,3 @@
authorities
ROLE_USER
ROLE_ADMIN
1 authorities
2 ROLE_USER
3 ROLE_ADMIN

View File

@ -0,0 +1,5 @@
employee_id;authority_id
1;1
2;1
3;1
4;1
1 employee_id authority_id
2 1 1
3 2 1
4 3 1
5 4 1

View File

@ -0,0 +1,17 @@
<databaseChangeLog xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:ext="http://www.liquibase.org/xml/ns/dbchangelog-ext"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog-ext.xsd">
<include file="db.changelog/1.0/1.0/2025-02-18-0001-employee.xml"/>
<include file="db.changelog/1.0/1.0/2025-02-18-0002-code.xml"/>
<include file="db.changelog/1.0/1.0/2025-02-18-0003-authority.xml"/>
<include file="db.changelog/1.0/1.0/2025-02-18-0004-employee-authority.xml"/>
<include file="db.changelog/1.0/data/2025-02-18-0001-employee-data.xml"/>
<include file="db.changelog/1.0/data/2025-02-18-0002-code-data.xml"/>
<include file="db.changelog/1.0/data/2025-02-18-0003-authority-data.xml"/>
<include file="db.changelog/1.0/data/2025-02-18-0004-employee-authority-data.xml"/>
</databaseChangeLog>