Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Product update product entity #50

Merged
Merged
Show file tree
Hide file tree
Changes from 10 commits
Commits
Show all changes
18 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 0 additions & 20 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1,6 @@
version: '3.9'
services:

#
# Mongo Database
#
mongodb:
image: "mongo:latest"
container_name: mongodb
environment:
- MONGO_INITDB_ROOT_USERNAME=rootuser
- MONGO_INITDB_ROOT_PASSWORD=rootpass
ports:
- '27017:27017'
networks:
- online-store-network
profiles:
- dev
- test
- prod

#
# Postgresql Database
#
Expand Down Expand Up @@ -60,8 +42,6 @@ services:
timeout: 5s
retries: 5
start_period: 40s
depends_on:
- mongodb
deploy:
replicas: 1
networks:
Expand Down
14 changes: 13 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">

<modelVersion>4.0.0</modelVersion>

Expand Down Expand Up @@ -231,6 +231,18 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-jpa</artifactId>
</dependency>

<!-- DataBase dependencies-->
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Пожалуйста, не забывай про пробелы

<!-- Database dependencies -->

<dependency>
<groupId>org.postgresql</groupId>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

зачем нам эта зависимость?
У нас есть зависимость spring-data-jpa. Ее должно хватить. Проверь.

<artifactId>postgresql</artifactId>
<version>42.5.4</version>
</dependency>
<dependency>
<groupId>org.liquibase</groupId>
<artifactId>liquibase-core</artifactId>
<version>4.23.0</version>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

версии всегда прячь в

</dependency>
</dependencies>
<build>
<plugins>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@

import lombok.AllArgsConstructor;

import java.util.UUID;

