From b48d2e906fe57a66357e2e6d4094e3e613f5f645 Mon Sep 17 00:00:00 2001 From: Tin Pham Date: Thu, 7 Dec 2023 20:28:11 -0800 Subject: [PATCH] change return type in serivces --- .../data/network/product/ProductService.kt | 4 ++-- .../network/product/ProductServiceImpl.kt | 21 +++++++------------ 2 files changed, 10 insertions(+), 15 deletions(-) diff --git a/app/src/main/java/com/example/belindas_closet/data/network/product/ProductService.kt b/app/src/main/java/com/example/belindas_closet/data/network/product/ProductService.kt index d6a5426e..5a7eaf97 100644 --- a/app/src/main/java/com/example/belindas_closet/data/network/product/ProductService.kt +++ b/app/src/main/java/com/example/belindas_closet/data/network/product/ProductService.kt @@ -14,9 +14,9 @@ import io.ktor.serialization.kotlinx.json.json import kotlinx.serialization.json.Json interface ProductService { - suspend fun getProduct(productRequest: ProductRequest): ProductRequest? + suspend fun getProduct(productRequest: ProductRequest): ProductResponse? - suspend fun getProducts(productRequest: ProductRequest): List? + suspend fun getProducts(): List? suspend fun addProduct(productRequest: ProductRequest): ProductResponse? diff --git a/app/src/main/java/com/example/belindas_closet/data/network/product/ProductServiceImpl.kt b/app/src/main/java/com/example/belindas_closet/data/network/product/ProductServiceImpl.kt index 23d4e3c9..0f81fca2 100644 --- a/app/src/main/java/com/example/belindas_closet/data/network/product/ProductServiceImpl.kt +++ b/app/src/main/java/com/example/belindas_closet/data/network/product/ProductServiceImpl.kt @@ -22,33 +22,28 @@ class ProductServiceImpl ( private val client: HttpClient, private val getToken: suspend () -> String ) : ProductService { - override suspend fun getProduct(productRequest: ProductRequest): ProductRequest? { + override suspend fun getProduct(productRequest: ProductRequest): ProductResponse? { TODO("Not yet implemented") } - @OptIn(InternalAPI::class) - override suspend fun getProducts(productRequest: ProductRequest): List? { + override suspend fun getProducts(): List? { return try { - val token = getToken() - val response = client.get { + client.get { url (HttpRoutes.PRODUCTS) - header(HttpHeaders.ContentType, ContentType.Application.Json.toString()) - header(HttpHeaders.Authorization, "Bearer $token") - body = Json.encodeToString(ProductRequest.serializer(), productRequest) } - response.body() + emptyList() } catch (e: RedirectResponseException) { println("Error: ${e.response.status.description}") - null + emptyList() } catch (e: ClientRequestException) { println("Error: ${e.response.status.description}") - null + emptyList() } catch (e: ServerResponseException) { println("Error: ${e.response.status.description}") - null + emptyList() } catch (e: Exception) { println("Error: ${e.message}") - null + emptyList() } }