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

feat(): added simple kotlin example for Synapse integration #231

Open
wants to merge 3 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -354,6 +354,11 @@
<artifactId>sample-service-graphql-book</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>sample-service-kotlin</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>sample-service-reactive-cassandra-book</artifactId>
Expand Down
1 change: 1 addition & 0 deletions service/service-samples/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
<!--Modules-->
<modules>
<module>sample-service-graphql-book</module>
<module>sample-service-kotlin</module>
<module>sample-service-reactive-cassandra-book</module>
<module>sample-service-reactive-mongodb-book</module>
<module>sample-service-reactive-mysql-book</module>
Expand Down
86 changes: 86 additions & 0 deletions service/service-samples/sample-service-kotlin/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
<?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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<parent>
<artifactId>synapse</artifactId>
<groupId>io.americanexpress.synapse</groupId>
<version>0.3.8-SNAPSHOT</version>
<relativePath>../../../pom.xml</relativePath>
</parent>
<modelVersion>4.0.0</modelVersion>

<artifactId>sample-service-kotlin</artifactId>

<properties>
<maven.compiler.source>19</maven.compiler.source>
<maven.compiler.target>19</maven.compiler.target>
<kotlin.version>1.6.10</kotlin.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
</properties>

<!--Dependencies-->
<dependencies>
<!--Synapse-->
<dependency>
<groupId>io.americanexpress.synapse</groupId>
<artifactId>synapse-service-rest</artifactId>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-reflect</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-stdlib</artifactId>
<version>${kotlin.version}</version>
</dependency>
<dependency>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-allopen</artifactId>
<version>${kotlin.version}</version>
</dependency>
</dependencies>

<build>
<plugins>
<!-- Kotlin Maven Plugin -->
<plugin>
<groupId>org.jetbrains.kotlin</groupId>
<artifactId>kotlin-maven-plugin</artifactId>
<version>${kotlin.version}</version>
<executions>
<execution>
<id>compile</id>
<goals>
<goal>compile</goal>
</goals>
<configuration>
<jvmTarget>17</jvmTarget>
</configuration>
</execution>
<execution>
<id>test-compile</id>
<goals>
<goal>test-compile</goal>
</goals>
<configuration>
<jvmTarget>17</jvmTarget>
</configuration>
</execution>
</executions>
</plugin>
<!-- Surefire Plugin -->
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<includes>
<include>**/*Test.kt</include>
</includes>
</configuration>
</plugin>
</plugins>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*
* 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.synapse.kotlin.book

import org.springframework.boot.autoconfigure.SpringBootApplication
import org.springframework.boot.runApplication

/**
* {@code BookApplication} starts the Spring Boot Application for the book Kotlin sample.
*/
@SpringBootApplication
open class BookApplication

/**
* Spring Boot main method to launch application
*/
fun main(args: Array<String>) {
runApplication<BookApplication>(*args)
}
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.synapse.kotlin.book.config

import io.americanexpress.synapse.service.rest.config.ServiceRestConfig
import org.springframework.context.annotation.ComponentScan
import org.springframework.context.annotation.Configuration
import org.springframework.context.annotation.Import

/**
* {@code BookConfig} SpringBook Configuration Kotlin example. Importing {@link ServiceRestConfig} to enable
* Synapse configuration.
*/
@Configuration
@ComponentScan(basePackages = ["io.americanexpress.synapse.kotlin.book"])
@Import(ServiceRestConfig::class)
open class BookConfig {

/**
* Constant string object.
*/
companion object {
const val BOOK_ENDPOINT = "/v1/books"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.synapse.kotlin.book.controller

import io.americanexpress.synapse.kotlin.book.config.BookConfig
import io.americanexpress.synapse.kotlin.book.model.BookRequest
import io.americanexpress.synapse.kotlin.book.model.BookResponse
import io.americanexpress.synapse.kotlin.book.service.CreateBookService
import io.americanexpress.synapse.service.rest.controller.BaseCreateController
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestMapping

/**
* {@code CreateBookController} Create book controller Kotlin example for Synapse.
*/
@Controller
@RequestMapping(BookConfig.BOOK_ENDPOINT)
open class CreateBookController : BaseCreateController<BookRequest, BookResponse, CreateBookService>()
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.synapse.kotlin.book.controller

import io.americanexpress.synapse.kotlin.book.config.BookConfig.Companion.BOOK_ENDPOINT
import io.americanexpress.synapse.kotlin.book.service.DeleteBookService
import io.americanexpress.synapse.service.rest.controller.BaseDeleteController
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

/**
* {@code DeleteBookController} Delete book controller Kotlin example for Synapse.
*/
@RestController
@RequestMapping(BOOK_ENDPOINT)
open class DeleteBookController : BaseDeleteController<DeleteBookService>()
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.synapse.kotlin.book.controller

import io.americanexpress.synapse.kotlin.book.config.BookConfig.Companion.BOOK_ENDPOINT
import io.americanexpress.synapse.kotlin.book.model.BookResponse
import io.americanexpress.synapse.kotlin.book.service.GetBookService
import io.americanexpress.synapse.service.rest.controller.BaseGetMonoController
import org.springframework.stereotype.Controller
import org.springframework.web.bind.annotation.RequestMapping

/**
* {@code GetBookController} Get book controller Kotlin example for Synapse.
*/
@Controller
@RequestMapping(BOOK_ENDPOINT)
open class GetBookController : BaseGetMonoController<BookResponse, GetBookService>()
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* 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.synapse.kotlin.book.controller

import io.americanexpress.synapse.kotlin.book.config.BookConfig.Companion.BOOK_ENDPOINT
import io.americanexpress.synapse.kotlin.book.model.BookRequest
import io.americanexpress.synapse.kotlin.book.model.BookResponse
import io.americanexpress.synapse.kotlin.book.service.ReadBookService
import io.americanexpress.synapse.service.rest.controller.BaseReadMonoController
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

/**
* {@code ReadBookController} Read book controller Kotlin example for Synapse.
*/
@RestController
@RequestMapping(BOOK_ENDPOINT)
open class ReadBookController : BaseReadMonoController<BookRequest, BookResponse, ReadBookService>()
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
* 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.synapse.kotlin.book.controller

import io.americanexpress.synapse.kotlin.book.config.BookConfig.Companion.BOOK_ENDPOINT
import io.americanexpress.synapse.kotlin.book.model.BookRequest
import io.americanexpress.synapse.kotlin.book.service.UpdateBookService
import io.americanexpress.synapse.service.rest.controller.BaseUpdateController
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RestController

/**
* {@code UpdateBookController} Update book controller Kotlin example for Synapse.
*/
@RestController
@RequestMapping(BOOK_ENDPOINT)
open class UpdateBookController : BaseUpdateController<BookRequest, UpdateBookService>()
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* 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.synapse.kotlin.book.model

import io.americanexpress.synapse.service.rest.model.BaseServiceRequest

/**
* {@code BookRequest} Request object for Kotlin example using Synpase.
*/
open class BookRequest(
val identifier: String,
val title: String,
val author: String,
) : BaseServiceRequest {
constructor() : this("", "", "")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
/*
* 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.synapse.kotlin.book.model

import io.americanexpress.synapse.service.rest.model.BaseServiceResponse

/**
* {@code BookResponse} Response object for Kotlin example using Synapse.
*/
open class BookResponse(
val title: String,
val author: String
) : BaseServiceResponse() {
constructor() : this("", "")
}
Loading