@Service
@AllArgsConstructor
public class CustomerDtoConverter {
Expand All @@ -17,7 +19,7 @@ public class CustomerDtoConverter {
public CustomerDto convertToDto(final Customer entity) {
AddressDto addressDto = addressDtoConverter.convertToDto(entity.getAddress());
return CustomerDto.builder()
.customerId(entity.getCustomerId())
.customerId(entity.getId().toString())
.firstName(entity.getFirstName())
.lastName(entity.getLastName())
.email(entity.getEmail())
Expand All @@ -28,11 +30,11 @@ public CustomerDto convertToDto(final Customer entity) {
public Customer convertToEntity(final CustomerDto dto) {
Address addressDto = addressDtoConverter.convertToEntity(dto.getAddress());
return Customer.builder()
.customerId(dto.getCustomerId())
.id(UUID.fromString(dto.getCustomerId()))
.firstName(dto.getFirstName())
.lastName(dto.getLastName())
.email(dto.getEmail())
.address(addressDto)
.build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import java.util.Collection;
import java.util.List;
import java.util.Optional;
import java.util.UUID;

import static com.zufar.onlinestore.customer.endpoint.UrlConstants.API_CUSTOMERS;

Expand Down Expand Up @@ -86,10 +87,10 @@ public ResponseEntity<Void> updateCustomer(@PathVariable("id") @NotBlank final S
@RequestBody @Valid @NotNull final CustomerDto updateCustomerRequest) {
log.info("Received updateCustomerRequest to update the Customer with id - {}, updateCustomerRequest - {}.", customerId, updateCustomerRequest);
Customer customerEntity = customerDtoConverter.convertToEntity(updateCustomerRequest);
customerEntity.setCustomerId(customerId);
customerEntity.setId(UUID.fromString(customerId));
customerCrudRepository.save(customerEntity);
log.info("the Customer with id - {} was updated.", customerId);
return ResponseEntity.ok()
.build();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,19 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.UUID;

@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "addresses")
@Table(name = "address")
public class Address {

@Id
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private Long id;
private UUID id;

@Column(name = "line", nullable = false)
private String line;
Expand All @@ -31,4 +33,4 @@ public class Address {

@Column(name = "country", nullable = false)
private String country;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,21 @@
import lombok.Data;
import lombok.NoArgsConstructor;

import java.util.UUID;


@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Entity
@Table(name = "customers")
@Table(name = "customer")
public class Customer {

@Id
@Column(nullable = false)
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private String customerId;
private UUID id;

@Column(name = "first_name", nullable = false)
private String firstName;
Expand All @@ -41,4 +43,4 @@ public class Customer {
@JoinColumn(name = "address_id", referencedColumnName = "id")
private Address address;

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.util.List;
import java.util.Optional;
import java.util.UUID;

/**
* @author Alex Zarubin
Expand Down Expand Up @@ -82,7 +83,7 @@ public ResponseEntity<Void> updateNotification(@PathVariable("id") String id, @R
.build();
}
Notification notificationToUpdate = notificationDtoConverter.convertToEntity(request);
notificationToUpdate.setId(Integer.parseInt(id));
notificationToUpdate.setId(UUID.fromString(id));
notificationRepository.save(notificationToUpdate);
log.info("The Notification with id - {} was updated.", id);
return ResponseEntity.ok().build();
Expand All @@ -96,4 +97,4 @@ public ResponseEntity<Void> deleteNotification(@PathVariable("id") String id) {
return ResponseEntity.ok().build();
}

}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,23 @@
package com.zufar.onlinestore.notification.entity;

import com.zufar.onlinestore.customer.entity.Customer;
import jakarta.persistence.CascadeType;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.OneToOne;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.springframework.data.annotation.Id;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.UUID;

/**
* @author Alex Zarubin
* created on 24.05.2023
Expand All @@ -18,13 +28,20 @@
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Document
@Entity
@Table(name = "notification")
public class Notification {


@Id
private int id;
@Column(nullable = false)
@GeneratedValue(strategy = GenerationType.SEQUENCE)
private UUID id;

@Column(name = "message")
private String message;
private Customer recipient;
}

@OneToOne(cascade = CascadeType.REFRESH)
@JoinColumn(name = "recipient_id", referencedColumnName = "id")
private Customer recipient;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@


import com.zufar.onlinestore.notification.entity.Notification;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface NotificationRepository extends MongoRepository<Notification, Integer> {
}

public interface NotificationRepository extends JpaRepository<Notification, Integer> {
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.UUID;

/**
* @author Alex Zarubin
* created on 27.05.2023
Expand All @@ -20,10 +22,10 @@ CommandLineRunner notificationCommandLineRunner(NotificationRepository repositor
Customer customer = new Customer();

return strings -> {
repository.save(new Notification(1, "Notification1", customer));
repository.save(new Notification(2, "Notification2", customer));
repository.save(new Notification(3, "Notification3", customer));
repository.save(new Notification(4, "Notification4", customer));
repository.save(new Notification(UUID.randomUUID(), "Notification1", customer));
repository.save(new Notification(UUID.randomUUID(), "Notification2", customer));
repository.save(new Notification(UUID.randomUUID(), "Notification3", customer));
repository.save(new Notification(UUID.randomUUID(), "Notification4", customer));
};
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.zufar.onlinestore.product;

import com.zufar.onlinestore.product.dto.PriceDto;
import com.zufar.onlinestore.product.dto.ProductInfoDto;

import org.springframework.stereotype.Service;
Expand All @@ -13,8 +12,7 @@ public class ProductsSumCalculator {

public BigDecimal calculate(final Collection<ProductInfoDto> products) {
return products.stream()
.map(ProductInfoDto::getPrice)
.map(PriceDto::getAmount)
.map(ProductInfoDto::price)
.reduce(BigDecimal.ZERO, BigDecimal::add);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import com.zufar.onlinestore.product.dto.ProductInfoDto;
import com.zufar.onlinestore.product.entity.ProductInfo;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

@Component
Expand All @@ -11,17 +10,19 @@ public class ProductInfoDtoConverter {
public ProductInfoDto convertToDto(final ProductInfo entity) {
return ProductInfoDto.builder()
.id(entity.getId())
.category(entity.getCategory())
.description(entity.getDescription())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ты либо используй гетеры entity.getDescription() либо используй возможности record - entity.description()
и так везде единообразно должно быть

.name(entity.getName())
.price(entity.getPrice())
.currency(entity.getCurrency())
.build();
}

public ProductInfo convertToEntity(final ProductInfoDto dto) {
return ProductInfo.builder()
.category(dto.getCategory())
.name(dto.getName())
.price(dto.getPrice())
.description(dto.description())
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ты либо используй гетеры entity.getDescription() либо используй возможности record - entity.description()
и так везде единообразно должно быть

.name(dto.name())
.price(dto.price())
.currency(dto.currency())
.build();
}
}
27 changes: 0 additions & 27 deletions src/main/java/com/zufar/onlinestore/product/dto/PriceDto.java
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Зачем ты удалил класс для цены?

This file was deleted.

Loading