-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
polish dynamodb implementation (#817)
* polish dynamodb implementation * delombok * adds to string
- Loading branch information
1 parent
905e61a
commit 0083751
Showing
14 changed files
with
128 additions
and
62 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 51 additions & 4 deletions
55
aws-dynamodb-project/src/main/java/com/learning/awsspring/config/ApplicationProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,20 +1,67 @@ | ||
package com.learning.awsspring.config; | ||
|
||
import lombok.Data; | ||
import jakarta.validation.Valid; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.boot.context.properties.NestedConfigurationProperty; | ||
|
||
@Data | ||
@ConfigurationProperties("application") | ||
public class ApplicationProperties { | ||
@NestedConfigurationProperty private Cors cors = new Cors(); | ||
|
||
@Data | ||
@NestedConfigurationProperty @Valid private Cors cors = new Cors(); | ||
|
||
public static class Cors { | ||
private String pathPattern = "/api/**"; | ||
private String allowedMethods = "*"; | ||
private String allowedHeaders = "*"; | ||
private String allowedOriginPatterns = "*"; | ||
private boolean allowCredentials = true; | ||
|
||
public String getPathPattern() { | ||
return pathPattern; | ||
} | ||
|
||
public void setPathPattern(String pathPattern) { | ||
this.pathPattern = pathPattern; | ||
} | ||
|
||
public String getAllowedMethods() { | ||
return allowedMethods; | ||
} | ||
|
||
public void setAllowedMethods(String allowedMethods) { | ||
this.allowedMethods = allowedMethods; | ||
} | ||
|
||
public String getAllowedHeaders() { | ||
return allowedHeaders; | ||
} | ||
|
||
public void setAllowedHeaders(String allowedHeaders) { | ||
this.allowedHeaders = allowedHeaders; | ||
} | ||
|
||
public String getAllowedOriginPatterns() { | ||
return allowedOriginPatterns; | ||
} | ||
|
||
public void setAllowedOriginPatterns(String allowedOriginPatterns) { | ||
this.allowedOriginPatterns = allowedOriginPatterns; | ||
} | ||
|
||
public boolean isAllowCredentials() { | ||
return allowCredentials; | ||
} | ||
|
||
public void setAllowCredentials(boolean allowCredentials) { | ||
this.allowCredentials = allowCredentials; | ||
} | ||
} | ||
|
||
public Cors getCors() { | ||
return cors; | ||
} | ||
|
||
public void setCors(Cors cors) { | ||
this.cors = cors; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 14 additions & 8 deletions
22
aws-dynamodb-project/src/main/java/com/learning/awsspring/config/WebMvcConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,27 @@ | ||
package com.learning.awsspring.config; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import com.learning.awsspring.config.ApplicationProperties.Cors; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.lang.NonNull; | ||
import org.springframework.web.servlet.config.annotation.CorsRegistry; | ||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | ||
|
||
@Configuration | ||
@RequiredArgsConstructor | ||
public class WebMvcConfig implements WebMvcConfigurer { | ||
|
||
private final ApplicationProperties properties; | ||
|
||
public WebMvcConfig(ApplicationProperties properties) { | ||
this.properties = properties; | ||
} | ||
|
||
@Override | ||
public void addCorsMappings(CorsRegistry registry) { | ||
registry.addMapping(properties.getCors().getPathPattern()) | ||
.allowedMethods(properties.getCors().getAllowedMethods()) | ||
.allowedHeaders(properties.getCors().getAllowedHeaders()) | ||
.allowedOriginPatterns(properties.getCors().getAllowedOriginPatterns()) | ||
.allowCredentials(properties.getCors().isAllowCredentials()); | ||
public void addCorsMappings(@NonNull CorsRegistry registry) { | ||
Cors cors = properties.getCors(); | ||
registry.addMapping(cors.getPathPattern()) | ||
.allowedMethods(cors.getAllowedMethods()) | ||
.allowedHeaders(cors.getAllowedHeaders()) | ||
.allowedOriginPatterns(cors.getAllowedOriginPatterns()) | ||
.allowCredentials(cors.isAllowCredentials()); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,18 +6,20 @@ | |
import com.learning.awsspring.entities.Customer; | ||
import io.awspring.cloud.dynamodb.DynamoDbOperations; | ||
import java.util.UUID; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.junit.jupiter.api.Test; | ||
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import software.amazon.awssdk.enhanced.dynamodb.Key; | ||
import software.amazon.awssdk.enhanced.dynamodb.model.PageIterable; | ||
import software.amazon.awssdk.enhanced.dynamodb.model.QueryConditional; | ||
import software.amazon.awssdk.enhanced.dynamodb.model.QueryEnhancedRequest; | ||
import software.amazon.awssdk.services.dynamodb.model.AttributeValue; | ||
|
||
@Slf4j | ||
class ApplicationIntegrationTest extends AbstractIntegrationTest { | ||
|
||
private static final Logger log = LoggerFactory.getLogger(ApplicationIntegrationTest.class); | ||
|
||
@Autowired private DynamoDbOperations dynamoDbOperations; | ||
|
||
@Test | ||
|
@@ -26,7 +28,7 @@ void contextLoads() { | |
UUID id = UUID.randomUUID(); | ||
String email = "[email protected]"; | ||
String name = "junit"; | ||
Customer customer = Customer.builder().id(id).name(name).email(email).build(); | ||
Customer customer = new Customer(id, name, email); | ||
// Saving Customer | ||
dynamoDbOperations.save(customer); | ||
|
||
|
11 changes: 11 additions & 0 deletions
11
aws-dynamodb-project/src/test/java/com/learning/awsspring/TestDynamoDBApplication.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.learning.awsspring; | ||
|
||
import com.learning.awsspring.common.ContainerConfig; | ||
import org.springframework.boot.SpringApplication; | ||
|
||
public class TestDynamoDBApplication { | ||
|
||
public static void main(String[] args) { | ||
SpringApplication.from(DynamoDBApplication::main).with(ContainerConfig.class).run(args); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.