Created
July 13, 2022 07:11
-
-
Save raphaeldelio/25bd79e1a77dea5296c5ad49c7195d41 to your computer and use it in GitHub Desktop.
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
| import org.jetbrains.kotlin.gradle.tasks.KotlinCompile | |
| plugins { | |
| id("org.springframework.boot") version "2.7.1" | |
| id("io.spring.dependency-management") version "1.0.11.RELEASE" | |
| kotlin("jvm") version "1.6.21" | |
| kotlin("plugin.spring") version "1.6.21" | |
| } | |
| group = "com.raphaeldelio" | |
| version = "0.0.1-SNAPSHOT" | |
| java.sourceCompatibility = JavaVersion.VERSION_17 | |
| repositories { | |
| mavenCentral() | |
| } | |
| dependencies { | |
| implementation("org.springframework.boot:spring-boot-starter") | |
| implementation("org.springframework.boot:spring-boot-starter-web") | |
| implementation("org.jetbrains.kotlin:kotlin-reflect") | |
| implementation("org.jetbrains.kotlin:kotlin-stdlib-jdk8") | |
| implementation("com.redis.om:redis-om-spring:0.5.0") | |
| testImplementation("org.springframework.boot:spring-boot-starter-test") | |
| } | |
| tasks.withType<KotlinCompile> { | |
| kotlinOptions { | |
| freeCompilerArgs = listOf("-Xjsr305=strict") | |
| jvmTarget = "17" | |
| } | |
| } | |
| tasks.withType<Test> { | |
| useJUnitPlatform() | |
| } |
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
| data class Product( | |
| @Indexed | |
| val name: String, | |
| @Indexed | |
| val price: Double | |
| ) |
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
| @Document | |
| data class Store( | |
| @Id | |
| @Indexed | |
| var id: String? = null, | |
| @Indexed | |
| var name: String, | |
| @Searchable | |
| var storeLogo: String, | |
| @Indexed | |
| var products: List<Product> | |
| ) |
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
| @RestController | |
| @RequestMapping("/store") | |
| class StoreController( | |
| private val storeRepository: StoreRepository | |
| ) { | |
| @GetMapping | |
| fun getAll(): List<Store> { | |
| return storeRepository.findAll().toList() | |
| } | |
| @PostMapping | |
| fun save(@RequestBody store: Store): Store { | |
| return storeRepository.save(store) | |
| } | |
| @PutMapping | |
| fun updateNameById(@RequestParam id: String, @RequestParam name: String): Optional<Store> { | |
| val store = storeRepository.findById(id) | |
| store.ifPresent { | |
| it.name = name | |
| storeRepository.save(it) | |
| } | |
| return store | |
| } | |
| @DeleteMapping | |
| fun deleteById(@RequestParam id: String) { | |
| storeRepository.deleteById(id) | |
| } | |
| } |
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
| interface StoreRepository : RedisDocumentRepository<Store, String> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment