Compare commits

..

2 Commits

Author SHA1 Message Date
e2ea7ba71a Обновить README.md 2024-12-26 00:26:23 +04:00
e8afd0c4be Обновить README.md 2024-12-26 00:25:28 +04:00
64 changed files with 27 additions and 3616 deletions

3
.idea/.gitignore vendored
View File

@ -1,3 +0,0 @@
# Default ignored files
/shelf/
/workspace.xml

View File

@ -1,9 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<module type="JAVA_MODULE" version="4">
<component name="NewModuleRootManager" inherit-compiler-output="true">
<exclude-output />
<content url="file://$MODULE_DIR$" />
<orderEntry type="inheritedJdk" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" languageLevel="JDK_19" default="true" project-jdk-name="19" project-jdk-type="JavaSDK">
<output url="file://$PROJECT_DIR$/out" />
</component>
</project>

View File

@ -1,8 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/PutBit.iml" filepath="$PROJECT_DIR$/.idea/PutBit.iml" />
</modules>
</component>
</project>

View File

@ -1,6 +0,0 @@
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="" vcs="Git" />
</component>
</project>

View File

@ -1,2 +1,12 @@
# PutBit
# Разработка веб-сервиса для приема абитуриентов в вуз
Данное приложение представляет из себя веб-сервис, который позволит упростить, ускорить и автоматизировать процесс подачи заявления абитуриетов в вуз
## Что из себя представляет ?
Сайт, через который абитуриенты смогут заполнить о себе информацию и подать заявление на поступление
## Пример
Примером можно рассматривать данную [систему](https://ulstu.ru/)

1
app/.gitignore vendored
View File

@ -1,5 +1,4 @@
HELP.md
data.mv.db
target/
!.mvn/wrapper/maven-wrapper.jar
!**/src/main/**/target/

View File

@ -1,19 +0,0 @@
# Licensed to the Apache Software Foundation (ASF) under one
# or more contributor license agreements. See the NOTICE file
# distributed with this work for additional information
# regarding copyright ownership. The ASF licenses this file
# to you under the Apache License, Version 2.0 (the
# "License"); you may not use this file except in compliance
# with the License. You may obtain a copy of the License at
#
# http://www.apache.org/licenses/LICENSE-2.0
#
# Unless required by applicable law or agreed to in writing,
# software distributed under the License is distributed on an
# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
# KIND, either express or implied. See the License for the
# specific language governing permissions and limitations
# under the License.
wrapperVersion=3.3.2
distributionType=only-script
distributionUrl=https://repo.maven.apache.org/maven2/org/apache/maven/apache-maven/3.9.9/apache-maven-3.9.9-bin.zip

View File

@ -30,13 +30,6 @@
<java.version>17</java.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
<version>3.2.4</version>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
@ -61,17 +54,22 @@
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.angus</groupId>
<artifactId>angus-mail</artifactId>
<version>2.0.1</version>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<annotationProcessorPaths>
<path>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
</path>
</annotationProcessorPaths>
</configuration>
</plugin>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
@ -86,4 +84,5 @@
</plugin>
</plugins>
</build>
</project>

View File

@ -1,15 +1,11 @@
package putBit.app;
import lombok.AllArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import putBit.app.Timer.myTimer;
import putBit.app.services.OrderService;
@SpringBootApplication
public class AppApplication {
public static void main(String[] args) {
SpringApplication.run(AppApplication.class, args);
}

View File

@ -1,35 +0,0 @@
package putBit.app.Timer;
import jakarta.mail.MessagingException;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.ComponentScan;
import putBit.app.models.Order;
import putBit.app.services.OrderService;
import java.util.TimerTask;
@Data
@AllArgsConstructor
@ComponentScan
public class Task extends TimerTask {
@Autowired
private OrderService orderService;
@Override
public void run() {
try {
System.out.println("START");
orderService.workWithStudents();
} catch (MessagingException e) {
throw new RuntimeException(e);
}
}
}

View File

@ -1,47 +0,0 @@
package putBit.app.Timer;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.aspectj.weaver.ast.Or;
import org.springframework.beans.factory.annotation.Autowired;
import putBit.app.services.OrderService;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneId;
import java.util.Date;
import java.util.Timer;
@Data
public final class myTimer {
private static myTimer INSTANCE;
private boolean closed = false;
private LocalDateTime date = LocalDateTime.of(2024, Month.DECEMBER,11, 0,0,0);
private OrderService orderService;
private myTimer(OrderService orderService) {
this.orderService = orderService;
System.out.println("create timer");
LocalDateTime later = LocalDateTime.now().plusDays(10);
Date LaterAsDate = Date.from(later.atZone(ZoneId.systemDefault()).toInstant());
new Timer().schedule(new Task(orderService), LaterAsDate);
}
public static myTimer getInstance(OrderService orderService) {
if(INSTANCE == null) {
INSTANCE = new myTimer(orderService);
}
return INSTANCE;
}
public static myTimer getInstance() {
return INSTANCE;
}
}

View File

@ -1,20 +0,0 @@
package putBit.app;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.ComponentScan;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.CorsRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;
import putBit.app.Timer.Task;
import putBit.app.Timer.myTimer;
import putBit.app.services.OrderService;
@Configuration
@ComponentScan("putBit.app.services")
class WebConfiguration implements WebMvcConfigurer {
@Override
public void addCorsMappings(CorsRegistry registry) {
registry.addMapping("/**").allowedMethods("*");
}
}

View File

@ -1,167 +0,0 @@
package putBit.app.controllers;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import putBit.app.controllers.Dto.AchievementDto;
import putBit.app.controllers.Dto.ExamDto;
import putBit.app.services.AchievementService;
import putBit.app.services.exceptions.ValidationException;
import java.util.List;
@AllArgsConstructor
@CrossOrigin(origins = "http://localhost:8081")
@RestController
@RequestMapping("/api/achievement")
public class AchievementsController {
private final AchievementService achievementService;
@PostMapping("/")
public ResponseEntity<AchievementDto> create(@RequestBody AchievementDto examDto) {
try
{
return new ResponseEntity<>
(new AchievementDto(achievementService.create(examDto)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@PutMapping("/")
public ResponseEntity<AchievementDto> update(@RequestBody AchievementDto examDto) {
try
{
return new ResponseEntity<>
(new AchievementDto(achievementService.update(examDto)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@DeleteMapping("/{id}")
public ResponseEntity<AchievementDto> delete(@PathVariable int id) {
try
{
return new ResponseEntity<>
(new AchievementDto(achievementService.delete(id)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/")
public ResponseEntity<List<AchievementDto>> getAll() {
try
{
return new ResponseEntity<>
(achievementService.findAll().stream().map(AchievementDto::new).toList(), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/{id}")
public ResponseEntity<AchievementDto> getById(@PathVariable int id) {
try
{
return new ResponseEntity<>
(new AchievementDto(achievementService.findById(id)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/forUser/{id}")
public ResponseEntity<List<AchievementDto>> getForUser(@PathVariable int id) {
try
{
return new ResponseEntity<>
(achievementService.findByUser(id).stream().map(AchievementDto::new).toList(), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/forUserNot/{id}")
public ResponseEntity<List<AchievementDto>> getForUserNot(@PathVariable int id) {
try
{
return new ResponseEntity<>
(achievementService.findByUserNot(id).stream().map(AchievementDto::new).toList(), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -1,129 +0,0 @@
package putBit.app.controllers;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import putBit.app.controllers.Dto.AchievementDto;
import putBit.app.controllers.Dto.BenefitDto;
import putBit.app.services.BenefitService;
import putBit.app.services.exceptions.ValidationException;
import java.util.List;
@AllArgsConstructor
@CrossOrigin(origins = "http://localhost:8081")
@RestController
@RequestMapping("/api/benefit")
public class BenefitController {
private final BenefitService benefitService;
@PostMapping("/")
public ResponseEntity<BenefitDto> create(@RequestBody BenefitDto examDto) {
try {
return new ResponseEntity<>
(new BenefitDto(benefitService.create(examDto)), HttpStatus.OK);
} catch (ValidationException ex) {
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
} catch (Exception ex) {
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@PutMapping("/")
public ResponseEntity<BenefitDto> update(@RequestBody BenefitDto examDto) {
try {
return new ResponseEntity<>
(new BenefitDto(benefitService.update(examDto)), HttpStatus.OK);
} catch (ValidationException ex) {
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
} catch (Exception ex) {
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@DeleteMapping("/{id}")
public ResponseEntity<BenefitDto> delete(@PathVariable int id) {
try {
return new ResponseEntity<>
(new BenefitDto(benefitService.delete(id)), HttpStatus.OK);
} catch (ValidationException ex) {
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
} catch (Exception ex) {
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/")
public ResponseEntity<List<BenefitDto>> getAll() {
try {
return new ResponseEntity<>
(benefitService.findAll().stream().map(BenefitDto::new).toList(), HttpStatus.OK);
} catch (ValidationException ex) {
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
} catch (Exception ex) {
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/{id}")
public ResponseEntity<BenefitDto> getById(@PathVariable int id) {
try {
return new ResponseEntity<>
(new BenefitDto(benefitService.findById(id)), HttpStatus.OK);
} catch (ValidationException ex) {
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
} catch (Exception ex) {
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/forUser/{id}")
public ResponseEntity<List<BenefitDto>> getForUser(@PathVariable int id) {
try {
return new ResponseEntity<>
(benefitService.findByUser(id).stream().map(BenefitDto::new).toList(), HttpStatus.OK);
} catch (ValidationException ex) {
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
} catch (Exception ex) {
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/forUserNot/{id}")
public ResponseEntity<List<BenefitDto>> getForUserNot(@PathVariable int id) {
try {
return new ResponseEntity<>
(benefitService.findByUserNot(id).stream().map(BenefitDto::new).toList(), HttpStatus.OK);
} catch (ValidationException ex) {
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
} catch (Exception ex) {
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -1,41 +0,0 @@
package putBit.app.controllers;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import putBit.app.Timer.myTimer;
import putBit.app.controllers.Dto.UserDto;
import putBit.app.services.exceptions.ValidationException;
import java.time.LocalDateTime;
import java.time.ZoneId;
import java.time.ZoneOffset;
import java.time.ZonedDateTime;
import java.util.Date;
@AllArgsConstructor
@CrossOrigin(origins = "http://localhost:8081")
@RestController
@RequestMapping("/api/date_close")
public class DateController {
@PostMapping("/")
public ResponseEntity<Long> createUser() {
try
{
LocalDateTime date = myTimer.getInstance().getDate();
ZonedDateTime zdt = ZonedDateTime.of(date, ZoneId.systemDefault());
return new ResponseEntity<Long>(zdt.toInstant().toEpochMilli(), HttpStatus.OK);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -1,26 +0,0 @@
package putBit.app.controllers.Dto;
import lombok.*;
import putBit.app.models.Achievement;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class AchievementDto {
private int id;
@NonNull
private String title ;
private int points;
public AchievementDto(Achievement achievement){
this.id = achievement.getId();
this.title = achievement.getTitle();
this.points = achievement.getPoints();
}
}

View File

@ -1,26 +0,0 @@
package putBit.app.controllers.Dto;
import lombok.*;
import putBit.app.models.Achievement;
import putBit.app.models.Benefit;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class BenefitDto {
private int id;
@NonNull
private String title ;
public BenefitDto(Benefit benefit){
this.id = benefit.getId();
this.title = benefit.getTitle();
}
}

View File

@ -1,28 +0,0 @@
package putBit.app.controllers.Dto;
import jakarta.persistence.Column;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import lombok.*;
import putBit.app.models.Exam;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ExamDto {
private int id;
@NonNull
private String title ;
public ExamDto(Exam exam){
this.id = exam.getId();
this.title = exam.getTitle();
}
}

View File

@ -1,39 +0,0 @@
package putBit.app.controllers.Dto;
import jakarta.persistence.Column;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import putBit.app.models.Exam;
import putBit.app.models.ExamResult;
import putBit.app.models.User;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ExamResultDto {
private int user ;
private int exam ;
private String title;
private int points ;
public ExamResultDto(ExamResult examResult){
this.user = examResult.getUser().getId();
this.exam = examResult.getExam().getId();
this.title = examResult.getExam().getTitle();
this.points = examResult.getPoints();
}
}

View File

@ -1,58 +0,0 @@
package putBit.app.controllers.Dto;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import putBit.app.models.Benefit;
import putBit.app.models.Order;
import putBit.app.models.Training;
import putBit.app.models.User;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OrderDto {
private int user;
private int training;
private String name = null;
private String snils = null;
private int points = 0;
private Boolean confirm ;
private Boolean benefit ;
public OrderDto(Order order){
this.user = order.getUser().getId();
this.training = order.getTraining().getId();
this.name = order.getUser().getName();
this.snils = order.getUser().getSnils();
int sum = 0;
for(var exam: order.getUser().getExams())
{
for(var examT: order.getTraining().getExams())
{
if(examT.getExam().getId() == exam.getExam().getId())
sum+= exam.getPoints();
}
}
for(var ach : order.getUser().getAchievements())
{
sum+= ach.getPoints();
}
this.points = sum;
this.confirm = order.getConfirm();
this.benefit = order.getBenefit();
}
}

View File

@ -1,53 +0,0 @@
package putBit.app.controllers.Dto;
import jakarta.persistence.Column;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import putBit.app.models.Training;
import java.util.ArrayList;
import java.util.List;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TrainingDto {
private int id;
private String num ;
private String title ;
private String desc ;
private String prof ;
private List<String> exams = new ArrayList<>();
private int basic_places ;
private int benefit_places ;
public TrainingDto(Training training){
this.id = training.getId();
this.title = training.getTitle();
this.num = training.getNum();
this.desc = training.getDesc();
for(var exam: training.getExams())
{
this.exams.add(exam.getExam().getTitle() + " (" + exam.getPoints() + "б.)");
}
this.prof = training.getProf();
this.basic_places = training.getBasic_places();
this.benefit_places = training.getBenefit_places();
}
}

View File

@ -1,31 +0,0 @@
package putBit.app.controllers.Dto;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import putBit.app.models.TrainingExam;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TrainingExamDto {
private int training ;
private int exam ;
private String title;
private int points ;
public TrainingExamDto(TrainingExam trainingExam){
this.training = trainingExam.getTraining().getId();
this.exam = trainingExam.getExam().getId();
this.title = trainingExam.getExam().getTitle();
this.points = trainingExam.getPoints();
}
}

View File

@ -1,44 +0,0 @@
package putBit.app.controllers.Dto;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import putBit.app.models.User;
import putBit.app.models.enums.Role;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class UserDto {
private int id;
private String role = null;
private String email = null;
private String password = null;
private String AgainPassword = null;
private String phone = null;
private String name = null;
private String snils = null;
public UserDto(User user){
this.id = user.getId();
this.role = user.getRole().name();
this.email = user.getEmail();
this.password = user.getPassword();
this.phone = user.getPhone();
this.name = user.getName();
this.snils = user.getSnils();
}
}

View File

@ -1,165 +0,0 @@
package putBit.app.controllers;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import putBit.app.controllers.Dto.ExamDto;
import putBit.app.controllers.Dto.UserDto;
import putBit.app.services.ExamService;
import putBit.app.services.exceptions.ValidationException;
import java.util.List;
@AllArgsConstructor
@CrossOrigin(origins = "http://localhost:8081")
@RestController
@RequestMapping("/api/exam")
public class ExamController {
private final ExamService examService;
@PostMapping("/")
public ResponseEntity<ExamDto> create(@RequestBody ExamDto examDto) {
try
{
return new ResponseEntity<>
(new ExamDto(examService.create(examDto)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@PutMapping("/")
public ResponseEntity<ExamDto> update(@RequestBody ExamDto examDto) {
try
{
return new ResponseEntity<>
(new ExamDto(examService.update(examDto)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@DeleteMapping("/{id}")
public ResponseEntity<ExamDto> delete(@PathVariable int id) {
try
{
return new ResponseEntity<>
(new ExamDto(examService.delete(id)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/")
public ResponseEntity<List<ExamDto>> getAll() {
try
{
return new ResponseEntity<>
(examService.findAll().stream().map(ExamDto::new).toList(), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/{id}")
public ResponseEntity<ExamDto> getById(@PathVariable int id) {
try
{
return new ResponseEntity<>
(new ExamDto(examService.findById(id)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/forTraining/{id}")
public ResponseEntity<List<ExamDto>> getForTraining(@PathVariable int id) {
try
{
return new ResponseEntity<>
(examService.findNotTraining(id).stream().map(ExamDto::new).toList(), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/forUser/{id}")
public ResponseEntity<List<ExamDto>> getForUser(@PathVariable int id) {
try
{
return new ResponseEntity<>
(examService.findNotUser(id).stream().map(ExamDto::new).toList(), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -1,125 +0,0 @@
package putBit.app.controllers;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import putBit.app.controllers.Dto.ExamDto;
import putBit.app.controllers.Dto.ExamResultDto;
import putBit.app.models.ExamResult;
import putBit.app.services.ExamResultService;
import putBit.app.services.exceptions.ValidationException;
import java.util.List;
@AllArgsConstructor
@CrossOrigin(origins = "http://localhost:8081")
@RestController
@RequestMapping("/api/exam_result")
public class ExamResultController {
private final ExamResultService examResultService;
@PostMapping("/")
public ResponseEntity<ExamResultDto> create(@RequestBody ExamResultDto examDto) {
try
{
return new ResponseEntity<>
(new ExamResultDto(examResultService.create(examDto)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@PutMapping("/")
public ResponseEntity<ExamResultDto> update(@RequestBody ExamResultDto examDto) {
try
{
return new ResponseEntity<>
(new ExamResultDto(examResultService.update(examDto)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@DeleteMapping("/{userId}/{examId}")
public ResponseEntity<ExamResultDto> delete(@PathVariable int userId, @PathVariable int examId) {
try
{
return new ResponseEntity<>
(new ExamResultDto(examResultService.delete(userId,examId)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/{userId}/{examId}")
public ResponseEntity<ExamResultDto> getById(@PathVariable int userId, @PathVariable int examId) {
try
{
return new ResponseEntity<>
(new ExamResultDto(examResultService.findById(userId, examId)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/forUser/{id}")
public ResponseEntity<List<ExamResultDto>> getForUser(@PathVariable int id) {
try
{
return new ResponseEntity<>
(examResultService.findByUser(id).stream().map(ExamResultDto::new).toList(), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -1,141 +0,0 @@
package putBit.app.controllers;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import putBit.app.controllers.Dto.ExamDto;
import putBit.app.controllers.Dto.OrderDto;
import putBit.app.services.OrderService;
import putBit.app.services.exceptions.ValidationException;
import java.util.List;
@AllArgsConstructor
@CrossOrigin(origins = "http://localhost:8081")
@RestController
@RequestMapping("/api/order")
public class OrderController {
private final OrderService orderService;
@PostMapping("/")
public ResponseEntity<OrderDto> create(@RequestBody OrderDto examDto) {
try
{
return new ResponseEntity<>
(new OrderDto(orderService.create(examDto)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@DeleteMapping("/{userId}/{trainingId}")
public ResponseEntity<OrderDto> delete(@PathVariable int userId, @PathVariable int trainingId) {
try
{
return new ResponseEntity<>
(new OrderDto(orderService.delete(userId, trainingId)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/benefit/{id}")
public ResponseEntity<List<OrderDto>> getBenefit(@PathVariable int id) {
try
{
return new ResponseEntity<>
(orderService.findForBenefit(id).stream().map(OrderDto::new).toList(), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/basic/{id}")
public ResponseEntity<List<OrderDto>> getBasic(@PathVariable int id) {
try
{
return new ResponseEntity<>
(orderService.findForBasic(id).stream().map(OrderDto::new).toList(), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/search/{id}/{value}")
public ResponseEntity<List<OrderDto>> getSearch(@PathVariable int id,@PathVariable String value) {
try
{
return new ResponseEntity<>
(orderService.findByNameOrSnils(id,value).stream().map(OrderDto::new).toList(), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/forUser/{id}")
public ResponseEntity<OrderDto> getByUser(@PathVariable int id) {
try
{
return new ResponseEntity<>
(new OrderDto(orderService.findByUser(id)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -1,126 +0,0 @@
package putBit.app.controllers;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import putBit.app.controllers.Dto.ExamDto;
import putBit.app.controllers.Dto.TrainingDto;
import putBit.app.services.TrainingService;
import putBit.app.services.exceptions.ValidationException;
import java.util.List;
@AllArgsConstructor
@CrossOrigin(origins = "http://localhost:8081")
@RestController
@RequestMapping("/api/training")
public class TrainingController {
private final TrainingService trainingService;
@PostMapping("/")
public ResponseEntity<TrainingDto> create(@RequestBody TrainingDto examDto) {
try
{
return new ResponseEntity<>
(new TrainingDto(trainingService.create(examDto)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@PutMapping("/")
public ResponseEntity<TrainingDto> update(@RequestBody TrainingDto examDto) {
try
{
return new ResponseEntity<>
(new TrainingDto(trainingService.update(examDto)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@DeleteMapping("/{id}")
public ResponseEntity<TrainingDto> delete(@PathVariable int id) {
try
{
return new ResponseEntity<>
(new TrainingDto(trainingService.delete(id)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/")
public ResponseEntity<List<TrainingDto>> getAll() {
try
{
return new ResponseEntity<>
(trainingService.findAll().stream().map(TrainingDto::new).toList(), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/{id}")
public ResponseEntity<TrainingDto> getById(@PathVariable int id) {
try
{
return new ResponseEntity<>
(new TrainingDto(trainingService.findById(id)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -1,126 +0,0 @@
package putBit.app.controllers;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import putBit.app.controllers.Dto.ExamResultDto;
import putBit.app.controllers.Dto.TrainingExamDto;
import putBit.app.services.TrainingExamService;
import putBit.app.services.TrainingService;
import putBit.app.services.exceptions.ValidationException;
import java.util.List;
@AllArgsConstructor
@CrossOrigin(origins = "http://localhost:8081")
@RestController
@RequestMapping("/api/training_exam")
public class TrainingExamController {
private final TrainingExamService trainingExamService;
@PostMapping("/")
public ResponseEntity<TrainingExamDto> create(@RequestBody TrainingExamDto examDto) {
try
{
return new ResponseEntity<>
(new TrainingExamDto(trainingExamService.create(examDto)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@PutMapping("/")
public ResponseEntity<TrainingExamDto> update(@RequestBody TrainingExamDto examDto) {
try
{
return new ResponseEntity<>
(new TrainingExamDto(trainingExamService.update(examDto)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@DeleteMapping("/{trainingId}/{examId}")
public ResponseEntity<TrainingExamDto> delete(@PathVariable int trainingId, @PathVariable int examId) {
try
{
return new ResponseEntity<>
(new TrainingExamDto(trainingExamService.delete(trainingId,examId)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/{trainingId}/{examId}")
public ResponseEntity<TrainingExamDto> getById(@PathVariable int trainingId, @PathVariable int examId) {
try
{
return new ResponseEntity<>
(new TrainingExamDto(trainingExamService.findById(trainingId, examId)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/forTraining/{id}")
public ResponseEntity<List<TrainingExamDto>> getForUser(@PathVariable int id) {
try
{
return new ResponseEntity<>
(trainingExamService.findByTraining(id).stream().map(TrainingExamDto::new).toList(), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -1,114 +0,0 @@
package putBit.app.controllers;
import lombok.AllArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import putBit.app.controllers.Dto.ExamResultDto;
import putBit.app.controllers.Dto.UserDto;
import putBit.app.services.*;
import putBit.app.services.exceptions.EntityNotFoundException;
import putBit.app.services.exceptions.ValidationException;
import java.util.List;
@AllArgsConstructor
@CrossOrigin(origins = "http://localhost:8081")
@RestController
@RequestMapping("/api/user")
public class UserController {
private final UserService userService;
@PostMapping("/")
public ResponseEntity<UserDto> createUser(@RequestBody UserDto userDto) {
try
{
return new ResponseEntity<>
(new UserDto(userService.create(userDto)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/auth")
public ResponseEntity<UserDto> auth(@RequestBody UserDto userDto) {
try
{
return new ResponseEntity<>
(new UserDto(userService.auth(userDto)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (EntityNotFoundException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@PutMapping("/")
public ResponseEntity<UserDto> update(@RequestBody UserDto userDto) {
try
{
return new ResponseEntity<>
(new UserDto(userService.update(userDto)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
@GetMapping("/{id}")
public ResponseEntity<UserDto> getById(@PathVariable int id) {
try
{
return new ResponseEntity<>
(new UserDto(userService.findById(id)), HttpStatus.OK);
}
catch (ValidationException ex)
{
return new ResponseEntity<>
(null, HttpStatus.BAD_REQUEST);
}
catch (Exception ex)
{
return new ResponseEntity<>
(null, HttpStatus.INTERNAL_SERVER_ERROR);
}
}
}

View File

@ -1,31 +0,0 @@
package putBit.app.models;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "achievements")
public class Achievement {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Column(name = "title", unique = true, nullable = false, length = 20)
private String title ;
@Column(name = "points", nullable = false, length = 3)
private int points ;
@ManyToMany(mappedBy = "achievements")
List<User> users;
}

View File

@ -1,28 +0,0 @@
package putBit.app.models;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "benefits")
public class Benefit {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Column(name = "title", unique = true,nullable = false, length = 20)
private String title ;
@ManyToMany(mappedBy = "benefits")
List<User> users;
}

View File

@ -1,32 +0,0 @@
package putBit.app.models;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
import java.util.UUID;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "exams")
public class Exam {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Column(name = "title", unique = true, nullable = false, length = 20)
private String title ;
@OneToMany(fetch = FetchType.EAGER,cascade = CascadeType.REMOVE, mappedBy = "exam")
List<ExamResult> users;
@OneToMany(fetch = FetchType.EAGER,cascade = CascadeType.REMOVE, mappedBy = "exam")
List<TrainingExam> trainings;
}

View File

@ -1,31 +0,0 @@
package putBit.app.models;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import putBit.app.models.PrimaryKey.ExamResultPK;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@IdClass(ExamResultPK.class)
@Entity(name = "exam_results")
public class ExamResult {
@Id
@ManyToOne
@JoinColumn(name = "user_id", nullable = false)
private User user ;
@Id
@ManyToOne
@JoinColumn(name = "exam_id", nullable = false)
private Exam exam ;
@Column(name = "points", nullable = false,unique = false, length = 3)
private int points ;
}

View File

@ -1,35 +0,0 @@
package putBit.app.models;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.Cascade;
import putBit.app.models.PrimaryKey.OrderPK;
import putBit.app.models.PrimaryKey.TrainingExamPK;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@IdClass(OrderPK.class)
@Entity(name = "orders")
public class Order {
@Id
@OneToOne
@JoinColumn(name = "user_id", unique = true,nullable = false)
private User user;
@Id
@ManyToOne
@JoinColumn(name = "training_id",nullable = false)
private Training training;
@Column(name = "confirm", columnDefinition = "boolean",nullable = false)
private Boolean confirm ;
@Column(name = "benefit", columnDefinition = "boolean",nullable = false)
private Boolean benefit ;
}

View File

@ -1,24 +0,0 @@
package putBit.app.models.PrimaryKey;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import putBit.app.models.Exam;
import putBit.app.models.User;
import java.io.Serializable;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class ExamResultPK implements Serializable {
private int user;
private int exam;
}

View File

@ -1,21 +0,0 @@
package putBit.app.models.PrimaryKey;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.io.Serializable;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OrderPK implements Serializable {
private int user;
private int training;
}

View File

@ -1,24 +0,0 @@
package putBit.app.models.PrimaryKey;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import putBit.app.models.Exam;
import putBit.app.models.Training;
import putBit.app.models.User;
import java.io.Serializable;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class TrainingExamPK implements Serializable {
private int training;
private int exam;
}

View File

@ -1,47 +0,0 @@
package putBit.app.models;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "trainings")
public class Training {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Column(name = "num", unique = true, nullable = false, length = 11)
private String num ;
@Column(name = "title", unique = true, nullable = false, length = 50)
private String title ;
@Column(name = "desc", nullable = false, length = 300)
private String desc ;
@Column(name = "prof", nullable = false, length = 300)
private String prof ;
@Column(name = "basic_places", nullable = false, length = 3)
private int basic_places ;
@Column(name = "benefit_places", nullable = false, length = 3)
private int benefit_places ;
@OneToMany(fetch = FetchType.EAGER,cascade = CascadeType.REMOVE, mappedBy = "training")
List<TrainingExam> exams;
@OneToMany(fetch = FetchType.EAGER, cascade = CascadeType.PERSIST, mappedBy = "training")
List<Order> orders;
}

View File

@ -1,32 +0,0 @@
package putBit.app.models;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import putBit.app.models.PrimaryKey.TrainingExamPK;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@IdClass(TrainingExamPK.class)
@Entity(name = "training_exams")
public class TrainingExam {
@Id
@ManyToOne
@JoinColumn(name = "training_id", nullable = false)
private Training training ;
@Id
@ManyToOne
@JoinColumn(name = "exam_id", nullable = false)
private Exam exam ;
@Column(name = "points", nullable = false, length = 3)
private int points ;
}

View File

@ -1,100 +0,0 @@
package putBit.app.models;
import jakarta.persistence.*;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import putBit.app.models.enums.Role;
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.UUID;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
@Entity(name = "users")
public class User {
@Id
@GeneratedValue
@Column(name = "id")
private int id;
@Enumerated(EnumType.STRING)
@Column(name = "role", nullable = false)
private Role role;
@Column(name = "email", nullable = false)
private String email;
@Column(name = "password", nullable = false, length = 20)
private String password;
@Column(name = "phone", length = 12)
private String phone;
@Column(name = "name", nullable = false, length = 80)
private String name;
@Column(name = "snils", unique = true, length = 11)
private String snils;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "user_achievements",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "achievements_id"))
Set<Achievement> achievements;
@ManyToMany(fetch = FetchType.EAGER)
@JoinTable(
name = "user_benefits",
joinColumns = @JoinColumn(name = "user_id"),
inverseJoinColumns = @JoinColumn(name = "benefits_id"))
Set<Benefit> benefits;
@OneToMany(fetch = FetchType.EAGER,cascade = CascadeType.REMOVE, mappedBy = "user")
List<ExamResult> exams;
@OneToOne(fetch = FetchType.EAGER,cascade = CascadeType.PERSIST, mappedBy = "user" )
Order order;
public void addAchievement(Achievement achievement){
achievements.add(achievement);
}
public boolean deleteAchievement(Achievement achievement){
for(Achievement ach:
achievements)
{
if (ach.getId() == achievement.getId()) {
achievements.remove(ach);
return true;
}
}
return false;
}
public void addBenefit(Benefit benefit){
benefits.add(benefit);
}
public boolean deleteBenefit(Benefit benefit){
for(Benefit ben:
benefits)
{
if (ben.getId() == benefit.getId()) {
benefits.remove(ben);
return true;
}
}
return false;
}
}

View File

@ -1,6 +0,0 @@
package putBit.app.models.enums;
public enum Role {
USER,
ADMIN,
}

View File

@ -1,28 +0,0 @@
package putBit.app.repositories;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import putBit.app.models.Achievement;
import putBit.app.models.Benefit;
import putBit.app.models.ExamResult;
import putBit.app.models.User;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
public interface AchievementRepository extends JpaRepository<Achievement, Integer> {
@Query(value = "select a.* from achievements a " +
"where a.id in (select ua.achievements_id from USER_ACHIEVEMENTS ua " +
"where ua.user_id = :id)", nativeQuery = true)
List<Achievement> findAchievementsByUsersId(@Param("id") int userId);
@Query(value = "select a.* from achievements a " +
"where a.id not in (select ua.achievements_id from USER_ACHIEVEMENTS ua " +
"where ua.user_id = :id)", nativeQuery = true)
List<Achievement> findAchievementsByUsersIdNot(@Param("id") int userId);
}

View File

@ -1,25 +0,0 @@
package putBit.app.repositories;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import putBit.app.models.Benefit;
import putBit.app.models.User;
import java.util.List;
import java.util.Optional;
public interface BenefitRepository extends JpaRepository<Benefit, Integer> {
@Query(value = "select b.* from benefits b " +
"where b.id in (select ub.benefits_id from USER_BENEFITS ub " +
"where ub.user_id = :id)", nativeQuery = true)
List<Benefit> findBenefitsByUsersId(@Param("id") int userId);
@Query(value = "select b.* from benefits b " +
"where b.id not in (select ub.benefits_id from USER_BENEFITS ub " +
"where ub.user_id = :id)", nativeQuery = true)
List<Benefit> findBenefitsByUsersIdNot(@Param("id") int userId);
}

View File

@ -1,23 +0,0 @@
package putBit.app.repositories;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import putBit.app.models.Exam;
import putBit.app.models.User;
import java.util.List;
import java.util.Optional;
public interface ExamRepository extends JpaRepository<Exam, Integer> {
@Query(value = "select e.* from exams e " +
"where e.id not in (select er.exam_id from exam_results er " +
"where er.user_id = :id )", nativeQuery = true)
List<Exam> findByUserIdNot(@Param("id") int id);
@Query(value = "select e.* from exams e " +
"where e.id not in (select te.exam_id from training_exams te " +
"where te.training_id = :id )", nativeQuery = true)
List<Exam> findByTrainingIdNot(@Param("id") int id);
}

View File

@ -1,17 +0,0 @@
package putBit.app.repositories;
import org.springframework.data.jpa.repository.JpaRepository;
import putBit.app.models.Exam;
import putBit.app.models.ExamResult;
import putBit.app.models.PrimaryKey.ExamResultPK;
import putBit.app.models.User;
import java.util.List;
import java.util.Optional;
public interface ExamResultRepository extends JpaRepository<ExamResult, ExamResultPK> {
Optional<ExamResult> findByUserAndExam(User user, Exam exam);
List<ExamResult> findAllByUser(User user);
}

View File

@ -1,31 +0,0 @@
package putBit.app.repositories;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Modifying;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import putBit.app.models.Order;
import putBit.app.models.PrimaryKey.OrderPK;
import putBit.app.models.Training;
import putBit.app.models.User;
import java.util.List;
import java.util.Optional;
public interface OrderRepository extends JpaRepository<Order, OrderPK> {
@Query(value = "select o.* from orders o " +
" where o.training_id = :id and " +
" o.user_id in (select u.id from users u where " +
" LOWER(u.name) LIKE CONCAT('%',LOWER(:value),'%') or LOWER(u.snils) like CONCAT('%',LOWER(:value),'%'))" , nativeQuery = true)
List<Order> findByUserInfo(@Param("value") String value, @Param("id") int id);
List<Order> findAllByBenefitAndTraining(Boolean benefit, Training training);
Optional<Order> findByUser(User user);
@Modifying
@Query(value = "delete from orders o where " +
"o.user_id = :user" , nativeQuery = true)
void deleteByUser(@Param("user") int userId);
}

View File

@ -1,16 +0,0 @@
package putBit.app.repositories;
import org.springframework.data.jpa.repository.JpaRepository;
import putBit.app.models.*;
import putBit.app.models.PrimaryKey.TrainingExamPK;
import java.util.List;
import java.util.Optional;
public interface TrainingExamRepository extends JpaRepository<TrainingExam, TrainingExamPK> {
List<TrainingExam> findAllByTraining(Training training);
Optional<TrainingExam> findByTrainingAndExam(Training training, Exam exam);
}

View File

@ -1,13 +0,0 @@
package putBit.app.repositories;
import org.springframework.data.jpa.repository.JpaRepository;
import putBit.app.models.Training;
import putBit.app.models.User;
import java.util.List;
import java.util.Optional;
public interface TrainingRepository extends JpaRepository<Training, Integer> {
List<Training> findAllByTitleContainingIgnoreCase(String title);
}

View File

@ -1,25 +0,0 @@
package putBit.app.repositories;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import putBit.app.models.User;
import java.util.List;
import java.util.Optional;
import java.util.UUID;
public interface UserRepository extends JpaRepository<User, Integer> {
@Query(value = "select u.* from users u " +
"where u.id in (select ua.user_id from USER_ACHIEVEMENTS ua " +
"where ua.achievements_id = :id)", nativeQuery = true)
List<User> findUsersByAchievementsId(@Param("id")int AchievementId);
@Query(value = "select u.* from users u " +
"where u.id in (select ub.user_id from USER_BENEFITS ub " +
"where ub.benefits_id = :id)", nativeQuery = true)
List<User> findUsersByBenefitsId(@Param("id")int AchievementId);
Optional<User> findByEmailAndPassword(String email, String password);
}

View File

@ -1,81 +0,0 @@
package putBit.app.services;
import lombok.RequiredArgsConstructor;
import org.hibernate.sql.exec.ExecutionException;
import org.springframework.stereotype.Service;
import putBit.app.controllers.Dto.AchievementDto;
import putBit.app.controllers.Dto.UserDto;
import putBit.app.models.Achievement;
import putBit.app.models.User;
import putBit.app.repositories.AchievementRepository;
import putBit.app.repositories.UserRepository;
import putBit.app.services.exceptions.EntityNotFoundException;
import putBit.app.services.exceptions.ValidationException;
import java.util.List;
@Service
@RequiredArgsConstructor
public class AchievementService {
private final AchievementRepository achievementRepository;
private final UserRepository userRepository;
public Achievement create(AchievementDto achievement){
if(achievement.getTitle().isEmpty() || (achievement.getTitle().length() < 3 || achievement.getTitle().length() > 20 ) )
throw new ValidationException("Неверные данные");
if(achievement.getPoints() > 10 || achievement.getPoints() < 0 )
throw new ValidationException("Неверные данные");
Achievement newAchievement = Achievement.builder()
.title(achievement.getTitle())
.points(achievement.getPoints())
.build();
return achievementRepository.save(newAchievement);
}
public Achievement findById(int id){
return achievementRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException("Достижение не найдено"));
}
public Achievement update(AchievementDto achievement)
{
if(achievement.getTitle().isEmpty() || (achievement.getTitle().length() < 3 || achievement.getTitle().length() > 20 ) )
throw new ValidationException("Неверные данные");
if(achievement.getPoints() > 10 || achievement.getPoints() < 0 )
throw new ValidationException("Неверные данные");
Achievement currentAchievement = findById(achievement.getId());
currentAchievement.setTitle(achievement.getTitle());
currentAchievement.setPoints(achievement.getPoints());
return achievementRepository.save(currentAchievement);
}
public Achievement delete(int id){
Achievement currentAchievement = findById(id);
List<User> users = userRepository.findUsersByAchievementsId(id);
for(User user:
users){
user.deleteAchievement(currentAchievement);
userRepository.save(user);
}
achievementRepository.delete(currentAchievement);
return currentAchievement;
}
public List<Achievement> findAll(){
return achievementRepository.findAll();
}
public List<Achievement> findByUser(int id){
return achievementRepository.findAchievementsByUsersId(id);
}
public List<Achievement> findByUserNot(int id){
return achievementRepository.findAchievementsByUsersIdNot(id);
}
}

View File

@ -1,76 +0,0 @@
package putBit.app.services;
import lombok.RequiredArgsConstructor;
import org.hibernate.sql.exec.ExecutionException;
import org.springframework.stereotype.Service;
import putBit.app.controllers.Dto.BenefitDto;
import putBit.app.controllers.Dto.UserDto;
import putBit.app.models.Achievement;
import putBit.app.models.Benefit;
import putBit.app.models.User;
import putBit.app.repositories.BenefitRepository;
import putBit.app.repositories.UserRepository;
import putBit.app.services.exceptions.EntityNotFoundException;
import putBit.app.services.exceptions.ValidationException;
import java.util.List;
@Service
@RequiredArgsConstructor
public class BenefitService {
private final BenefitRepository benefitRepository;
private final UserRepository userRepository;
public Benefit create(BenefitDto benefit){
if(benefit.getTitle().isEmpty() || (benefit.getTitle().length() < 3 || benefit.getTitle().length() > 20 ) )
throw new ValidationException("Неверные данные");
Benefit newBenefit = Benefit.builder()
.title(benefit.getTitle())
.build();
return benefitRepository.save(newBenefit);
}
public Benefit findById(int id){
return benefitRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException("Льгота не найдена"));
}
public Benefit update(BenefitDto benefit)
{
if(benefit.getTitle().isEmpty() || (benefit.getTitle().length() < 3 || benefit.getTitle().length() > 20 ) )
throw new ValidationException("Неверные данные");
Benefit currentBenefit = findById(benefit.getId());
currentBenefit.setTitle(benefit.getTitle());
return benefitRepository.save(currentBenefit);
}
public Benefit delete(int id ){
Benefit currentBenefit = findById(id);
List<User> users = userRepository.findUsersByBenefitsId(id);
for(User user:
users){
user.deleteBenefit(currentBenefit);
userRepository.save(user);
}
benefitRepository.delete(currentBenefit);
return currentBenefit;
}
public List<Benefit> findAll(){
return benefitRepository.findAll();
}
public List<Benefit> findByUser(int id){
return benefitRepository.findBenefitsByUsersId(id);
}
public List<Benefit> findByUserNot(int id){
return benefitRepository.findBenefitsByUsersIdNot(id);
}
}

View File

@ -1,67 +0,0 @@
package putBit.app.services;
import lombok.RequiredArgsConstructor;
import org.hibernate.sql.exec.ExecutionException;
import org.springframework.stereotype.Service;
import putBit.app.controllers.Dto.ExamResultDto;
import putBit.app.controllers.Dto.UserDto;
import putBit.app.models.Exam;
import putBit.app.models.ExamResult;
import putBit.app.models.PrimaryKey.ExamResultPK;
import putBit.app.models.User;
import putBit.app.repositories.ExamResultRepository;
import putBit.app.services.exceptions.EntityNotFoundException;
import putBit.app.services.exceptions.ValidationException;
import java.util.List;
@Service
@RequiredArgsConstructor
public class ExamResultService {
private final ExamResultRepository examResultRepository;
private final UserService userService;
private final ExamService examService;
public ExamResult create(ExamResultDto examResult){
User user = userService.findById(examResult.getUser());
Exam exam = examService.findById(examResult.getExam());
ExamResult newExam = ExamResult.builder()
.user(user)
.exam(exam)
.points(0)
.build();
return examResultRepository.save(newExam);
}
public ExamResult findById(int userId, int examId){
User user = userService.findById(userId);
Exam exam = examService.findById(examId);
ExamResultPK pk = new ExamResultPK(user.getId(),exam.getId());
return examResultRepository.findById(pk)
.orElseThrow(() -> new EntityNotFoundException("Экзамен не найден"));
}
public ExamResult update(ExamResultDto examResult)
{
if(examResult.getPoints() > 100 || examResult.getPoints() < 0 )
throw new ValidationException("Неверные данные");
ExamResult currentExam = findById(examResult.getUser(),examResult.getExam());
currentExam.setPoints(examResult.getPoints());
return examResultRepository.save(currentExam);
}
public ExamResult delete(int userId, int examId){
ExamResult currentExam = findById( userId, examId);
examResultRepository.delete(currentExam);
return currentExam;
}
public List<ExamResult> findByUser(int id){
User currentUser = userService.findById(id);
return examResultRepository.findAllByUser(currentUser);
}
}

View File

@ -1,69 +0,0 @@
package putBit.app.services;
import lombok.RequiredArgsConstructor;
import org.hibernate.sql.exec.ExecutionException;
import org.springframework.stereotype.Service;
import putBit.app.controllers.Dto.ExamDto;
import putBit.app.controllers.Dto.TrainingDto;
import putBit.app.controllers.Dto.UserDto;
import putBit.app.models.Exam;
import putBit.app.models.Training;
import putBit.app.models.User;
import putBit.app.models.enums.Role;
import putBit.app.repositories.ExamRepository;
import putBit.app.services.exceptions.EntityNotFoundException;
import putBit.app.services.exceptions.ValidationException;
import java.util.List;
@Service
@RequiredArgsConstructor
public class ExamService {
private final ExamRepository examRepository;
public Exam create(ExamDto exam){
if(exam.getTitle().isEmpty() || (exam.getTitle().length() < 3 || exam.getTitle().length() > 20 ) )
throw new ValidationException("Неверные данные");
Exam newExam = Exam.builder()
.title(exam.getTitle())
.build();
return examRepository.save(newExam);
}
public Exam findById(int id){
return examRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException("Экзамен не найден"));
}
public Exam update(ExamDto exam)
{
if(exam.getTitle().isEmpty() || (exam.getTitle().length() < 3 || exam.getTitle().length() > 20 ) )
throw new ValidationException("Неверные данные");
Exam currentExam = findById(exam.getId());
currentExam.setTitle(exam.getTitle());
return examRepository.save(currentExam);
}
public Exam delete(int id){
Exam currentExam = findById(id);
examRepository.delete(currentExam);
return currentExam;
}
public List<Exam> findAll(){
return examRepository.findAll();
}
public List<Exam> findNotUser(int id){
return examRepository.findByUserIdNot(id);
}
public List<Exam> findNotTraining(int id){
return examRepository.findByTrainingIdNot(id);
}
}

View File

@ -1,182 +0,0 @@
package putBit.app.services;
import jakarta.mail.MessagingException;
import lombok.RequiredArgsConstructor;
import org.aspectj.weaver.ast.Or;
import org.hibernate.service.NullServiceException;
import org.hibernate.sql.exec.ExecutionException;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import putBit.app.Timer.myTimer;
import putBit.app.controllers.Dto.OrderDto;
import putBit.app.models.*;
import putBit.app.models.PrimaryKey.OrderPK;
import putBit.app.repositories.OrderRepository;
import putBit.app.repositories.TrainingRepository;
import putBit.app.repositories.UserRepository;
import putBit.app.services.WorkEmail.EmailWork;
import putBit.app.services.exceptions.EntityNotFoundException;
import putBit.app.services.help.OrderPoints;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
@Service
public class OrderService {
private final UserService userService;
private final TrainingService trainingService;
private final OrderRepository orderRepository;
private final EmailWork emailWork;
public OrderService(
UserService userService,
TrainingService trainingService,
OrderRepository orderRepository){
this.userService=userService;
this.trainingService = trainingService;
this.orderRepository = orderRepository;
this.emailWork = new EmailWork();
myTimer timer = myTimer.getInstance(this);
}
@Transactional
public Order create(OrderDto order){
User user = userService.findById(order.getUser());
Training training = trainingService.findById(order.getTraining());
int limit = 0;
for(TrainingExam exam:
training.getExams())
{
boolean check = false;
for(ExamResult result:
user.getExams())
{
if(result.getExam().getId() == exam.getExam().getId())
{
check = true;
break;
}
}
if(!check)
return null;
}
for(TrainingExam exam:
training.getExams())
{
limit+=exam.getPoints();
}
int userPoints=0;
for(ExamResult result:
user.getExams())
{
userPoints+= result.getPoints();
}
if(limit>userPoints)
return null;
Order newOrder = Order.builder()
.user(user)
.training(training)
.benefit(user.getBenefits() != null && !user.getBenefits().isEmpty())
.confirm(false)
.build();
return orderRepository.save(newOrder);
}
public Order findById(int userId, int trainId){
OrderPK pk = new OrderPK(userId,trainId);
return orderRepository.findById(pk)
.orElseThrow(() -> new EntityNotFoundException("Заявка не найдена"));
}
@Transactional
public Order delete(int userId, int trainId){
Order currentOrder = findById(userId,trainId);
orderRepository.deleteByUser(userId);
return currentOrder;
}
public List<Order> findForBenefit(int id){
Training training = trainingService.findById(id);
return orderRepository.findAllByBenefitAndTraining(true, training);
}
public List<Order> findForBasic(int id){
Training training = trainingService.findById(id);
return orderRepository.findAllByBenefitAndTraining(false, training);
}
public List<Order> findByNameOrSnils(int id, String text){
return orderRepository.findByUserInfo(text, id);
}
public Order findByUser(int id){
User user = userService.findById(id);
return orderRepository.findByUser(user)
.orElseThrow(() -> new EntityNotFoundException("У этого челика нет заявления"));
}
public void emailSend() throws MessagingException {
List<Order> orders = orderRepository.findAll();
for(var order: orders){
String email = order.getUser().getEmail();
if(order.getConfirm())
emailWork.sendMessage(email, "Поздравляем, вы поступили");
else
emailWork.sendMessage(email, "Сожалеем, вы не поступили");
}
}
@Transactional
public void workWithStudents() throws MessagingException {
List<Training> trainings = trainingService.findAll();
for(Training training: trainings)
{
System.out.println(training.getId() + " or:" + training.getOrders().size());
if(training.getOrders().isEmpty())
continue;
List<OrderPoints> orders_benefits = new ArrayList<>(findForBenefit(training.getId()).stream().map(or -> new OrderPoints(or)).toList());
List<OrderPoints> orders_basic = new ArrayList<>(findForBasic(training.getId()).stream().map(or -> new OrderPoints(or)).toList());
orders_benefits.sort(Collections.reverseOrder());
orders_basic.sort(Collections.reverseOrder());
List<Order> orderToUpdate = new ArrayList<>();
System.out.println(orders_basic.size());
System.out.println(orders_benefits.size());
int i = 0;
for(var order: orders_benefits)
{
if(i == training.getBenefit_places())
break;
order.getOrder().setConfirm(true);
orderToUpdate.add(order.getOrder());
i++;
}
i = 0;
for(var order: orders_basic)
{
if(i == training.getBasic_places())
break;
order.getOrder().setConfirm(true);
orderToUpdate.add(order.getOrder());
i++;
}
orderRepository.saveAll(orderToUpdate);
}
//emailSend();
}
}

View File

@ -1,64 +0,0 @@
package putBit.app.services;
import lombok.RequiredArgsConstructor;
import org.hibernate.sql.exec.ExecutionException;
import org.springframework.stereotype.Service;
import putBit.app.controllers.Dto.TrainingDto;
import putBit.app.controllers.Dto.TrainingExamDto;
import putBit.app.models.*;
import putBit.app.models.PrimaryKey.TrainingExamPK;
import putBit.app.repositories.TrainingExamRepository;
import putBit.app.services.exceptions.EntityNotFoundException;
import putBit.app.services.exceptions.ValidationException;
import java.util.List;
@Service
@RequiredArgsConstructor
public class TrainingExamService {
private final TrainingExamRepository trainingExamRepository;
private final ExamService examService;
private final TrainingService trainingService;
public TrainingExam create(TrainingExamDto trainingExam){
Training training = trainingService.findById(trainingExam.getTraining());
Exam exam = examService.findById(trainingExam.getExam());
TrainingExam newExam = TrainingExam.builder()
.training(training)
.exam(exam)
.points(0)
.build();
return trainingExamRepository.save(newExam);
}
public TrainingExam findById(int trainId, int examId){
TrainingExamPK pk = new TrainingExamPK(trainId,examId);
return trainingExamRepository.findById(pk)
.orElseThrow(() -> new EntityNotFoundException("Экзамен не найден"));
}
public TrainingExam update(TrainingExamDto trainingExam)
{
if(trainingExam.getPoints() > 100 || trainingExam.getPoints() < 0 )
throw new ValidationException("Неверные данные");
TrainingExam currentExam = findById(trainingExam.getTraining(),trainingExam.getExam());
currentExam.setPoints(trainingExam.getPoints());
return trainingExamRepository.save(currentExam);
}
public TrainingExam delete(int trainId, int examId){
TrainingExam currentExam = findById( trainId, examId);
trainingExamRepository.delete(currentExam);
return currentExam;
}
public List<TrainingExam> findByTraining(int id){
Training currentTraining = trainingService.findById(id);
return trainingExamRepository.findAllByTraining(currentTraining);
}
}

View File

@ -1,93 +0,0 @@
package putBit.app.services;
import lombok.RequiredArgsConstructor;
import org.hibernate.sql.exec.ExecutionException;
import org.springframework.stereotype.Service;
import putBit.app.controllers.Dto.TrainingDto;
import putBit.app.models.Exam;
import putBit.app.models.Training;
import putBit.app.models.User;
import putBit.app.repositories.TrainingRepository;
import putBit.app.services.exceptions.EntityNotFoundException;
import putBit.app.services.exceptions.ValidationException;
import java.util.List;
@Service
@RequiredArgsConstructor
public class TrainingService {
private final TrainingRepository trainingRepository;
public Training create(TrainingDto training){
if(training.getTitle().isEmpty() || (training.getTitle().length() < 2 || training.getTitle().length() > 50 ) )
throw new ValidationException("Неверное название");
if(training.getNum().isEmpty() || (training.getNum().length() < 8 || training.getTitle().length() > 11 ) )
throw new ValidationException("Неверный номер");
if(training.getDesc().isEmpty() || (training.getDesc().length() < 10 || training.getDesc().length() > 300 ) )
throw new ValidationException("Неверное описание");
if(training.getProf().isEmpty() || (training.getProf().length() < 5 || training.getProf().length() > 300 ) )
throw new ValidationException("Неверные профессии");
if(training.getBasic_places() > 999 || training.getBasic_places() < 10 )
throw new ValidationException("Неверные базовые места");
if(training.getBenefit_places() > 999 || training.getBenefit_places() < 10 )
throw new ValidationException("Неверные льготные места");
Training newTraining = Training.builder()
.title(training.getTitle())
.num(training.getNum())
.desc(training.getDesc())
.prof(training.getProf())
.basic_places(training.getBasic_places())
.benefit_places(training.getBenefit_places())
.build();
return trainingRepository.save(newTraining);
}
public Training findById(int id){
return trainingRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException("Направление не найдено"));
}
public Training update(TrainingDto training)
{
if(training.getTitle().isEmpty() || (training.getTitle().length() < 2 || training.getTitle().length() > 50 ) )
throw new ValidationException("Неверное название");
if(training.getNum().isEmpty() || (training.getNum().length() < 8 || training.getNum().length() > 11 ) )
throw new ValidationException("Неверный номер");
if(training.getDesc().isEmpty() || (training.getDesc().length() < 10 || training.getDesc().length() > 300 ) )
throw new ValidationException("Неверное описание");
if(training.getProf().isEmpty() || (training.getProf().length() < 5 || training.getProf().length() > 300 ) )
throw new ValidationException("Неверные профессии");
if(training.getBasic_places() > 999 || training.getBasic_places() < 10 )
throw new ValidationException("Неверные базовые места");
if(training.getBenefit_places() > 999 || training.getBenefit_places() < 10 )
throw new ValidationException("Неверные льготные места");
Training currentTraining = findById(training.getId());
currentTraining.setTitle(training.getTitle());
currentTraining.setNum(training.getNum());
currentTraining.setDesc(training.getDesc());
currentTraining.setProf(training.getProf());
currentTraining.setBasic_places(training.getBasic_places());
currentTraining.setBenefit_places(training.getBenefit_places());
return trainingRepository.save(currentTraining);
}
public Training delete(int id){
Training currentTraining = findById(id);
trainingRepository.delete(currentTraining);
return currentTraining;
}
public List<Training> findAll(){
return trainingRepository.findAll();
}
public List<Training> findByTitle(String title){
return trainingRepository.findAllByTitleContainingIgnoreCase(title);
}
}

View File

@ -1,128 +0,0 @@
package putBit.app.services;
import lombok.RequiredArgsConstructor;
import org.hibernate.sql.exec.ExecutionException;
import org.springframework.stereotype.Service;
import putBit.app.controllers.Dto.AchievementDto;
import putBit.app.controllers.Dto.BenefitDto;
import putBit.app.controllers.Dto.UserDto;
import putBit.app.models.Achievement;
import putBit.app.models.Benefit;
import putBit.app.models.User;
import putBit.app.models.enums.Role;
import putBit.app.repositories.UserRepository;
import putBit.app.services.exceptions.EntityNotFoundException;
import putBit.app.services.exceptions.ValidationException;
import java.util.regex.Pattern;
@Service
@RequiredArgsConstructor
public class UserService {
private final UserRepository userRepository;
private final BenefitService benefitService;
private final AchievementService achievementService;
public static boolean patternMatches(String emailAddress) {
return Pattern
.compile("^(?=.{1,64}@)[A-Za-z0-9_-]+(\\\\.[A-Za-z0-9_-]+)*@[^-][A-Za-z0-9-]+(\\\\.[A-Za-z0-9-]+)*(\\\\.[A-Za-z]{2,})$")
.matcher(emailAddress)
.matches();
}
public User create(UserDto user){
if(patternMatches(user.getEmail()) )
throw new ValidationException("Неверная почта");
if(user.getName().isEmpty() || (user.getName().length() < 3 || user.getName().length() > 80 ) )
throw new ValidationException("Неверное ФИО");
if(user.getSnils().length() != 11)
throw new ValidationException("Неверный снилс");
if(user.getPassword().isEmpty() || (user.getPassword().length() < 6 || user.getName().length() > 20 ) )
throw new ValidationException("Неверный пароль");
if(user.getPhone().length() != 11)
throw new ValidationException("Неверный номер телефона");
User newUser = User.builder()
.email(user.getEmail())
.password(user.getPassword())
.phone(user.getPhone())
.role(Role.USER)
.name(user.getName())
.snils(user.getSnils())
.build();
return userRepository.save(newUser);
}
public User findById(int id){
return userRepository.findById(id)
.orElseThrow(() -> new EntityNotFoundException("Пользователь не найден"));
}
public User auth(UserDto user)
{
return userRepository.findByEmailAndPassword(user.getEmail(), user.getPassword())
.orElseThrow(() -> new EntityNotFoundException("Пользователь не найден"));
}
public User update(UserDto user)
{
if(user.getEmail().isEmpty() )
throw new ValidationException("Неверная почта");
if(user.getName().isEmpty() || (user.getName().length() < 3 || user.getName().length() > 80 ) )
throw new ValidationException("Неверное ФИО");
if(user.getSnils().length() != 11)
throw new ValidationException("Неверный снилс");
if(user.getPassword().isEmpty() || (user.getPassword().length() < 6 || user.getName().length() > 20 ) )
throw new ValidationException("Неверный пароль");
if(user.getPhone().length() > 12 || user.getPhone().length() < 11)
throw new ValidationException("Неверный номер телефона");
User currentUser = findById(user.getId());
if(!user.getName().isEmpty() && !currentUser.getName().equals(user.getName()))
currentUser.setName(user.getName());
if(!user.getEmail().isEmpty() && !currentUser.getEmail().equals(user.getEmail()))
currentUser.setName(user.getEmail());
if(!user.getPassword().isEmpty() && !currentUser.getPassword().equals(user.getPassword()))
currentUser.setPassword(user.getPassword());
if(!user.getPhone().isEmpty() && !currentUser.getPhone().equals(user.getPhone()))
currentUser.setPhone(user.getPhone());
if(!user.getSnils().isEmpty() && !currentUser.getSnils().equals(user.getSnils()))
currentUser.setSnils(user.getSnils());
return userRepository.save(currentUser);
}
public User addAchievement(UserDto user, AchievementDto achievement){
User currentUser = findById(user.getId());
Achievement newAch = achievementService.findById(achievement.getId());
currentUser.addAchievement(newAch);
return userRepository.save(currentUser);
}
public User addBenefit(UserDto user, BenefitDto benefit){
User currentUser = findById(user.getId());
Benefit newBen = benefitService.findById(benefit.getId());
currentUser.addBenefit(newBen);
return userRepository.save(currentUser);
}
public User removeAchievement(UserDto user,AchievementDto achievement){
User currentUser = findById(user.getId());
Achievement newAch = achievementService.findById(achievement.getId());
if (!currentUser.deleteAchievement(newAch))
throw new RuntimeException("нет такой ачивки у этого человека");
return userRepository.save(currentUser);
}
public User removeBenefit(UserDto user,BenefitDto benefit){
User currentUser = findById(user.getId());
Benefit newBen = benefitService.findById(benefit.getId());
if (!currentUser.deleteBenefit(newBen))
throw new RuntimeException("нет такой ачивки у этого человека");
return userRepository.save(currentUser);
}
}

View File

@ -1,59 +0,0 @@
package putBit.app.services.WorkEmail;
import jakarta.mail.*;
import jakarta.mail.internet.InternetAddress;
import jakarta.mail.internet.MimeBodyPart;
import jakarta.mail.internet.MimeMessage;
import jakarta.mail.internet.MimeMultipart;
import lombok.AllArgsConstructor;
import lombok.NoArgsConstructor;
import lombok.RequiredArgsConstructor;
import java.util.Properties;
public class EmailWork {
private Properties prop;
private final String username = "labrpp89@gmail.com";
private final String password = "wfhb szlu vibt jkae";
public EmailWork(){
prop = new Properties();
prop.put("mail.smtp.auth", true);
prop.put("mail.smtp.starttls.enable", "true");
prop.put("mail.smtp.host", "smtp.gmail.com");
prop.put("mail.smtp.port", "587");
prop.put("mail.smtp.ssl.trust", "smtp.gmail.com");
}
public void sendMessage(String emailTo, String text) throws MessagingException {
Session session = Session.getInstance(prop, new Authenticator() {
@Override
protected PasswordAuthentication getPasswordAuthentication() {
return new PasswordAuthentication(username, password);
}
});
Message message = new MimeMessage(session);
message.setFrom(new InternetAddress("from@gmail.com"));
message.setRecipients(
Message.RecipientType.TO, InternetAddress.parse(emailTo));
message.setSubject("Ваш любимый вуз");
String msg = text;
MimeBodyPart mimeBodyPart = new MimeBodyPart();
mimeBodyPart.setContent(msg, "text/html; charset=utf-8");
Multipart multipart = new MimeMultipart();
multipart.addBodyPart(mimeBodyPart);
message.setContent(multipart);
Transport.send(message);
}
}

View File

@ -1,7 +0,0 @@
package putBit.app.services.exceptions;
public class EntityNotFoundException extends RuntimeException {
public EntityNotFoundException(String text) {
super(String.format(text));
}
}

View File

@ -1,7 +0,0 @@
package putBit.app.services.exceptions;
public class ValidationException extends RuntimeException {
public ValidationException(String text) {
super(String.format(text));
}
}

View File

@ -1,40 +0,0 @@
package putBit.app.services.help;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import putBit.app.models.Order;
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class OrderPoints implements Comparable<OrderPoints>{
private Order order;
private int points;
public OrderPoints(Order order){
this.order = order;
int sum = 0;
for(var exam: order.getUser().getExams())
{
for(var examT: order.getTraining().getExams())
{
if(examT.getExam().getId() == exam.getExam().getId())
sum+= exam.getPoints();
}
}
for(var ach : order.getUser().getAchievements())
{
sum+= ach.getPoints();
}
this.points = sum;
}
@Override
public int compareTo(OrderPoints o) {
return Integer.compare(points,o.points);
}
}

View File

@ -1,12 +1 @@
spring.application.name=app
spring.main.banner-mode=off
#server.port=8081
spring.datasource.url=jdbc:h2:file:./data
spring.datasource.driverClassName=org.h2.Driver
spring.datasource.username=sa
spring.datasource.password=password
spring.jpa.database-platform=org.hibernate.dialect.H2Dialect
spring.jpa.hibernate.ddl-auto=update
spring.h2.console.enabled=true
spring.h2.console.settings.trace=false
spring.h2.console.settings.web-allow-others=false

View File

@ -1,541 +1,13 @@
package putBit.app;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import putBit.app.models.*;
import putBit.app.models.enums.Role;
import putBit.app.services.*;
import java.util.ArrayList;
import java.util.List;
@SpringBootTest
class AppApplicationTests {
@Autowired
UserService userService;
@Autowired
ExamService examService;
@Autowired
ExamResultService examResultService;
@Autowired
BenefitService benefitService;
@Autowired
AchievementService achievementService;
@Autowired
TrainingService trainingService;
@Autowired
TrainingExamService trainingExamService;
@Autowired
OrderService orderService;
// @Test
// void createUser() {
//
// User us1 = User.builder()
// .email("email1")
// .password("12345678")
// .phone("88005553535")
// .role(Role.USER)
// .name("Vova Morozov")
// .snils("33322233344")
// .build();
// User us2 = User.builder()
// .email("email2")
// .password("12345678")
// .phone("88005553535")
// .role(Role.USER)
// .name("Dima Redov")
// .snils("11122233344")
// .build();
// User res1 = userService.create(us1);
// User res2 = userService.create(us2);
// Assertions.assertNotNull(res1);
// Assertions.assertNotNull(res2);
// }
//
// @Test
// void CreateExam(){
// Exam ex1 = Exam.builder()
// .title("Математика")
// .build();
// Exam ex2 = Exam.builder()
// .title("Русский язык")
// .build();
// Exam ex3 = Exam.builder()
// .title("Физика")
// .build();
// Exam ex4 = Exam.builder()
// .title("Информатика")
// .build();
//
// Exam res1 = examService.create(ex1);
// Exam res2 = examService.create(ex2);
// Exam res3 = examService.create(ex3);
// Exam res4 = examService.create(ex4);
//
// Assertions.assertNotNull(res1);
// Assertions.assertNotNull(res2);
// Assertions.assertNotNull(res3);
// Assertions.assertNotNull(res4);
// }
//
// @Test
// void CreateBenefit(){
// Benefit bf1 = Benefit.builder()
// .title("Инвалидность I")
// .build();
// Benefit bf2 = Benefit.builder()
// .title("Инвалидность II")
// .build();
// Benefit bf3 = Benefit.builder()
// .title("Инвалидность III")
// .build();
//
// Benefit res1 = benefitService.create(bf1);
// Benefit res2 = benefitService.create(bf2);
// Benefit res3 = benefitService.create(bf3);
//
// Assertions.assertNotNull(res1);
// Assertions.assertNotNull(res2);
// Assertions.assertNotNull(res3);
// }
// @Test
// void CreateAchievements(){
// Achievement ac1 = Achievement.builder()
// .title("ГТО 1 степени")
// .points(5)
// .build();
// Achievement ac2 = Achievement.builder()
// .title("ГТО 2 степени")
// .points(3)
// .build();
// Achievement ac3 = Achievement.builder()
// .title("Красный диплом")
// .points(7)
// .build();
//
// Achievement res1 = achievementService.create(ac1);
// Achievement res2 = achievementService.create(ac2);
// Achievement res3 = achievementService.create(ac3);
//
// Assertions.assertNotNull(res1);
// Assertions.assertNotNull(res2);
// Assertions.assertNotNull(res3);
// }
// @Test
// void CreateExamResult(){
//
// User us1 = userService.findById(1);
// User us2 = userService.findById(52);
//
// Exam ex1 = examService.findById(1);
// Exam ex2 = examService.findById(2);
// Exam ex3 = examService.findById(3);
//
// ExamResult er1 = ExamResult.builder()
// .user(us1)
// .exam(ex1)
// .points(30)
// .build();
// ExamResult er2 = ExamResult.builder()
// .user(us1)
// .exam(ex2)
// .points(30)
// .build();
//
// ExamResult er3 = ExamResult.builder()
// .user(us2)
// .exam(ex2)
// .points(50)
// .build();
// ExamResult er4 = ExamResult.builder()
// .user(us2)
// .exam(ex3)
// .points(60)
// .build();
//
// var res1 = examResultService.create(er1);
// var res2 = examResultService.create(er2);
// var res3 = examResultService.create(er3);
// var res4 = examResultService.create(er4);
//
// Assertions.assertNotNull(res1);
// Assertions.assertNotNull(res2);
// Assertions.assertNotNull(res3);
// Assertions.assertNotNull(res4);
// }
//
// @Test
// void CreateTraining() {
// Training tr1 = Training.builder()
// .title("ПИбд")
// .num("09.09.01.01")
// .desc("Типо программисты")
// .prof("бэкендер, фронтендер, аналитикffff")
// .basic_places(100)
// .benefit_places(10)
// .build();
// Training tr2 = Training.builder()
// .title("ИВТ")
// .num("09.09.02")
// .desc("Типо программисты-инженеры")
// .prof("на заваод")
// .basic_places(120)
// .benefit_places(12)
// .build();
// Training tr3 = Training.builder()
// .title("ИСЭ")
// .num("09.09.03")
// .desc("Типо программисты-инженеры")
// .prof("цифровой экономист")
// .basic_places(120)
// .benefit_places(12)
// .build();
//
// var res1 = trainingService.create(tr1);
// var res2 = trainingService.create(tr2);
// var res3 = trainingService.create(tr3);
//
// Assertions.assertNotNull(res1);
// Assertions.assertNotNull(res2);
// Assertions.assertNotNull(res3);
// }
//
// @Test
// void CreateTrainingExam(){
//
// Training tr1 = trainingService.findById(1);
// Training tr2 = trainingService.findById(2);
//
// Exam ex1 = examService.findById(1);
// Exam ex2 = examService.findById(2);
// Exam ex3 = examService.findById(4);
//
// TrainingExam te1 = TrainingExam.builder()
// .training(tr1)
// .exam(ex1)
// .points(30)
// .build();
// TrainingExam te2 = TrainingExam.builder()
// .training(tr1)
// .exam(ex2)
// .points(30)
// .build();
// TrainingExam te3 = TrainingExam.builder()
// .training(tr2)
// .exam(ex2)
// .points(5)
// .build();
// TrainingExam te4 = TrainingExam.builder()
// .training(tr2)
// .exam(ex3)
// .points(66)
// .build();
//
// var res1 = trainingExamService.create(te1);
// var res2 = trainingExamService.create(te2);
// var res3 = trainingExamService.create(te3);
// var res4 = trainingExamService.create(te4);
//
// Assertions.assertNotNull(res1);
// Assertions.assertNotNull(res2);
// Assertions.assertNotNull(res3);
// Assertions.assertNotNull(res4);
//
// }
// @Test
// void CreateOrder(){
// Training tr1 = trainingService.findById(1);
// Training tr2 = trainingService.findById(3);
//
// User us1 = userService.findById(2);
// User us2 = userService.findById(2);
//
// Order o1 = Order.builder()
// .user(us1)
// .training(tr1)
// .build();
// Order o2 = Order.builder()
// .user(us2)
// .training(tr2)
// .build();
//
// var res1 = orderService.create(o1);
// var res2 = orderService.create(o2);
//
// Assertions.assertNotNull(res1);
// Assertions.assertNotNull(res2);
// }
//
// @Test
// void updateUser(){
// User us1 = userService.findById(1);
// String oldName = us1.getName();
// us1.setName(oldName + "Upd");
// var res = userService.update(us1);
// Assertions.assertNotNull(res);
//
// }
//
// @Test
// void updateUserAdd(){
// User us1 = userService.findById(1);
// Achievement ach1 = achievementService.findById(1);
// Achievement ach2 = achievementService.findById(2);
// List<User> res = new ArrayList<>();
// res.add(userService.addAchievement(us1, ach2));
// res.add(userService.addAchievement(us1, ach1));
//
// User us2 = userService.findById(52);
// Benefit b1 = benefitService.findById(2);
// Benefit b2 = benefitService.findById(3);
//
// res.add(userService.addAchievement(us2, ach2));
// res.add(userService.addBenefit(us2, b2));
// res.add(userService.addBenefit(us1,b2));
// Assertions.assertEquals(res.size(),4);
// }
//
// @Test
// void updateUserRemove(){
// User us1 = userService.findById(52);
// Benefit b1 = benefitService.findById(3);
// int countB = us1.getBenefits().size();
// us1 = userService.removeBenefit(us1,b1);
// Assertions.assertEquals(countB-1,us1.getBenefits().size());
// }
//
// @Test
// void updateExam(){
// Exam ex = examService.findById(1);
// String oldName = ex.getTitle();
// ex.setTitle(ex.getTitle() + "UPD");
// var res = examService.update(ex);
// Assertions.assertEquals(oldName + "UPD", res.getTitle());
// }
//
// @Test
// void updateExamResult(){
// ExamResult er = examResultService.findById(1,1);
// er.setPoints(100);
// var res = examResultService.update(er);
// Assertions.assertEquals(100,res.getPoints());
// }
//
// @Test
// void updateBenefit(){
// Benefit b = benefitService.findById(1);
// String oldName = b.getTitle();
// b.setTitle(b.getTitle() + "UPD");
// var res = benefitService.update(b);
// Assertions.assertEquals(oldName + "UPD", res.getTitle());
// }
//
// @Test
// void updateAchievement(){
// Achievement b = achievementService.findById(1);
// String oldName = b.getTitle();
// b.setTitle(b.getTitle() + "UPD");
// var res = achievementService.update(b);
// Assertions.assertEquals(oldName + "UPD", res.getTitle());
//
// }
//
// @Test
// void updateTraining(){
// Training b = trainingService.findById(1);
// String oldName = b.getTitle();
// b.setTitle(b.getTitle() + "UPD");
// var res = trainingService.update(b);
// Assertions.assertEquals(oldName + "UPD", res.getTitle());
//
// }
//
// @Test
// void updateTrainigExam(){
// TrainingExam er = trainingExamService.findById(1,1);
// er.setPoints(90);
// var res = trainingExamService.update(er);
// Assertions.assertEquals(110,res.getPoints());
//
// }
//
// @Test
// void deleteExam(){
// int countBefore = examService.findAll().size();
// Exam ex = examService.findById(3);
// examService.delete(ex);
// int countAfter = examService.findAll().size();
// Assertions.assertEquals(countBefore-1,countAfter);
// }
//
// @Test
// void deleteBenefit(){
// int countBefore = benefitService.findAll().size();
// Benefit ex = benefitService.findById(3);
// benefitService.delete(ex);
// int countAfter = benefitService.findAll().size();
// Assertions.assertEquals(countBefore-1,countAfter);
// }
//
// @Test
// void deleteAchievement(){
// int countBefore = achievementService.findAll().size();
// Achievement ex = achievementService.findById(2);
// achievementService.delete(ex);
// int countAfter = achievementService.findAll().size();
// Assertions.assertEquals(countBefore-1,countAfter);
// }
//
// @Test
// void deleteExamResult(){
// var res = examResultService.delete(1,1);
// Assertions.assertEquals(1,res.getUser().getId());
// }
//
// @Test
// void deleteTraining(){
// int countBefore = trainingService.findAll().size();
// Training ex = trainingService.findById(2);
// trainingService.delete(ex);
// int countAfter = trainingService.findAll().size();
// Assertions.assertEquals(countBefore-1,countAfter);
// }
//
// @Test
// void deleteTrainingExam(){
// var res = trainingExamService.delete(1,1);
// Assertions.assertEquals(1,res.getTraining().getId());
// }
//
// @Test
// void deleteOrder(){
// var res = orderService.delete(2,3);
// System.out.println(res.getUser().getName());
// }
//
// @Test
// void findUser(){
// userService.findByEmailAndPassword("email1","12345678");
// }
// @Test
// void findExam(){
// User user = userService.findById(2);
//
// var res1 = examResultService.findByUser(user);
// System.out.println("Exems have:" + user.getId());
// for(var res: res1)
// {
// System.out.println(res.getExam().getTitle());
// }
//
// var res2 = examService.findNotUser(user);
// System.out.println("Exems havent:" + user.getId());
// for(var res: res2)
// {
// System.out.println(res.getTitle());
// }
//
// Training training = trainingService.findById(1);
// var res3 = trainingExamService.findByTraining(training);
// System.out.println("Exems have:" + training.getId());
// for(var res: res3)
// {
// System.out.println(res.getExam().getTitle());
// }
//
// var res4 = examService.findNotTraining(training);
// System.out.println("Exems havent:" + training.getId());
// for(var res: res4)
// {
// System.out.println(res.getTitle());
// }
// }
// @Test
// void findBenefits(){
// User user = userService.findById(2);
//
// var res1 = benefitService.findByUser(user);
// System.out.println("Benefits have:" + user.getId());
// for(var res: res1)
// {
// System.out.println(res.getId());
// }
//
// var res2 = benefitService.findByUserNot(user);
// System.out.println("Benefits havent:" + user.getId());
// for(var res: res2)
// {
// System.out.println(res.getId());
// }
// }
//
// @Test
// void findAchievements(){
// User user = userService.findById(2);
//
// var res1 = achievementService.findByUser(user);
// System.out.println("chievement have:" + user.getId());
// for(var res: res1)
// {
// System.out.println(res.getId());
// }
//
// var res2 = achievementService.findByUserNot(user);
// System.out.println("chievement havent:" + user.getId());
// for(var res: res2)
// {
// System.out.println(res.getId());
// }
// }
//
// @Test
// void findTraining(){
// var res = trainingService.findByTitle("пи");
// for(var r: res)
// {
// System.out.println(r.getTitle());
// }
// }
//
// @Test
// void findOrders(){
// var res = orderService.findByNameOrSnils(1,"111");
// for(var r: res)
// {
// System.out.println(r.getUser().getName());
// }
// }
// @Test
// void findOrdersBenefit(){
// var res = orderService.findForBenefit(1);
// System.out.println("benefit");
// for(var r: res)
// {
// System.out.println(r.getUser().getName());
// }
//
// var res2 = orderService.findForBasic(1);
// System.out.println("basic");
// for(var r: res2)
// {
// System.out.println(r.getUser().getName());
// }
// }
@Test
void contextLoads() {
}
}