Initial commit

This commit is contained in:
2025-11-04 14:25:40 +03:00
commit 80b7e8e22f
16 changed files with 364 additions and 0 deletions

35
.gitignore vendored Normal file
View File

@@ -0,0 +1,35 @@
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/
!**/src/test/**/target/
### IntelliJ IDEA ###
.idea
*.iws
*.iml
*.ipr
### Eclipse ###
.apt_generated
.classpath
.factorypath
.project
.settings
.springBeans
.sts4-cache
### NetBeans ###
/nbproject/private/
/nbbuild/
/dist/
/nbdist/
/.nb-gradle/
build/
!**/src/main/**/build/
!**/src/test/**/build/
### VS Code ###
.vscode/
### Mac OS ###
.DS_Store

Binary file not shown.

45
pom.xml Normal file
View File

@@ -0,0 +1,45 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>org.example</groupId>
<artifactId>NTO-2025-Individual-Task</artifactId>
<version>1.0-SNAPSHOT</version>
<properties>
<maven.compiler.source>17</maven.compiler.source>
<maven.compiler.target>17</maven.compiler.target>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.5.5</version>
</parent>
<dependencies>
<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.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
</dependency>
<dependency>
<groupId>org.example</groupId>
<artifactId>NTO-2025-Encoder</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>system</scope>
<systemPath>${project.basedir}/libs/NTO-2025-Encoder-1.0-SNAPSHOT-obf.jar</systemPath>
</dependency>
</dependencies>
</project>

View File

@@ -0,0 +1,9 @@
package ru.example.nto;
import org.springframework.boot.SpringApplication;
public class App {
public static void main(String[] args) {
SpringApplication.run(App.class, args);
}
}

View File

@@ -0,0 +1,35 @@
package ru.example.nto.controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import ru.example.nto.service.DepartmentService;
import ru.nto.security.Encoder;
import ru.nto.security.EncoderApi;
@RestController
@RequestMapping("code")
public class CodeController {
private final DepartmentService departmentService;
private final EncoderApi encoderApi = Encoder.create();
public CodeController(DepartmentService departmentService) {
this.departmentService = departmentService;
}
@GetMapping("/task1/{id}")
public int getTask1Code(@PathVariable long id) {
return encoderApi.encode(null, id);
}
@GetMapping("/task2/{id}")
public int getTask2Code(@PathVariable long id) {
return encoderApi.encode(departmentService.getAll(), id);
}
@GetMapping("/task3/{id}")
public int getTask3Code(@PathVariable long id) {
return encoderApi.encode(departmentService.getByName("Департамент аналитики"), id);
}
}

View File

@@ -0,0 +1,31 @@
package ru.example.nto.controller;
import org.springframework.http.HttpStatus;
import org.springframework.web.bind.annotation.*;
import ru.example.nto.entity.Department;
import ru.example.nto.service.DepartmentService;
import java.util.List;
@RestController
@RequestMapping("api/v1/department")
public class DepartmentController {
private final DepartmentService departmentService;
public DepartmentController(DepartmentService departmentService) {
this.departmentService = departmentService;
}
@GetMapping
@ResponseStatus(code = HttpStatus.OK)
public List<Department> getAll() {
return departmentService.getAll();
}
@GetMapping("/{name}")
@ResponseStatus(HttpStatus.OK)
public Department getByName(@PathVariable String name) {
return departmentService.getByName(name);
}
}

View File

@@ -0,0 +1,56 @@
package ru.example.nto.entity;
import java.util.Objects;
//TODO: Задание 2
// Добавьте все необходимые аннотации для класса-сущности Department.
public class Department {
private long id;
private String name;
public Department() {
}
public Department(long id, String name) {
this.id = id;
this.name = name;
}
public long getId() {
return id;
}
public String getName() {
return name;
}
public void setId(long id) {
this.id = id;
}
public void setName(String name) {
this.name = name;
}
@Override
public String toString() {
return "Department{" +
"id=" + id +
", name='" + name + '\'' +
'}';
}
@Override
public boolean equals(Object o) {
if (o == null || getClass() != o.getClass()) return false;
Department that = (Department) o;
return id == that.id && Objects.equals(name, that.name);
}
@Override
public int hashCode() {
return Objects.hash(id, name);
}
}

View File

@@ -0,0 +1,7 @@
package ru.example.nto.exception;
public class DepartmentNotFoundException extends RuntimeException {
public DepartmentNotFoundException(String msg) {
super(msg);
}
}

View File

@@ -0,0 +1,11 @@
package ru.example.nto.repository;
//TODO: Задание 2
// Опишите интерфейс DepartmentRepository,
// так чтобы он обеспечивал корректную работу со всеми CRUD-операциями сущности Department.
public interface DepartmentRepository {
//TODO: Задание 3
// Добавьте метод для получения из базы данных департамента по его наименованию.
}

View File

@@ -0,0 +1,11 @@
package ru.example.nto.service;
import ru.example.nto.entity.Department;
import java.util.List;
public interface DepartmentService {
List<Department> getAll();
Department getByName(String name);
}

View File

@@ -0,0 +1,37 @@
package ru.example.nto.service.impl;
import org.springframework.stereotype.Service;
import ru.example.nto.entity.Department;
import ru.example.nto.repository.DepartmentRepository;
import ru.example.nto.service.DepartmentService;
import java.util.List;
@Service
public class DepartmentServiceImpl implements DepartmentService {
private final DepartmentRepository departmentRepository;
//TODO: Задание 2
// Исправьте конструктор так, чтобы он корректно инициализировал поле departmentRepository.
public DepartmentServiceImpl() {
this.departmentRepository = null;
}
@Override
public List<Department> getAll() {
//TODO: Задание 2
// Реализуйте метод, который возвращает всех департаментов, которые есть в базе данных.
return null;
}
@Override
public Department getByName(String name) {
//TODO: Задание 3
// Реализуйте метод, который получает департамент по его наименованию
// и обрабатывает результат слоя repository.
// Если департамента с указанным наименованием в базе данных нет,
// то необходимо выбрасывать DepartmentNotFoundException
return null;
}
}

View File

@@ -0,0 +1,26 @@
spring:
datasource:
url: jdbc:h2:mem:testdb
h2:
console:
#enabled: false
enabled: true
jpa:
generate-ddl: false
#generate-ddl: true
hibernate:
ddl-auto: none
#ddl-auto: create-drop
# Показываем запросы
show-sql: true
liquibase:
enabled: true
change-log: classpath:db.changelog/db.changelog-master.xml
server:
port: 8083

View File

@@ -0,0 +1,31 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet id="2025-10-12--0001-department" author="anepretimov">
<preConditions onFail="MARK_RAN">
<not>
<tableExists tableName="department"/>
</not>
</preConditions>
<createTable tableName="department">
<column name="id"
type="NUMERIC(19,0)"
autoIncrement="true">
<constraints primaryKey="true" nullable="false"/>
</column>
<column name="name" type="VARCHAR(100)">
<constraints nullable="false" unique="true"/>
</column>
</createTable>
</changeSet>
</databaseChangeLog>

View File

@@ -0,0 +1,16 @@
<?xml version="1.0" encoding="UTF-8"?>
<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.0.xsd
http://www.liquibase.org/xml/ns/dbchangelog-ext http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-ext.xsd">
<changeSet id="2025-10-12--0001-department-data" author="anepretimov">
<loadData tableName="department" file="db.changelog/data/csv/2025-10-12--0001-department-data.csv"
separator=";"
quotchar='"'
encoding="UTF-8"/>
</changeSet>
</databaseChangeLog>

View File

@@ -0,0 +1,4 @@
id;name
1;Департамент по работе с персоналом
2;Департамент информационных технологий
3;Департамент аналитики
1 id name
2 1 Департамент по работе с персоналом
3 2 Департамент информационных технологий
4 3 Департамент аналитики

View File

@@ -0,0 +1,10 @@
<databaseChangeLog
xmlns="http://www.liquibase.org/xml/ns/dbchangelog"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.liquibase.org/xml/ns/dbchangelog
http://www.liquibase.org/xml/ns/dbchangelog/dbchangelog-3.8.xsd">
<include file="db.changelog/1.0/2025-10-12--0001-department.xml"/>
<include file="db.changelog/data/2025-10-12--0001-department-data.xml"/>
</databaseChangeLog>