Change project to run spring-boot locally and kafka,zoo and mongo in docker-compose
This commit is contained in:
@@ -1,27 +1,19 @@
|
||||
package es.dbiosag.query.domain.model;
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import lombok.Data;
|
||||
|
||||
import javax.persistence.*;
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
@Data
|
||||
@Entity
|
||||
@Table(name = "PHONES")
|
||||
public class Phone {
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy= GenerationType.AUTO)
|
||||
@Column(name = "ID_PHONE")
|
||||
private Integer id;
|
||||
@Column(name = "NAME")
|
||||
@JsonIgnore
|
||||
private String id;
|
||||
private String name;
|
||||
@Column(name = "MODEL")
|
||||
private String model;
|
||||
@Column(name = "COLOR")
|
||||
private String color;
|
||||
@Column(name = "PRICE")
|
||||
private Double price;
|
||||
@Column(name = "CREATION_DATE")
|
||||
private String creationDate;
|
||||
|
||||
public Phone(){ }
|
||||
|
||||
@@ -9,8 +9,6 @@ import lombok.extern.log4j.Log4j2;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.stereotype.Service;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
@Service
|
||||
@Log4j2
|
||||
public class FindPhoneService {
|
||||
@@ -21,12 +19,9 @@ public class FindPhoneService {
|
||||
private PhoneConverter phoneConverter;
|
||||
|
||||
public PhoneResponse findByName(String name) throws PhoneNotFoundException {
|
||||
Optional<Phone> phone = phoneRepository.findByName(name);
|
||||
if(!phone.isPresent()) {
|
||||
throw new PhoneNotFoundException(name, "Phone not found");
|
||||
}
|
||||
Phone phone = phoneRepository.findByName(name).orElseThrow(() -> new PhoneNotFoundException(name, "Phone not found"));
|
||||
log.info("Find phone: {}", phone);
|
||||
return phoneConverter.phoneToPhoneResponse(phone.get());
|
||||
return phoneConverter.phoneToPhoneResponse(phone);
|
||||
}
|
||||
|
||||
public void createPhone(Phone p) {
|
||||
|
||||
@@ -1,13 +1,14 @@
|
||||
package es.dbiosag.query.infrastructure.repository;
|
||||
|
||||
import es.dbiosag.query.domain.model.Phone;
|
||||
import org.springframework.data.repository.CrudRepository;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
import java.util.Optional;
|
||||
|
||||
|
||||
@Repository
|
||||
public interface PhoneRepository extends CrudRepository<Phone, Integer> {
|
||||
public interface PhoneRepository extends MongoRepository<Phone, Integer> {
|
||||
|
||||
Optional<Phone> findByName(String name);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,16 @@
|
||||
server:
|
||||
port: 8082
|
||||
spring:
|
||||
datasource:
|
||||
driverClassName: org.h2.Driver
|
||||
password: 1234
|
||||
url: jdbc:h2:mem:querydb
|
||||
username: sa
|
||||
jpa:
|
||||
database-platform: org.hibernate.dialect.H2Dialect
|
||||
h2:
|
||||
console:
|
||||
enabled: true
|
||||
|
||||
data:
|
||||
mongodb:
|
||||
authentication-database: examples
|
||||
database: examples
|
||||
username: api_user
|
||||
password: NdEep0XLpMNKUmgQVa81oDCx7mrSRodh0Z79qdX3
|
||||
host: localhost
|
||||
port: 30001
|
||||
kafka:
|
||||
bootstrap-servers: kafka1:9092
|
||||
bootstrap-servers: localhost:29092
|
||||
consumer:
|
||||
group-id: test-consumer-group
|
||||
message:
|
||||
|
||||
@@ -1,10 +0,0 @@
|
||||
DROP TABLE IF EXISTS phones;
|
||||
|
||||
CREATE TABLE phones (
|
||||
id_phone INT AUTO_INCREMENT PRIMARY KEY,
|
||||
creation_date VARCHAR(250) NOT NULL,
|
||||
name VARCHAR(250) NOT NULL,
|
||||
model VARCHAR(250) NOT NULL,
|
||||
price VARCHAR(250) NOT NULL,
|
||||
color VARCHAR(250) NOT NULL
|
||||
);
|
||||
Reference in New Issue
Block a user