Created
September 5, 2018 03:32
-
-
Save thiagotn/951a1563854a864fc373a8db397e2c08 to your computer and use it in GitHub Desktop.
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
package com.example.demoapi.products | |
import org.springframework.stereotype.Service | |
@Service | |
class ProductsService { | |
fun create(product: Product): Product = product | |
fun list(): List<Product> { | |
val products = mutableListOf<Product>() | |
for (i in 1..2) { products.add(fakeProduct(i)) } | |
return products | |
} | |
fun read(id: Int): Product? { | |
if (listOf(1,2).contains(id)) { return fakeProduct(id) } | |
return null | |
} | |
fun update(product: Product): Product? { | |
if (listOf(1,2).contains(product.id)) { | |
return product | |
} | |
return null | |
} | |
fun delete(id: String) { | |
} | |
private fun fakeProduct(id: Int): Product = Product(id = id, name = "Book Kotlin for Android Developers - ${id}st Edition", description = "Kotlin for Android Developers - ${id}st Edition: Learn Kotlin the easy way while developing an Android App") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment