configured mongoDB
This commit is contained in:
@@ -11,7 +11,7 @@
|
||||
</parent>
|
||||
|
||||
<groupId>de.strasser.peter.hexagonal</groupId>
|
||||
<artifactId>persistenceadapter</artifactId>
|
||||
<artifactId>persistence</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<packaging>jar</packaging>
|
||||
<properties>
|
||||
|
||||
@@ -1,10 +1,15 @@
|
||||
package de.strasser.peter.hexagonal.persistence.config;
|
||||
|
||||
import de.strasser.peter.hexagonal.persistence.repository.CustomerRepository;
|
||||
import com.mongodb.client.MongoClient;
|
||||
import com.mongodb.client.MongoClients;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.data.mongodb.repository.config.EnableMongoRepositories;
|
||||
|
||||
@Configuration
|
||||
@EnableMongoRepositories(basePackageClasses = CustomerRepository.class)
|
||||
public class MongoConfig {
|
||||
|
||||
@Bean
|
||||
public MongoClient mongoClient() {
|
||||
return MongoClients.create("mongodb://admin:changeme@localhost:27017");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,11 +1,15 @@
|
||||
package de.strasser.peter.hexagonal.persistence.model;
|
||||
|
||||
import lombok.AllArgsConstructor;
|
||||
import lombok.Data;
|
||||
import lombok.NoArgsConstructor;
|
||||
import org.springframework.data.annotation.Id;
|
||||
|
||||
import java.time.LocalDate;
|
||||
|
||||
@Data
|
||||
@AllArgsConstructor
|
||||
@NoArgsConstructor
|
||||
public class CustomerEntity {
|
||||
@Id
|
||||
private Integer id;
|
||||
@@ -28,4 +32,5 @@ public class CustomerEntity {
|
||||
private int billingHouseNumber;
|
||||
private int billingZipCode;
|
||||
private String billingCountry;
|
||||
|
||||
}
|
||||
|
||||
@@ -2,6 +2,8 @@ package de.strasser.peter.hexagonal.persistence.repository;
|
||||
|
||||
import de.strasser.peter.hexagonal.persistence.model.CustomerEntity;
|
||||
import org.springframework.data.mongodb.repository.MongoRepository;
|
||||
import org.springframework.stereotype.Repository;
|
||||
|
||||
@Repository
|
||||
public interface CustomerRepository extends MongoRepository<CustomerEntity, Integer> {
|
||||
}
|
||||
|
||||
@@ -10,9 +10,9 @@
|
||||
</parent>
|
||||
|
||||
<groupId>de.strasser.peter.hexagonal</groupId>
|
||||
<artifactId>webadapter</artifactId>
|
||||
<artifactId>web</artifactId>
|
||||
<version>0.0.1-SNAPSHOT</version>
|
||||
<name>webadapter</name>
|
||||
<name>web</name>
|
||||
<description>Web adapter</description>
|
||||
<properties>
|
||||
<java.version>14</java.version>
|
||||
|
||||
@@ -0,0 +1,8 @@
|
||||
package de.strasser.peter.hexagonal.webadapter.config;
|
||||
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
|
||||
@Configuration
|
||||
public class WebConfig {
|
||||
|
||||
}
|
||||
@@ -28,11 +28,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-validation</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-test</artifactId>
|
||||
|
||||
@@ -6,7 +6,6 @@ import de.strasser.peter.hexagonal.application.customer.port.in.commands.Registe
|
||||
import de.strasser.peter.hexagonal.application.customer.port.out.SaveCustomerAdapter;
|
||||
import lombok.RequiredArgsConstructor;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
import org.springframework.stereotype.Service;
|
||||
import org.springframework.validation.annotation.Validated;
|
||||
|
||||
@@ -18,13 +17,16 @@ import javax.validation.Valid;
|
||||
@RequiredArgsConstructor
|
||||
class RegisterCustomerService implements RegisterCustomerUseCase {
|
||||
private final SaveCustomerAdapter saveUser;
|
||||
private final PasswordEncoder pwEncoder;
|
||||
|
||||
@Override
|
||||
public void register(@Valid RegisterCustomerCommand registerCmd) {
|
||||
var encryptedPw = pwEncoder.encode(registerCmd.getClearPassword());
|
||||
var encryptedPw = this.secureHashingAlgorithm(registerCmd.getClearPassword());
|
||||
var newCustomer = Customer.newCustomer(registerCmd.getName(), encryptedPw, registerCmd.getBirthDay());
|
||||
|
||||
saveUser.upsert(newCustomer);
|
||||
}
|
||||
|
||||
private String secureHashingAlgorithm(String s) {
|
||||
return new StringBuilder(s).reverse().toString();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,25 +1,12 @@
|
||||
package de.strasser.peter.hexagonal.application;
|
||||
|
||||
|
||||
import de.strasser.peter.hexagonal.application.customer.mapper.AddAddressMapper;
|
||||
import de.strasser.peter.hexagonal.application.customer.port.out.AddressValidatorAdapter;
|
||||
import de.strasser.peter.hexagonal.application.customer.port.out.LoadCustomerAdapter;
|
||||
import de.strasser.peter.hexagonal.application.customer.port.out.SaveCustomerAdapter;
|
||||
import lombok.extern.slf4j.Slf4j;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.boot.test.mock.mockito.MockBean;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
@Slf4j
|
||||
@SpringBootApplication
|
||||
public class TestConfiguration {
|
||||
@Bean
|
||||
public PasswordEncoder pwEncoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
||||
@@ -22,14 +22,6 @@
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-data-mongodb</artifactId>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
@@ -49,12 +41,12 @@
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.strasser.peter.hexagonal</groupId>
|
||||
<artifactId>webadapter</artifactId>
|
||||
<artifactId>web</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>de.strasser.peter.hexagonal</groupId>
|
||||
<artifactId>persistenceadapter</artifactId>
|
||||
<artifactId>persistence</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
@@ -1,11 +1,9 @@
|
||||
package de.strasser.peter.hexagonal.config;
|
||||
package de.strasser.peter.hexagonal;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.ComponentScan;
|
||||
|
||||
@SpringBootApplication
|
||||
@ComponentScan("de.strasser.peter.hexagonal")
|
||||
public class HexagonalApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
@@ -1,14 +0,0 @@
|
||||
package de.strasser.peter.hexagonal.config;
|
||||
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
|
||||
import org.springframework.security.crypto.password.PasswordEncoder;
|
||||
|
||||
@Configuration
|
||||
public class SecurityConfig {
|
||||
@Bean
|
||||
public PasswordEncoder encoder() {
|
||||
return new BCryptPasswordEncoder();
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1 @@
|
||||
spring.data.mongodb.host=localhost
|
||||
spring.data.mongodb.port=27021
|
||||
spring.data.mongodb.database=test
|
||||
spring.data.mongodb.authentication-database=admin
|
||||
spring.data.mongodb.username=test
|
||||
spring.data.mongodb.password=test
|
||||
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
|
||||
|
||||
1
config/src/test/java/resources/application.properties
Normal file
1
config/src/test/java/resources/application.properties
Normal file
@@ -0,0 +1 @@
|
||||
spring.jackson.serialization.WRITE_DATES_AS_TIMESTAMPS=false
|
||||
@@ -1,14 +1,15 @@
|
||||
version: '3.1'
|
||||
|
||||
services:
|
||||
|
||||
mongo:
|
||||
image: mongo
|
||||
restart: always
|
||||
ports:
|
||||
- 27017:27017
|
||||
environment:
|
||||
MONGO_INITDB_ROOT_USERNAME: test
|
||||
MONGO_INITDB_ROOT_PASSWORD: test
|
||||
MONGO_INITDB_DATABASE: test
|
||||
MONGO_INITDB_ROOT_USERNAME: admin
|
||||
MONGO_INITDB_ROOT_PASSWORD: changeme
|
||||
MONGO_INITDB_DATABASE: customer
|
||||
|
||||
mongo-express:
|
||||
image: mongo-express
|
||||
@@ -16,5 +17,5 @@ services:
|
||||
ports:
|
||||
- 8081:8081
|
||||
environment:
|
||||
ME_CONFIG_MONGODB_ADMINUSERNAME: test
|
||||
ME_CONFIG_MONGODB_ADMINPASSWORD: test
|
||||
ME_CONFIG_MONGODB_ADMINUSERNAME: admin
|
||||
ME_CONFIG_MONGODB_ADMINPASSWORD: changeme
|
||||
|
||||
Reference in New Issue
Block a user