diff --git a/gradle/wrapper/gradle-wrapper.jar b/gradle/wrapper/gradle-wrapper.jar deleted file mode 100644 index d64cd49..0000000 Binary files a/gradle/wrapper/gradle-wrapper.jar and /dev/null differ diff --git a/gradle/wrapper/gradle-wrapper.properties b/gradle/wrapper/gradle-wrapper.properties deleted file mode 100644 index 97f9ad6..0000000 --- a/gradle/wrapper/gradle-wrapper.properties +++ /dev/null @@ -1,23 +0,0 @@ -# -# Copyright 2012-2024 the original author or authors. -# -# Licensed 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 -# -# https://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. -# - -distributionBase=GRADLE_USER_HOME -distributionPath=wrapper/dists -distributionUrl=https\://services.gradle.org/distributions/gradle-8.6-bin.zip -networkTimeout=10000 -validateDistributionUrl=true -zipStoreBase=GRADLE_USER_HOME -zipStorePath=wrapper/dists diff --git a/src/main/java/com/example/demo/itemCategories/model/ItemEntity.java b/src/main/java/com/example/demo/itemCategories/model/CategoriesEntity.java similarity index 83% rename from src/main/java/com/example/demo/itemCategories/model/ItemEntity.java rename to src/main/java/com/example/demo/itemCategories/model/CategoriesEntity.java index 239d2de..7b1d846 100644 --- a/src/main/java/com/example/demo/itemCategories/model/ItemEntity.java +++ b/src/main/java/com/example/demo/itemCategories/model/CategoriesEntity.java @@ -1,21 +1,19 @@ package com.example.demo.itemCategories.model; - import java.util.Objects; - import com.example.demo.core.model.BaseEntity; import com.example.demo.types.model.TypeEntity; -public class ItemEntity extends BaseEntity { +public class CategoriesEntity extends BaseEntity { private TypeEntity type; // private Double price; // private Integer count; private String name; - public ItemEntity() { + public CategoriesEntity() { super(); } - public ItemEntity(Long id, TypeEntity type, String name) { + public CategoriesEntity(Long id, TypeEntity type, String name) { super(id); this.type = type; this.name = name; @@ -48,7 +46,7 @@ public class ItemEntity extends BaseEntity { return true; if (obj == null || getClass() != obj.getClass()) return false; - final ItemEntity other = (ItemEntity) obj; + final CategoriesEntity other = (CategoriesEntity) obj; return Objects.equals(other.getId(), id) && Objects.equals(other.getType(), type) && Objects.equals(other.getName(), name); diff --git a/src/main/java/com/example/demo/itemOrders/model/OrderEntity.java b/src/main/java/com/example/demo/itemOrders/model/OrderEntity.java deleted file mode 100644 index 4186482..0000000 --- a/src/main/java/com/example/demo/itemOrders/model/OrderEntity.java +++ /dev/null @@ -1,66 +0,0 @@ -package com.example.demo.itemOrders.model; - -import java.util.ArrayList; -import java.util.List; -import java.util.Objects; - -import com.example.demo.core.model.BaseEntity; -import com.example.demo.itemProducts.model.ProductsEntity; -import com.example.demo.itemUsers.model.UserEntity; -import com.example.demo.types.model.TypeEntity; - -public class OrderEntity extends BaseEntity { - private TypeEntity type; - private UserEntity user; - private List products = new ArrayList<>(); - - public OrderEntity() { - super(); - } - - public OrderEntity(Long id, TypeEntity type, UserEntity user, List products) { - super(id); - this.type = type; - this.user = user; - this.products = products; - } - - public TypeEntity getType() { - return type; - } - - public void setType(TypeEntity type) { - this.type = type; - } - - public UserEntity getUser() { - return user; - } - - public void setUser(UserEntity user) { - this.user = user; - } - - // добавить методы добавить и удалить продукт, и получить продукт - public List getProducts() { - return products; - } - - @Override - public int hashCode() { - return Objects.hash(id, type, login, password); - } - - @Override - public boolean equals(Object obj) { - if (this == obj) - return true; - if (obj == null || getClass() != obj.getClass()) - return false; - final OrderEntity other = (OrderEntity) obj; - return Objects.equals(other.getId(), id) - && Objects.equals(other.getType(), type) - && Objects.equals(other.getLogin(), login) - && Objects.equals(other.getPassword(), password); - } -} diff --git a/src/main/java/com/example/demo/itemOrders/model/OrdersEntity.java b/src/main/java/com/example/demo/itemOrders/model/OrdersEntity.java new file mode 100644 index 0000000..4a6731e --- /dev/null +++ b/src/main/java/com/example/demo/itemOrders/model/OrdersEntity.java @@ -0,0 +1,82 @@ +package com.example.demo.itemOrders.model; +import java.sql.Date; +import java.util.Objects; +import com.example.demo.core.model.BaseEntity; +import com.example.demo.types.model.TypeEntity; + +public class OrdersEntity extends BaseEntity { + private TypeEntity type; + private Integer categoriesId; + private Double price; + private Integer count; + private Date date; + + public OrdersEntity() { + super(); + } + + public OrdersEntity(Long id, TypeEntity type, Integer categoriesId, Double price, Integer count, Date date) { + super(id); + this.type = type; + this.categoriesId = categoriesId; + this.price = price; + this.count = count; + this.date = date; + } + + public TypeEntity getType() { + return type; + } + + public void setType(TypeEntity type) { + this.type = type; + } + public Integer getCategoriesId() { + return categoriesId; + } + + public void setCategoriesId(Integer categoriesId) { + this.categoriesId = categoriesId; + } + public Double getPrice() { + return price; + } + + public void setPrice(Double price) { + this.price = price; + } + + public Integer getCount() { + return count; + } + + public void setCount(Integer count) { + this.count = count; + } + public Date getDate() { + return date; + } + + public void setDate(Date date) { + this.date = date; + } + @Override + public int hashCode() { + return Objects.hash(id, type, categoriesId, price, count); + } + + @Override + public boolean equals(Object obj) { + if (this == obj) + return true; + if (obj == null || getClass() != obj.getClass()) + return false; + final OrdersEntity other = (OrdersEntity) obj; + return Objects.equals(other.getId(), id) + && Objects.equals(other.getType(), type) + && Objects.equals(other.getCategoriesId(), categoriesId) + && Objects.equals(other.getPrice(), price) + && Objects.equals(other.getCount(), count) + && Objects.equals(other.getDate(), date); + } +} diff --git a/src/main/java/com/example/demo/itemProducts/model/ProductsEntity.java b/src/main/java/com/example/demo/itemProducts/model/ProductsEntity.java index dcae8f6..385b920 100644 --- a/src/main/java/com/example/demo/itemProducts/model/ProductsEntity.java +++ b/src/main/java/com/example/demo/itemProducts/model/ProductsEntity.java @@ -5,20 +5,24 @@ import java.util.Objects; import com.example.demo.core.model.BaseEntity; import com.example.demo.types.model.TypeEntity; -public class ProductsEntity extends BaseEntity { +public class ProductsEntity extends BaseEntity{ private TypeEntity type; + private Integer categoriesId; private Double price; private Integer count; + private Double sum; public ProductsEntity() { super(); } - public ProductsEntity(Long id, TypeEntity type, Double price, Integer count) { + public ProductsEntity(Long id, TypeEntity type, Integer categoriesId, Double price, Integer count, Double sum) { super(id); this.type = type; + this.categoriesId = categoriesId; this.price = price; this.count = count; + this.sum = sum; } public TypeEntity getType() { @@ -28,7 +32,13 @@ public class ProductsEntity extends BaseEntity { public void setType(TypeEntity type) { this.type = type; } + public Integer getCategoriesId() { + return categoriesId; + } + public void setCategoriesId(Integer categoriesId) { + this.categoriesId = categoriesId; + } public Double getPrice() { return price; } @@ -44,10 +54,16 @@ public class ProductsEntity extends BaseEntity { public void setCount(Integer count) { this.count = count; } + public Double getSum() { + return sum; + } + public void setSum(Double sum) { + this.sum = sum; + } @Override public int hashCode() { - return Objects.hash(id, type, price, count); + return Objects.hash(id, type, categoriesId, price, count, sum); } @Override @@ -58,8 +74,10 @@ public class ProductsEntity extends BaseEntity { return false; final ProductsEntity other = (ProductsEntity) obj; return Objects.equals(other.getId(), id) - && Objects.equals(other.getType(), type) - && Objects.equals(other.getPrice(), price) - && Objects.equals(other.getCount(), count); + && Objects.equals(other.getType(), type) + && Objects.equals(other.getCategoriesId(), categoriesId) + && Objects.equals(other.getPrice(), price) + && Objects.equals(other.getCount(), count) + && Objects.equals(other.getSum(), sum); } } diff --git a/src/main/java/com/example/demo/itemUsers/api/UserController.java b/src/main/java/com/example/demo/itemUsers/api/UserController.java deleted file mode 100644 index 9e41e69..0000000 --- a/src/main/java/com/example/demo/itemUsers/api/UserController.java +++ /dev/null @@ -1,70 +0,0 @@ -package com.example.demo.itemUsers.api; - -import java.util.List; - -import org.modelmapper.ModelMapper; -import org.springframework.web.bind.annotation.DeleteMapping; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.PutMapping; -import org.springframework.web.bind.annotation.RequestBody; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RequestParam; -import org.springframework.web.bind.annotation.RestController; - -import com.example.demo.core.configuration.Constants; -import com.example.demo.itemUsers.model.UserEntity; -import com.example.demo.itemUsers.service.UserService; -import com.example.demo.types.service.TypeService; - -import jakarta.validation.Valid; - -@RestController -@RequestMapping(Constants.API_URL + "/item") -public class UserController { - private final UserService itemService; - private final TypeService typeService; - private final ModelMapper modelMapper; - - public UserController(UserService itemService, TypeService typeService, ModelMapper modelMapper) { - this.itemService = itemService; - this.typeService = typeService; - this.modelMapper = modelMapper; - } - - private UserDto toDto(OrderEntity entity) { - return modelMapper.map(entity, UserDto.class); - } - - private OrderEntity toEntity(UserDto dto) { - final OrderEntity entity = modelMapper.map(dto, OrderEntity.class); - entity.setType(typeService.get(dto.getTypeId())); - return entity; - } - - @GetMapping - public List getAll(@RequestParam(name = "typeId", defaultValue = "0") Long typeId) { - return itemService.getAll(typeId).stream().map(this::toDto).toList(); - } - - @GetMapping("/{id}") - public UserDto get(@PathVariable(name = "id") Long id) { - return toDto(itemService.get(id)); - } - - @PostMapping - public UserDto create(@RequestBody @Valid UserDto dto) { - return toDto(itemService.create(toEntity(dto))); - } - - @PutMapping("/{id}") - public UserDto update(@PathVariable(name = "id") Long id, @RequestBody UserDto dto) { - return toDto(itemService.update(id, toEntity(dto))); - } - - @DeleteMapping("/{id}") - public UserDto delete(@PathVariable(name = "id") Long id) { - return toDto(itemService.delete(id)); - } -} diff --git a/src/main/java/com/example/demo/itemUsers/api/UserDto.java b/src/main/java/com/example/demo/itemUsers/api/UserDto.java deleted file mode 100644 index 3a1c20b..0000000 --- a/src/main/java/com/example/demo/itemUsers/api/UserDto.java +++ /dev/null @@ -1,57 +0,0 @@ -package com.example.demo.itemUsers.api; - -import com.fasterxml.jackson.annotation.JsonProperty; - -import jakarta.validation.constraints.Min; -import jakarta.validation.constraints.NotNull; - -public class UserDto { - @JsonProperty(access = JsonProperty.Access.READ_ONLY) - private Long id; - @NotNull - @Min(1) - private Long typeId; - @NotNull - @Min(1) - private Double price; - @NotNull - @Min(1) - private Integer count; - - public Long getId() { - return id; - } - - public void setId(Long id) { - this.id = id; - } - - public Long getTypeId() { - return typeId; - } - - public void setTypeId(Long typeId) { - this.typeId = typeId; - } - - public Double getPrice() { - return price; - } - - public void setPrice(Double price) { - this.price = price; - } - - public Integer getCount() { - return count; - } - - public void setCount(Integer count) { - this.count = count; - } - - @JsonProperty(access = JsonProperty.Access.READ_ONLY) - public Double getSum() { - return price * count; - } -} diff --git a/src/main/java/com/example/demo/itemUsers/model/UserEntity.java b/src/main/java/com/example/demo/itemUsers/model/UsersEntity.java similarity index 86% rename from src/main/java/com/example/demo/itemUsers/model/UserEntity.java rename to src/main/java/com/example/demo/itemUsers/model/UsersEntity.java index 8928ef1..6d18213 100644 --- a/src/main/java/com/example/demo/itemUsers/model/UserEntity.java +++ b/src/main/java/com/example/demo/itemUsers/model/UsersEntity.java @@ -1,20 +1,18 @@ package com.example.demo.itemUsers.model; - import java.util.Objects; - import com.example.demo.core.model.BaseEntity; import com.example.demo.types.model.TypeEntity; -public class UserEntity extends BaseEntity { +public class UsersEntity extends BaseEntity { private TypeEntity type; private String login; private String password; - public UserEntity() { + public UsersEntity() { super(); } - public UserEntity(Long id, TypeEntity type, String login, String password) { + public UsersEntity(Long id, TypeEntity type, String login, String password) { super(id); this.type = type; this.login = login; @@ -56,7 +54,7 @@ public class UserEntity extends BaseEntity { return true; if (obj == null || getClass() != obj.getClass()) return false; - final UserEntity other = (UserEntity) obj; + final UsersEntity other = (UsersEntity) obj; return Objects.equals(other.getId(), id) && Objects.equals(other.getType(), type) && Objects.equals(other.getLogin(), login) diff --git a/src/main/java/com/example/demo/itemUsers/repository/UserRepository.java b/src/main/java/com/example/demo/itemUsers/repository/UsersRepository.java similarity index 76% rename from src/main/java/com/example/demo/itemUsers/repository/UserRepository.java rename to src/main/java/com/example/demo/itemUsers/repository/UsersRepository.java index ea17089..9b0518d 100644 --- a/src/main/java/com/example/demo/itemUsers/repository/UserRepository.java +++ b/src/main/java/com/example/demo/itemUsers/repository/UsersRepository.java @@ -6,5 +6,5 @@ import com.example.demo.core.repository.MapRepository; import com.example.demo.itemUsers.model.ItemEntity; @Repository -public class UserRepository extends MapRepository { +public class UsersRepository extends MapRepository { } diff --git a/src/main/java/com/example/demo/itemUsers/service/UserService.java b/src/main/java/com/example/demo/itemUsers/service/UserService.java index 9a5eae3..8a2c98c 100644 --- a/src/main/java/com/example/demo/itemUsers/service/UserService.java +++ b/src/main/java/com/example/demo/itemUsers/service/UserService.java @@ -7,18 +7,18 @@ import java.util.Optional; import org.springframework.stereotype.Service; import com.example.demo.core.error.NotFoundException; -import com.example.demo.itemUsers.model.UserEntity; -import com.example.demo.itemUsers.repository.UserRepository; +import com.example.demo.itemUsers.model.UsersEntity; +import com.example.demo.itemUsers.repository.UsersRepository; @Service public class UserService { - private final UserRepository repository; + private final UsersRepository repository; - public UserService(UserRepository repository) { + public UserService(UsersRepository repository) { this.repository = repository; } - public List getAll(Long typeId) { + public List getAll(Long typeId) { if (Objects.equals(typeId, 0L)) { return repository.getAll(); } @@ -27,25 +27,25 @@ public class UserService { .toList(); } - public UserEntity get(Long id) { + public UsersEntity get(Long id) { return Optional.ofNullable(repository.get(id)) .orElseThrow(() -> new NotFoundException(id)); } - public UserEntity create(UserEntity entity) { + public UsersEntity create(UsersEntity entity) { return repository.create(entity); } - public UserEntity update(Long id, UserEntity entity) { - final UserEntity existsEntity = get(id); + public UsersEntity update(Long id, UsersEntity entity) { + final UsersEntity existsEntity = get(id); existsEntity.setType(entity.getType()); existsEntity.setPrice(entity.getPrice()); existsEntity.setCount(entity.getCount()); return repository.update(existsEntity); } - public UserEntity delete(Long id) { - final UserEntity existsEntity = get(id); + public UsersEntity delete(Long id) { + final UsersEntity existsEntity = get(id); return repository.delete(existsEntity); } }