From 189d0ed203b68a3b525e8f470d5d3875442699f2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=D0=9D=D0=B8=D0=BA=D0=B8=D1=82=D0=B0=20=D0=91=D0=B5=D0=BB?= =?UTF-8?q?=D1=8F=D0=BD=D0=B8=D0=BD?= Date: Mon, 6 May 2024 15:30:32 +0400 Subject: [PATCH] =?UTF-8?q?=D0=9B=D0=B0=D0=B1=D0=BE=D1=80=D0=B0=D1=82?= =?UTF-8?q?=D0=BE=D1=80=D0=BD=D0=B0=D1=8F=203=20(Backend)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/example/demo/DemoApplication.java | 77 ------------------- .../demo/core/error/NotFoundException.java | 7 -- .../example/demo/core/model/BaseEntity.java | 20 ----- .../core/repository/CommonRepository.java | 17 ---- .../demo/core/repository/MapRepository.java | 57 -------------- .../house/repository/HouseRepository.java | 11 --- .../demo/house/service/HouseService.java | 72 ----------------- .../demo/speaker/api/SpeakerController.java | 23 ------ .../configuration/SpeakerConfiguration.java | 27 ------- .../example/demo/speaker/domain/Speaker.java | 5 -- .../demo/speaker/domain/SpeakerDeu.java | 28 ------- .../demo/speaker/domain/SpeakerEng.java | 26 ------- .../demo/speaker/domain/SpeakerRus.java | 21 ----- .../demo/speaker/service/SpeakerService.java | 21 ----- .../demo/types/repository/TypeRepository.java | 10 --- .../demo/types/service/TypeService.java | 43 ----------- .../example/demo/users/model/UserEntity.java | 75 ------------------ .../users/repository/UsersRepository.java | 10 --- .../demo/users/service/UsersService.java | 46 ----------- .../src/main/resources/application.properties | 1 - .../com/example/demo/HouseServiceTests.java | 52 ------------- .../com/example/demo/SpeakerSrviceTests.java | 38 --------- .../com/example/demo/TypeServiceTests.java | 59 -------------- .../com/example/demo/UsersServiceTests.java | 59 -------------- 24 files changed, 805 deletions(-) delete mode 100644 Lab2_2/src/main/java/com/example/demo/DemoApplication.java delete mode 100644 Lab2_2/src/main/java/com/example/demo/core/error/NotFoundException.java delete mode 100644 Lab2_2/src/main/java/com/example/demo/core/model/BaseEntity.java delete mode 100644 Lab2_2/src/main/java/com/example/demo/core/repository/CommonRepository.java delete mode 100644 Lab2_2/src/main/java/com/example/demo/core/repository/MapRepository.java delete mode 100644 Lab2_2/src/main/java/com/example/demo/house/repository/HouseRepository.java delete mode 100644 Lab2_2/src/main/java/com/example/demo/house/service/HouseService.java delete mode 100644 Lab2_2/src/main/java/com/example/demo/speaker/api/SpeakerController.java delete mode 100644 Lab2_2/src/main/java/com/example/demo/speaker/configuration/SpeakerConfiguration.java delete mode 100644 Lab2_2/src/main/java/com/example/demo/speaker/domain/Speaker.java delete mode 100644 Lab2_2/src/main/java/com/example/demo/speaker/domain/SpeakerDeu.java delete mode 100644 Lab2_2/src/main/java/com/example/demo/speaker/domain/SpeakerEng.java delete mode 100644 Lab2_2/src/main/java/com/example/demo/speaker/domain/SpeakerRus.java delete mode 100644 Lab2_2/src/main/java/com/example/demo/speaker/service/SpeakerService.java delete mode 100644 Lab2_2/src/main/java/com/example/demo/types/repository/TypeRepository.java delete mode 100644 Lab2_2/src/main/java/com/example/demo/types/service/TypeService.java delete mode 100644 Lab2_2/src/main/java/com/example/demo/users/model/UserEntity.java delete mode 100644 Lab2_2/src/main/java/com/example/demo/users/repository/UsersRepository.java delete mode 100644 Lab2_2/src/main/java/com/example/demo/users/service/UsersService.java delete mode 100644 Lab2_2/src/main/resources/application.properties delete mode 100644 Lab2_2/src/test/java/com/example/demo/HouseServiceTests.java delete mode 100644 Lab2_2/src/test/java/com/example/demo/SpeakerSrviceTests.java delete mode 100644 Lab2_2/src/test/java/com/example/demo/TypeServiceTests.java delete mode 100644 Lab2_2/src/test/java/com/example/demo/UsersServiceTests.java diff --git a/Lab2_2/src/main/java/com/example/demo/DemoApplication.java b/Lab2_2/src/main/java/com/example/demo/DemoApplication.java deleted file mode 100644 index 2ea99d0..0000000 --- a/Lab2_2/src/main/java/com/example/demo/DemoApplication.java +++ /dev/null @@ -1,77 +0,0 @@ -package com.example.demo; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.boot.CommandLineRunner; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; - -import com.example.demo.house.model.HouseEntity; -import com.example.demo.house.service.HouseService; -import com.example.demo.types.model.TypeEntity; -import com.example.demo.types.service.TypeService; -import com.example.demo.users.model.UserEntity; -import com.example.demo.users.service.UsersService; - -@SpringBootApplication -@RestController -@RequestMapping("/api") -public class DemoApplication implements CommandLineRunner { - private final Logger log = LoggerFactory.getLogger(DemoApplication.class); - - private final TypeService typeService; - private final HouseService houseService; - private final UsersService usersService; - - public DemoApplication(TypeService typeService, HouseService houseService, UsersService usersService) { - this.typeService = typeService; - this.houseService = houseService; - this.usersService = usersService; - } - - public static void main(String[] args) { - SpringApplication.run(DemoApplication.class, args); - } - - @Override - public void run(String... args) throws Exception { - log.info("Create default types values"); - final var type1 = typeService.create(new TypeEntity(null, "Апартаменты")); - final var type2 = typeService.create(new TypeEntity(null, "Таунхауз")); - final var type3 = typeService.create(new TypeEntity(null, "Пентхауз")); - final var type4 = typeService.create(new TypeEntity(null, "Квартира")); - - final var user1 = usersService.create(new UserEntity(null, "Иван", - "ivan@mail.ru", "+79048756587", "1")); - final var user2 = usersService.create(new UserEntity(null, "Пётр", - "ivan@mail.ru", "+79048756587", "1232")); - - log.info("Create default items values"); - - houseService.create(user1.getId(), new HouseEntity(null, type4, user1, "Квартира1", - "Удобная квартира в центре города", 49999.00)); - houseService.create(user1.getId(), new HouseEntity(null, type1, user1, "Квартира2", - "Удобная квартира на севере", 129999.00)); - houseService.create(user1.getId(), new HouseEntity(null, type4, user1, "Квартира3", - "Квартира с большой парковкой", 15450.50)); - houseService.create(user2.getId(), new HouseEntity(null, type2, user2, "Апартаменты", - "Апартаменты на 24 этаже", 69900.50)); - houseService.create(user2.getId(), new HouseEntity(null, type2, user2, "Пентауз", - "Дорогой пентхауз", 150000.00)); - houseService.create(user1.getId(), new HouseEntity(null, type3, user1, "Таунхауз", - "Большой бассейн", 75000.00)); - houseService.create(user2.getId(), new HouseEntity(null, type3, user2, "Пентауз", - "Для каждого!", 67800.00)); - - usersService.create(new UserEntity(null, "Иван", - "ivan@mail.ru", "+79048756587", "1")); - usersService.create(new UserEntity(null, "Пётр", - "petr@mail.ru", "89057655257", "12345")); - usersService.create(new UserEntity(null, "Сергей", - "serg79@mail.ru", "95-85-72", "1234")); - usersService.create(new UserEntity(null, "Джеймс", - "jaims21@mail.ru", "89047856987", "jaen12")); - } -} diff --git a/Lab2_2/src/main/java/com/example/demo/core/error/NotFoundException.java b/Lab2_2/src/main/java/com/example/demo/core/error/NotFoundException.java deleted file mode 100644 index 586af3c..0000000 --- a/Lab2_2/src/main/java/com/example/demo/core/error/NotFoundException.java +++ /dev/null @@ -1,7 +0,0 @@ -package com.example.demo.core.error; - -public class NotFoundException extends RuntimeException { - public NotFoundException(Long id) { - super(String.format("Entity with id [%s] is not found or not exists", id)); - } -} diff --git a/Lab2_2/src/main/java/com/example/demo/core/model/BaseEntity.java b/Lab2_2/src/main/java/com/example/demo/core/model/BaseEntity.java deleted file mode 100644 index 674ddfb..0000000 --- a/Lab2_2/src/main/java/com/example/demo/core/model/BaseEntity.java +++ /dev/null @@ -1,20 +0,0 @@ -package com.example.demo.core.model; - -public abstract class BaseEntity { - protected Long id; - - protected BaseEntity() { - } - - protected BaseEntity(Long id) { - this.id = id; - } - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } -} diff --git a/Lab2_2/src/main/java/com/example/demo/core/repository/CommonRepository.java b/Lab2_2/src/main/java/com/example/demo/core/repository/CommonRepository.java deleted file mode 100644 index 85e1e6d..0000000 --- a/Lab2_2/src/main/java/com/example/demo/core/repository/CommonRepository.java +++ /dev/null @@ -1,17 +0,0 @@ -package com.example.demo.core.repository; - -import java.util.List; - -public interface CommonRepository { - List getAll(); - - E get(T id); - - E create(E entity); - - E update(E entity); - - E delete(E entity); - - void deleteAll(); -} diff --git a/Lab2_2/src/main/java/com/example/demo/core/repository/MapRepository.java b/Lab2_2/src/main/java/com/example/demo/core/repository/MapRepository.java deleted file mode 100644 index 6809ac2..0000000 --- a/Lab2_2/src/main/java/com/example/demo/core/repository/MapRepository.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.example.demo.core.repository; - -import java.util.List; -import java.util.Map; -import java.util.TreeMap; - -import com.example.demo.core.model.BaseEntity; - -public abstract class MapRepository implements CommonRepository { - private final Map entities = new TreeMap<>(); - private Long lastId = 0L; - - protected MapRepository() { - } - - @Override - public List getAll() { - return entities.values().stream().toList(); - } - - @Override - public E get(Long id) { - return entities.get(id); - } - - @Override - public E create(E entity) { - lastId++; - entity.setId(lastId); - entities.put(lastId, entity); - return entity; - } - - @Override - public E update(E entity) { - if (get(entity.getId()) == null) { - return null; - } - entities.put(entity.getId(), entity); - return entity; - } - - @Override - public E delete(E entity) { - if (get(entity.getId()) == null) { - return null; - } - entities.remove(entity.getId()); - return entity; - } - - @Override - public void deleteAll() { - lastId = 0L; - entities.clear(); - } -} diff --git a/Lab2_2/src/main/java/com/example/demo/house/repository/HouseRepository.java b/Lab2_2/src/main/java/com/example/demo/house/repository/HouseRepository.java deleted file mode 100644 index 21b74da..0000000 --- a/Lab2_2/src/main/java/com/example/demo/house/repository/HouseRepository.java +++ /dev/null @@ -1,11 +0,0 @@ -package com.example.demo.house.repository; - -import org.springframework.stereotype.Repository; - -import com.example.demo.core.repository.MapRepository; -import com.example.demo.house.model.HouseEntity; - -@Repository -public class HouseRepository extends MapRepository { - -} diff --git a/Lab2_2/src/main/java/com/example/demo/house/service/HouseService.java b/Lab2_2/src/main/java/com/example/demo/house/service/HouseService.java deleted file mode 100644 index ddaa54b..0000000 --- a/Lab2_2/src/main/java/com/example/demo/house/service/HouseService.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.example.demo.house.service; - -import java.util.List; -import java.util.Optional; - -import org.springframework.stereotype.Service; - -import com.example.demo.core.error.NotFoundException; -import com.example.demo.house.model.HouseEntity; -import com.example.demo.house.repository.HouseRepository; -import com.example.demo.users.model.UserEntity; -import com.example.demo.users.service.UsersService; - -@Service -public class HouseService { - private final HouseRepository repository; - private final UsersService userService; - - public HouseService(HouseRepository repository, UsersService usersService) { - this.repository = repository; - this.userService = usersService; - } - - public List getAllHouses() { - return repository.getAll(); - } - - public List getAll(Long typeId, Long userId) { - final UserEntity user = userService.get(userId); - if (typeId > 0) { - return repository.getAll().stream() - .filter(house -> house.getType().getId().equals(typeId)) - .filter(house -> house.getUser().equals(user)) - .toList(); - } - - return repository.getAll().stream() - .filter(house -> house.getUser().equals(user)) - .toList(); - } - - public HouseEntity get(Long id, Long userId) { - final UserEntity user = userService.get(userId); - final HouseEntity house = Optional.ofNullable(repository.get(id)).orElseThrow(() -> new NotFoundException(id)); - if (!house.getUser().equals(user)) { - throw new NotFoundException(id); - } - return house; - } - - public HouseEntity create(Long userId, HouseEntity entity) { - final UserEntity user = userService.get(userId); - entity.setUser(user); - return repository.create(entity); - } - - public HouseEntity update(Long id, Long userId, HouseEntity entity) { - userService.get(userId); - final HouseEntity existEntity = get(id, userId); - existEntity.setTitle(entity.getTitle()); - existEntity.setDescription(entity.getDescription()); - existEntity.setPrice(entity.getPrice()); - existEntity.setType(entity.getType()); - return repository.update(existEntity); - } - - public HouseEntity delete(Long id, Long userId) { - userService.get(userId); - final HouseEntity existEntity = get(id, userId); - return repository.delete(existEntity); - } -} diff --git a/Lab2_2/src/main/java/com/example/demo/speaker/api/SpeakerController.java b/Lab2_2/src/main/java/com/example/demo/speaker/api/SpeakerController.java deleted file mode 100644 index 293296d..0000000 --- a/Lab2_2/src/main/java/com/example/demo/speaker/api/SpeakerController.java +++ /dev/null @@ -1,23 +0,0 @@ -package com.example.demo.speaker.api; - -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import com.example.demo.speaker.service.SpeakerService; - -@RestController -public class SpeakerController { - private final SpeakerService speakerService; - - public SpeakerController(SpeakerService speakerService) { - this.speakerService = speakerService; - } - - @GetMapping - public String hello( - @RequestParam(value = "name", defaultValue = "Мир") String name, - @RequestParam(value = "lang", defaultValue = "ru") String lang) { - return speakerService.say(name, lang); - } -} diff --git a/Lab2_2/src/main/java/com/example/demo/speaker/configuration/SpeakerConfiguration.java b/Lab2_2/src/main/java/com/example/demo/speaker/configuration/SpeakerConfiguration.java deleted file mode 100644 index 0ef7cda..0000000 --- a/Lab2_2/src/main/java/com/example/demo/speaker/configuration/SpeakerConfiguration.java +++ /dev/null @@ -1,27 +0,0 @@ -package com.example.demo.speaker.configuration; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; - -import com.example.demo.speaker.domain.Speaker; -import com.example.demo.speaker.domain.SpeakerEng; -import com.example.demo.speaker.domain.SpeakerRus; - -@Configuration -public class SpeakerConfiguration { - private final Logger log = LoggerFactory.getLogger(SpeakerConfiguration.class); - - @Bean(value = "ru", initMethod = "init", destroyMethod = "destroy") - public SpeakerRus createRusSpeaker() { - log.info("Call createRusSpeaker()"); - return new SpeakerRus(); - } - - @Bean(value = "en") - public Speaker createEngSpeaker() { - log.info("Call createEngSpeaker()"); - return new SpeakerEng(); - } -} diff --git a/Lab2_2/src/main/java/com/example/demo/speaker/domain/Speaker.java b/Lab2_2/src/main/java/com/example/demo/speaker/domain/Speaker.java deleted file mode 100644 index 27a0a29..0000000 --- a/Lab2_2/src/main/java/com/example/demo/speaker/domain/Speaker.java +++ /dev/null @@ -1,5 +0,0 @@ -package com.example.demo.speaker.domain; - -public interface Speaker { - String say(); -} diff --git a/Lab2_2/src/main/java/com/example/demo/speaker/domain/SpeakerDeu.java b/Lab2_2/src/main/java/com/example/demo/speaker/domain/SpeakerDeu.java deleted file mode 100644 index 5909864..0000000 --- a/Lab2_2/src/main/java/com/example/demo/speaker/domain/SpeakerDeu.java +++ /dev/null @@ -1,28 +0,0 @@ -package com.example.demo.speaker.domain; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.stereotype.Component; - -import jakarta.annotation.PostConstruct; -import jakarta.annotation.PreDestroy; - -@Component(value = "de") -public class SpeakerDeu implements Speaker { - private final Logger log = LoggerFactory.getLogger(SpeakerDeu.class); - - @Override - public String say() { - return "Hallo"; - } - - @PostConstruct - public void init() { - log.info("SpeakerDeu.init()"); - } - - @PreDestroy - public void destroy() { - log.info("SpeakerDeu.destroy()"); - } -} diff --git a/Lab2_2/src/main/java/com/example/demo/speaker/domain/SpeakerEng.java b/Lab2_2/src/main/java/com/example/demo/speaker/domain/SpeakerEng.java deleted file mode 100644 index a310403..0000000 --- a/Lab2_2/src/main/java/com/example/demo/speaker/domain/SpeakerEng.java +++ /dev/null @@ -1,26 +0,0 @@ -package com.example.demo.speaker.domain; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; -import org.springframework.beans.factory.DisposableBean; -import org.springframework.beans.factory.InitializingBean; - -public class SpeakerEng implements Speaker, InitializingBean, DisposableBean { - private final Logger log = LoggerFactory.getLogger(SpeakerEng.class); - - @Override - public String say() { - return "Hello"; - } - - @Override - public void afterPropertiesSet() { - log.info("SpeakerEng.afterPropertiesSet()"); - } - - @Override - public void destroy() { - log.info("SpeakerEng.destroy()"); - - } -} diff --git a/Lab2_2/src/main/java/com/example/demo/speaker/domain/SpeakerRus.java b/Lab2_2/src/main/java/com/example/demo/speaker/domain/SpeakerRus.java deleted file mode 100644 index d6ed18e..0000000 --- a/Lab2_2/src/main/java/com/example/demo/speaker/domain/SpeakerRus.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.example.demo.speaker.domain; - -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class SpeakerRus implements Speaker { - private final Logger log = LoggerFactory.getLogger(SpeakerRus.class); - - @Override - public String say() { - return "Привет"; - } - - public void init() { - log.info("SpeakerRus.init()"); - } - - public void destroy() { - log.info("SpeakerRus.destroy()"); - } -} diff --git a/Lab2_2/src/main/java/com/example/demo/speaker/service/SpeakerService.java b/Lab2_2/src/main/java/com/example/demo/speaker/service/SpeakerService.java deleted file mode 100644 index de3a463..0000000 --- a/Lab2_2/src/main/java/com/example/demo/speaker/service/SpeakerService.java +++ /dev/null @@ -1,21 +0,0 @@ -package com.example.demo.speaker.service; - -import org.springframework.context.ApplicationContext; -import org.springframework.stereotype.Service; - -import com.example.demo.speaker.domain.Speaker; - -@Service -public class SpeakerService { - private final ApplicationContext applicationContext; - - public SpeakerService(ApplicationContext applicationContext) { - this.applicationContext = applicationContext; - } - - public String say(String name, String lang) { - @SuppressWarnings("null") - final Speaker speaker = (Speaker) applicationContext.getBean(lang); - return String.format("%s, %s!", speaker.say(), name); - } -} diff --git a/Lab2_2/src/main/java/com/example/demo/types/repository/TypeRepository.java b/Lab2_2/src/main/java/com/example/demo/types/repository/TypeRepository.java deleted file mode 100644 index 1c29ea2..0000000 --- a/Lab2_2/src/main/java/com/example/demo/types/repository/TypeRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.example.demo.types.repository; - -import org.springframework.stereotype.Repository; - -import com.example.demo.core.repository.MapRepository; -import com.example.demo.types.model.TypeEntity; - -@Repository -public class TypeRepository extends MapRepository { -} diff --git a/Lab2_2/src/main/java/com/example/demo/types/service/TypeService.java b/Lab2_2/src/main/java/com/example/demo/types/service/TypeService.java deleted file mode 100644 index e71b030..0000000 --- a/Lab2_2/src/main/java/com/example/demo/types/service/TypeService.java +++ /dev/null @@ -1,43 +0,0 @@ -package com.example.demo.types.service; - -import java.util.List; -import java.util.Optional; - -import org.springframework.stereotype.Service; - -import com.example.demo.core.error.NotFoundException; -import com.example.demo.types.model.TypeEntity; -import com.example.demo.types.repository.TypeRepository; - -@Service -public class TypeService { - private final TypeRepository repository; - - public TypeService(TypeRepository repository) { - this.repository = repository; - } - - public List getAll() { - return repository.getAll(); - } - - public TypeEntity get(Long id) { - return Optional.ofNullable(repository.get(id)) - .orElseThrow(() -> new NotFoundException(id)); - } - - public TypeEntity create(TypeEntity entity) { - return repository.create(entity); - } - - public TypeEntity update(Long id, TypeEntity entity) { - final TypeEntity existsEntity = get(id); - existsEntity.setName(entity.getName()); - return repository.update(existsEntity); - } - - public TypeEntity delete(Long id) { - final TypeEntity existsEntity = get(id); - return repository.delete(existsEntity); - } -} diff --git a/Lab2_2/src/main/java/com/example/demo/users/model/UserEntity.java b/Lab2_2/src/main/java/com/example/demo/users/model/UserEntity.java deleted file mode 100644 index ee97eeb..0000000 --- a/Lab2_2/src/main/java/com/example/demo/users/model/UserEntity.java +++ /dev/null @@ -1,75 +0,0 @@ -package com.example.demo.users.model; - -import java.util.Objects; - -import com.example.demo.core.model.BaseEntity; - -public class UserEntity extends BaseEntity { - private String name; - private String email; - private String numberphone; - private String password; - - public UserEntity() { - super(); - } - - public UserEntity(Long id, String name, String email, String numberphone, String password) { - super(id); - this.name = name; - this.email = email; - this.numberphone = numberphone; - this.password = password; - } - - public String getName() { - return name; - } - - public void setName(String name) { - this.name = name; - } - - public String getEmail() { - return email; - } - - public void setEmail(String email) { - this.email = email; - } - - public String getNumberPhone() { - return numberphone; - } - - public void setNumberPhone(String numberphone) { - this.numberphone = numberphone; - } - - public String getPassword() { - return password; - } - - public void setPassword(String password) { - this.password = password; - } - - @Override - public int hashCode() { - return Objects.hash(id, name, email, numberphone, password); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null || getClass() != obj.getClass()) - return false; - final UserEntity other = (UserEntity) obj; - return Objects.equals(other.getId(), id) - && Objects.equals(other.getName(), name) - && Objects.equals(other.getEmail(), email) - && Objects.equals(other.getNumberPhone(), numberphone) - && Objects.equals(other.getPassword(), password); - } -} diff --git a/Lab2_2/src/main/java/com/example/demo/users/repository/UsersRepository.java b/Lab2_2/src/main/java/com/example/demo/users/repository/UsersRepository.java deleted file mode 100644 index 096f31a..0000000 --- a/Lab2_2/src/main/java/com/example/demo/users/repository/UsersRepository.java +++ /dev/null @@ -1,10 +0,0 @@ -package com.example.demo.users.repository; - -import org.springframework.stereotype.Repository; - -import com.example.demo.core.repository.MapRepository; -import com.example.demo.users.model.UserEntity; - -@Repository -public class UsersRepository extends MapRepository { -} diff --git a/Lab2_2/src/main/java/com/example/demo/users/service/UsersService.java b/Lab2_2/src/main/java/com/example/demo/users/service/UsersService.java deleted file mode 100644 index d1a770c..0000000 --- a/Lab2_2/src/main/java/com/example/demo/users/service/UsersService.java +++ /dev/null @@ -1,46 +0,0 @@ -package com.example.demo.users.service; - -import java.util.List; -import java.util.Optional; - -import org.springframework.stereotype.Service; - -import com.example.demo.core.error.NotFoundException; -import com.example.demo.users.model.UserEntity; -import com.example.demo.users.repository.UsersRepository; - -@Service -public class UsersService { - private final UsersRepository repository; - - public UsersService(UsersRepository repository) { - this.repository = repository; - } - - public List getAll() { - return repository.getAll(); - } - - public UserEntity get(Long id) { - return Optional.ofNullable(repository.get(id)) - .orElseThrow(() -> new NotFoundException(id)); - } - - public UserEntity create(UserEntity entity) { - return repository.create(entity); - } - - public UserEntity update(Long id, UserEntity entity) { - final UserEntity existsEntity = get(id); - existsEntity.setName(entity.getName()); - existsEntity.setEmail(entity.getEmail()); - existsEntity.setNumberPhone(entity.getNumberPhone()); - existsEntity.setPassword(entity.getPassword()); - return repository.update(existsEntity); - } - - public UserEntity delete(Long id) { - final UserEntity existsEntity = get(id); - return repository.delete(existsEntity); - } -} diff --git a/Lab2_2/src/main/resources/application.properties b/Lab2_2/src/main/resources/application.properties deleted file mode 100644 index 8b13789..0000000 --- a/Lab2_2/src/main/resources/application.properties +++ /dev/null @@ -1 +0,0 @@ - diff --git a/Lab2_2/src/test/java/com/example/demo/HouseServiceTests.java b/Lab2_2/src/test/java/com/example/demo/HouseServiceTests.java deleted file mode 100644 index 51f3f1d..0000000 --- a/Lab2_2/src/test/java/com/example/demo/HouseServiceTests.java +++ /dev/null @@ -1,52 +0,0 @@ -package com.example.demo; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; -import org.junit.jupiter.api.Order; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestMethodOrder; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import com.example.demo.core.error.NotFoundException; -import com.example.demo.house.model.HouseEntity; -import com.example.demo.house.service.HouseService; - -@SpringBootTest -@TestMethodOrder(OrderAnnotation.class) -class HouseServiceTests { - @Autowired - private HouseService houseService; - - @Test - void getTest() { - Assertions.assertThrows(NotFoundException.class, () -> houseService.get(0L, 0L)); - } - - @Test - @Order(1) - void createTest() { - houseService.create(1L, new HouseEntity(null, null, null, "fewfe", "cool",210.0)); - houseService.create(2L, new HouseEntity(null, null, null, "weffew", "cool efwfew", 210.0)); - houseService.create(3L, new HouseEntity(null, null, null, "efwfew", "very cool wffwe", 2100.0)); - - Assertions.assertEquals(5, houseService.getAll(0L, 1L).size()); - } - - @Test - @Order(2) - void updateTest() { - final HouseEntity newHouse = new HouseEntity(null, null, null, "House", "cool house", 1500.0); - final HouseEntity upHouse = houseService.update(2L, 1L, newHouse); - Assertions.assertEquals(newHouse.getTitle(), upHouse.getTitle()); - Assertions.assertEquals(newHouse.getDescription(), upHouse.getDescription()); - Assertions.assertEquals(newHouse.getPrice(), upHouse.getPrice()); - } - - @Test - @Order(3) - void deleteTest() { - houseService.delete(1L, 1L); - Assertions.assertEquals(4, houseService.getAll(0L, 1L).size()); - } -} \ No newline at end of file diff --git a/Lab2_2/src/test/java/com/example/demo/SpeakerSrviceTests.java b/Lab2_2/src/test/java/com/example/demo/SpeakerSrviceTests.java deleted file mode 100644 index d8624d3..0000000 --- a/Lab2_2/src/test/java/com/example/demo/SpeakerSrviceTests.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.example.demo; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.NoSuchBeanDefinitionException; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import com.example.demo.speaker.service.SpeakerService; - -@SpringBootTest -class SpeakerSrviceTests { - @Autowired - SpeakerService speakerService; - - @Test - void testSpeakerRus() { - final String res = speakerService.say("Мир", "ru"); - Assertions.assertEquals("Привет, Мир!", res); - } - - @Test - void testSpeakerEng() { - final String res = speakerService.say("World", "en"); - Assertions.assertEquals("Hello, World!", res); - } - - @Test - void testSpeakerDeu() { - final String res = speakerService.say("Welt", "de"); - Assertions.assertEquals("Hallo, Welt!", res); - } - - @Test - void testSpeakerErrorWired() { - Assertions.assertThrows(NoSuchBeanDefinitionException.class, () -> speakerService.say("Мир", "rus")); - } -} diff --git a/Lab2_2/src/test/java/com/example/demo/TypeServiceTests.java b/Lab2_2/src/test/java/com/example/demo/TypeServiceTests.java deleted file mode 100644 index 5d78b02..0000000 --- a/Lab2_2/src/test/java/com/example/demo/TypeServiceTests.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.example.demo; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; -import org.junit.jupiter.api.Order; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestMethodOrder; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import com.example.demo.core.error.NotFoundException; -import com.example.demo.types.model.TypeEntity; -import com.example.demo.types.service.TypeService; - -@SpringBootTest -@TestMethodOrder(OrderAnnotation.class) -class TypeServiceTests { - @Autowired - private TypeService typeService; - - @Test - void getTest() { - Assertions.assertThrows(NotFoundException.class, () -> typeService.get(0L)); - } - - @Test - @Order(1) - void createTest() { - typeService.create(new TypeEntity(null, "Ноутбук")); - typeService.create(new TypeEntity(null, "Телефон")); - Assertions.assertEquals(6, typeService.getAll().size()); - } - - @Test - @Order(2) - void updateTest() { - final String test = "TEST"; - final TypeEntity entity = typeService.get(3L); - final String oldName = entity.getName(); - final TypeEntity newEntity = typeService.update(3L, new TypeEntity(1L, test)); - Assertions.assertEquals(6, typeService.getAll().size()); - Assertions.assertEquals(newEntity, typeService.get(3L)); - Assertions.assertEquals(test, newEntity.getName()); - Assertions.assertNotEquals(oldName, newEntity.getName()); - } - - @Test - @Order(3) - void deleteTest() { - typeService.delete(3L); - Assertions.assertEquals(5, typeService.getAll().size()); - final TypeEntity last = typeService.get(2L); - Assertions.assertEquals(2L, last.getId()); - - final TypeEntity newEntity = typeService.create(new TypeEntity(null, "Игровая приставка")); - Assertions.assertEquals(6, typeService.getAll().size()); - Assertions.assertEquals(7, newEntity.getId()); - } -} diff --git a/Lab2_2/src/test/java/com/example/demo/UsersServiceTests.java b/Lab2_2/src/test/java/com/example/demo/UsersServiceTests.java deleted file mode 100644 index df845a9..0000000 --- a/Lab2_2/src/test/java/com/example/demo/UsersServiceTests.java +++ /dev/null @@ -1,59 +0,0 @@ -package com.example.demo; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.MethodOrderer.OrderAnnotation; -import org.junit.jupiter.api.Order; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestMethodOrder; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; - -import com.example.demo.core.error.NotFoundException; -import com.example.demo.users.model.UserEntity; -import com.example.demo.users.service.UsersService; - -@SpringBootTest -@TestMethodOrder(OrderAnnotation.class) -class UsersServiceTests { - @Autowired - private UsersService userService; - - @Test - void getTest() { - Assertions.assertThrows(NotFoundException.class, () -> userService.get(0L)); - } - - @Test - @Order(1) - void createTest() { - userService.create(new UserEntity(null, "Иван", "", "", "")); - userService.create(new UserEntity(null, "Иван", "", "", "")); - Assertions.assertEquals(8, userService.getAll().size()); - } - - @Test - @Order(2) - void updateTest() { - final String test = "TEST"; - final UserEntity entity = userService.get(3L); - final String oldName = entity.getName(); - final UserEntity newEntity = userService.update(3L, new UserEntity(1L, test, "test", "test", "test")); - Assertions.assertEquals(8, userService.getAll().size()); - Assertions.assertEquals(newEntity, userService.get(3L)); - Assertions.assertEquals(test, newEntity.getName()); - Assertions.assertNotEquals(oldName, newEntity.getName()); - } - - @Test - @Order(3) - void deleteTest() { - userService.delete(3L); - Assertions.assertEquals(7, userService.getAll().size()); - final UserEntity last = userService.get(2L); - Assertions.assertEquals(2L, last.getId()); - - final UserEntity newEntity = userService.create(new UserEntity(null, "Игровая приставка", "", "", "")); - Assertions.assertEquals(8, userService.getAll().size()); - Assertions.assertEquals(9, newEntity.getId()); - } -}