-
Notifications
You must be signed in to change notification settings - Fork 19
Synapse imperative api sample #376
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
Open
aazizali
wants to merge
3
commits into
develop
Choose a base branch
from
feature/25.2.9/IS-46055_synapse-imperative-api-sample
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,31 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| Copyright 2020 American Express Travel Related Services Company, Inc. | ||
|
|
||
| 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 | ||
|
|
||
| http://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. | ||
| --> | ||
| <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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
| <parent> | ||
| <groupId>io.americanexpress.synapse</groupId> | ||
| <artifactId>api</artifactId> | ||
| <version>0.4.16-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <modelVersion>4.0.0</modelVersion> | ||
| <artifactId>api-samples</artifactId> | ||
| <packaging>pom</packaging> | ||
|
|
||
| <!--Modules--> | ||
| <modules> | ||
| <module>sample-api-imperative-book</module> | ||
| </modules> | ||
|
|
||
| </project> |
This file contains hidden or 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,36 @@ | ||
| <?xml version="1.0" encoding="UTF-8"?> | ||
| <!-- | ||
| Copyright 2020 American Express Travel Related Services Company, Inc. | ||
|
|
||
| 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 | ||
|
|
||
| http://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. | ||
| --> | ||
| <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 http://maven.apache.org/xsd/maven-4.0.0.xsd"> | ||
|
|
||
| <parent> | ||
| <artifactId>api-samples</artifactId> | ||
| <groupId>io.americanexpress.synapse</groupId> | ||
| <version>0.4.16-SNAPSHOT</version> | ||
| </parent> | ||
|
|
||
| <modelVersion>4.0.0</modelVersion> | ||
| <artifactId>sample-api-imperative-book</artifactId> | ||
|
|
||
| <dependencies> | ||
| <dependency> | ||
| <groupId>io.americanexpress.synapse</groupId> | ||
| <artifactId>sample-service-imperative-book</artifactId> | ||
| </dependency> | ||
| <dependency> | ||
| <groupId>io.americanexpress.synapse</groupId> | ||
| <artifactId>synapse-api-rest-imperative</artifactId> | ||
| </dependency> | ||
| </dependencies> | ||
| </project> |
25 changes: 25 additions & 0 deletions
25
...i-imperative-book/src/main/java/io/americanexpress/api/sample/imperativebook/BookApp.java
This file contains hidden or 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,25 @@ | ||
| /* | ||
| * Copyright 2020 American Express Travel Related Services Company, Inc. | ||
| * | ||
| * 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 | ||
| * | ||
| * http://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. | ||
| */ | ||
| package io.americanexpress.api.sample.imperativebook; | ||
|
|
||
| import org.springframework.boot.SpringApplication; | ||
| import org.springframework.boot.autoconfigure.SpringBootApplication; | ||
|
|
||
| @SpringBootApplication | ||
| public class BookApp { | ||
|
|
||
| public static void main(String[] args) { | ||
| SpringApplication.run(BookApp.class, args); | ||
| } | ||
| } |
69 changes: 69 additions & 0 deletions
69
...book/src/main/java/io/americanexpress/api/sample/imperativebook/config/BookApiConfig.java
This file contains hidden or 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,69 @@ | ||
| /* | ||
| * Copyright 2020 American Express Travel Related Services Company, Inc. | ||
| * | ||
| * 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 | ||
| * | ||
| * http://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. | ||
| */ | ||
| package io.americanexpress.api.sample.imperativebook.config; | ||
|
|
||
| import com.fasterxml.jackson.databind.ObjectMapper; | ||
| import io.americanexpress.synapse.api.rest.imperative.config.BaseApiImperativeRestConfig; | ||
| import io.americanexpress.synapse.api.rest.imperative.interceptor.MetricInterceptor; | ||
| import org.springframework.context.annotation.ComponentScan; | ||
| import org.springframework.context.annotation.Configuration; | ||
| import org.springframework.web.servlet.config.annotation.InterceptorRegistry; | ||
|
|
||
| /** | ||
| * Configuration class for the Book API. | ||
| * <p> | ||
| * This class extends {@code BaseApiImperativeRestConfig} to provide custom configurations for the Book API, | ||
| * including component scanning and interceptor registration. | ||
| * | ||
| * @author Aziz Ali | ||
| */ | ||
| @ComponentScan({ | ||
| "io.americanexpress.service.sample.imperativebook", | ||
| "io.americanexpress.api.sample.imperativebook" | ||
| }) | ||
| @Configuration | ||
| public class BookApiConfig extends BaseApiImperativeRestConfig { | ||
|
|
||
| /** | ||
| * Used to intercept requests for checking headers. | ||
| */ | ||
| private final BookHttpHeadersInterceptor bookHttpHeadersInterceptor; | ||
|
|
||
|
|
||
| /** | ||
| * Constructor taking in objectMapper & metricInterceptor. | ||
| * | ||
| * @param defaultObjectMapper the default object mapper | ||
| * @param interceptor the metric interceptor | ||
| * @param bookHttpHeadersInterceptor the | ||
| */ | ||
| public BookApiConfig(ObjectMapper defaultObjectMapper, | ||
| MetricInterceptor interceptor, | ||
| BookHttpHeadersInterceptor bookHttpHeadersInterceptor) { | ||
| super(defaultObjectMapper, interceptor); | ||
| this.bookHttpHeadersInterceptor = bookHttpHeadersInterceptor; | ||
| } | ||
|
|
||
| /** | ||
| * Takes any interceptor we provide and binds it to our service endpoint. | ||
| * | ||
| * @param registry the list of interceptors bound to our service | ||
| */ | ||
| @Override | ||
| public void addInterceptors(InterceptorRegistry registry) { | ||
| registry.addInterceptor(this.bookHttpHeadersInterceptor).order(1); | ||
| super.addInterceptors(registry); | ||
| } | ||
|
|
||
| } |
33 changes: 33 additions & 0 deletions
33
...-book/src/main/java/io/americanexpress/api/sample/imperativebook/config/BookEndpoint.java
This file contains hidden or 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,33 @@ | ||
| /* | ||
| * Copyright 2020 American Express Travel Related Services Company, Inc. | ||
| * | ||
| * 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 | ||
| * | ||
| * http://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. | ||
| */ | ||
| package io.americanexpress.api.sample.imperativebook.config; | ||
|
|
||
| /** | ||
| * Configuration class for defining API endpoints related to books. | ||
| * <p> | ||
| * This class provides a centralized location for managing endpoint paths used in the application. It is designed to | ||
| * prevent instantiation. | ||
| * | ||
| * @author Aziz Ali | ||
| */ | ||
| public class BookEndpoint { | ||
|
|
||
| /** | ||
| * The base endpoint for book-related API operations. | ||
| */ | ||
| public static final String BOOKS_ENDPOINT = "/api/v1/books"; | ||
|
|
||
| private BookEndpoint() { | ||
| } | ||
| } |
37 changes: 37 additions & 0 deletions
37
.../java/io/americanexpress/api/sample/imperativebook/config/BookHttpHeadersInterceptor.java
This file contains hidden or 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,37 @@ | ||
| /* | ||
| * Copyright 2020 American Express Travel Related Services Company, Inc. | ||
| * | ||
| * 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 | ||
| * | ||
| * http://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. | ||
| */ | ||
| package io.americanexpress.api.sample.imperativebook.config; | ||
|
|
||
| import io.americanexpress.synapse.api.rest.imperative.interceptor.BaseHttpInterceptor; | ||
| import org.springframework.stereotype.Component; | ||
| import java.util.List; | ||
|
|
||
| /** | ||
| * Intercepts HTTP requests to validate required headers for book-related APIs. | ||
| * | ||
| * @author Aziz Ali | ||
| */ | ||
| @Component | ||
| public class BookHttpHeadersInterceptor extends BaseHttpInterceptor { | ||
|
|
||
| /** | ||
| * Provides the list of required HTTP header names. | ||
| * | ||
| * @return list of required header names | ||
| */ | ||
| @Override | ||
| protected List<String> getRequiredHttpHeaderNames() { | ||
| return requiredHttpHeaderNames.stream().toList(); | ||
| } | ||
| } |
36 changes: 36 additions & 0 deletions
36
...in/java/io/americanexpress/api/sample/imperativebook/controller/CreateBookController.java
This file contains hidden or 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,36 @@ | ||
| /* | ||
| * Copyright 2020 American Express Travel Related Services Company, Inc. | ||
| * | ||
| * 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 | ||
| * | ||
| * http://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. | ||
| */ | ||
| package io.americanexpress.api.sample.imperativebook.controller; | ||
|
|
||
| import io.americanexpress.service.sample.imperativebook.model.CreateBookServiceRequest; | ||
| import io.americanexpress.service.sample.imperativebook.model.CreateBookServiceResponse; | ||
| import io.americanexpress.service.sample.imperativebook.service.CreateBookService; | ||
| import io.americanexpress.synapse.api.rest.imperative.controller.BaseCreateImperativeRestController; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import static io.americanexpress.api.sample.imperativebook.config.BookEndpoint.BOOKS_ENDPOINT; | ||
|
|
||
| /** | ||
| * Controller for handling HTTP POST requests to create books. Extends the base class to utilize common create | ||
| * functionality. | ||
| * | ||
| * @author Aziz Ali | ||
| */ | ||
| @RequestMapping(BOOKS_ENDPOINT) | ||
| @RestController | ||
| public class CreateBookController extends BaseCreateImperativeRestController< | ||
| CreateBookServiceRequest, | ||
| CreateBookServiceResponse, | ||
| CreateBookService> { | ||
| } |
37 changes: 37 additions & 0 deletions
37
...in/java/io/americanexpress/api/sample/imperativebook/controller/DeleteBookController.java
This file contains hidden or 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,37 @@ | ||
| /* | ||
| * Copyright 2020 American Express Travel Related Services Company, Inc. | ||
| * | ||
| * 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 | ||
| * | ||
| * http://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. | ||
| */ | ||
| package io.americanexpress.api.sample.imperativebook.controller; | ||
|
|
||
| import io.americanexpress.service.sample.imperativebook.model.DeleteBookServiceRequest; | ||
| import io.americanexpress.service.sample.imperativebook.model.DeleteBookServiceResponse; | ||
| import io.americanexpress.service.sample.imperativebook.service.DeleteBookService; | ||
| import io.americanexpress.synapse.api.rest.imperative.controller.BaseDeleteImperativeRestController; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import static io.americanexpress.api.sample.imperativebook.config.BookEndpoint.BOOKS_ENDPOINT; | ||
|
|
||
| /** | ||
| * Controller for handling HTTP DELETE requests to delete books. Extends the base class to utilize common delete | ||
| * functionality. | ||
| * | ||
| * @author Aziz Ali | ||
| */ | ||
| @RequestMapping(BOOKS_ENDPOINT) | ||
| @RestController | ||
| public class DeleteBookController extends BaseDeleteImperativeRestController< | ||
| DeleteBookServiceRequest, | ||
| DeleteBookServiceResponse, | ||
| DeleteBookService> { | ||
|
|
||
| } |
36 changes: 36 additions & 0 deletions
36
...main/java/io/americanexpress/api/sample/imperativebook/controller/ReadBookController.java
This file contains hidden or 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,36 @@ | ||
| /* | ||
| * Copyright 2020 American Express Travel Related Services Company, Inc. | ||
| * | ||
| * 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 | ||
| * | ||
| * http://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. | ||
| */ | ||
| package io.americanexpress.api.sample.imperativebook.controller; | ||
|
|
||
| import io.americanexpress.service.sample.imperativebook.model.ReadBookServiceRequest; | ||
| import io.americanexpress.service.sample.imperativebook.model.ReadBookServiceResponse; | ||
| import io.americanexpress.service.sample.imperativebook.service.ReadBookService; | ||
| import io.americanexpress.synapse.api.rest.imperative.controller.BaseReadMonoImperativeRestController; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import static io.americanexpress.api.sample.imperativebook.config.BookEndpoint.BOOKS_ENDPOINT; | ||
|
|
||
| /** | ||
| * Controller for handling HTTP GET requests to read book details. Extends the base class to utilize common read | ||
| * functionality. | ||
| * | ||
| * @author Aziz Ali | ||
| */ | ||
| @RequestMapping(BOOKS_ENDPOINT) | ||
| @RestController | ||
| public class ReadBookController extends BaseReadMonoImperativeRestController< | ||
| ReadBookServiceRequest, | ||
| ReadBookServiceResponse, | ||
| ReadBookService> { | ||
| } |
37 changes: 37 additions & 0 deletions
37
...in/java/io/americanexpress/api/sample/imperativebook/controller/UpdateBookController.java
This file contains hidden or 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,37 @@ | ||
| /* | ||
| * Copyright 2020 American Express Travel Related Services Company, Inc. | ||
| * | ||
| * 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 | ||
| * | ||
| * http://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. | ||
| */ | ||
| package io.americanexpress.api.sample.imperativebook.controller; | ||
|
|
||
| import io.americanexpress.service.sample.imperativebook.model.UpdateBookServiceRequest; | ||
| import io.americanexpress.service.sample.imperativebook.model.UpdateBookServiceResponse; | ||
| import io.americanexpress.service.sample.imperativebook.service.UpdateBookService; | ||
| import io.americanexpress.synapse.api.rest.imperative.controller.BaseUpdateImperativeRestController; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RestController; | ||
| import static io.americanexpress.api.sample.imperativebook.config.BookEndpoint.BOOKS_ENDPOINT; | ||
|
|
||
| /** | ||
| * Controller for handling HTTP PUT requests to update book details. Extends the base class to utilize common update | ||
| * functionality. | ||
| * | ||
| * @author Aziz Ali | ||
| */ | ||
| @RequestMapping(BOOKS_ENDPOINT) | ||
| @RestController | ||
| public class UpdateBookController extends BaseUpdateImperativeRestController< | ||
| UpdateBookServiceRequest, | ||
| UpdateBookServiceResponse, | ||
| UpdateBookService> { | ||
|
|
||
| } |
This file contains hidden or 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.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hi @aazizali
Can this module be renamed to synapse-api-samples? This keeps your naming consistent with other modules.