diff --git a/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/mapper/InvoiceMapper.kt b/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/mapper/InvoiceMapper.kt index d4d5b6f..7fabfb4 100644 --- a/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/mapper/InvoiceMapper.kt +++ b/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/mapper/InvoiceMapper.kt @@ -1,10 +1,12 @@ package com.example.shoestoreapp.features.invoice.data.mapper -import com.example.shoestoreapp.features.invoice.data.remote.Item +import com.example.shoestoreapp.features.invoice.data.remote.DetailDto +import com.example.shoestoreapp.features.invoice.data.remote.ItemDto +import com.example.shoestoreapp.features.invoice.model.Detail import com.example.shoestoreapp.features.invoice.model.Invoice import com.example.shoestoreapp.features.invoice.model.InvoiceStatus -fun Item.toDomain() : Invoice { +fun ItemDto.toDomain() : Invoice { return Invoice( orderCode = this.orderCode ?: "", userName = this.username ?: "Empty", @@ -20,4 +22,15 @@ fun Item.toDomain() : Invoice { createdAt = this.dateCreated, finalPrice = this.finalPrice ) +} + +fun DetailDto.toDomain() : Detail { + return Detail( + color = this.color ?: "", + imageUrl = this.imageUrl ?: "", + productName = this.productName ?: "", + quantity = this.quantity ?: 0, + size = this.size ?: 0, + unitPrice = this.unitPrice ?: 0 + ) } \ No newline at end of file diff --git a/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/DetailDto.kt b/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/DetailDto.kt new file mode 100644 index 0000000..29d570c --- /dev/null +++ b/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/DetailDto.kt @@ -0,0 +1,19 @@ +package com.example.shoestoreapp.features.invoice.data.remote + + +import com.google.gson.annotations.SerializedName + +data class DetailDto( + @SerializedName("color") + val color: String?, + @SerializedName("imageUrl") + val imageUrl: String?, + @SerializedName("productName") + val productName: String?, + @SerializedName("quantity") + val quantity: Int?, + @SerializedName("size") + val size: Int?, + @SerializedName("unitPrice") + val unitPrice: Int? +) \ No newline at end of file diff --git a/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/InvoiceApi.kt b/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/InvoiceApi.kt index 07dd5ee..8be71f4 100644 --- a/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/InvoiceApi.kt +++ b/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/InvoiceApi.kt @@ -9,7 +9,7 @@ import retrofit2.http.Query interface InvoiceApi { @GET ("api/invoice/admin/get-all") - suspend fun getallInvoices( + suspend fun getAllInvoices( @Query("PageNumber") pageNumber: Int = 1, @Query("PageSize") pageSize: Int = 10 ): Response diff --git a/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/InvoiceDetailsDto.kt b/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/InvoiceDetailsDto.kt index c176c56..14ba91c 100644 --- a/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/InvoiceDetailsDto.kt +++ b/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/InvoiceDetailsDto.kt @@ -5,7 +5,7 @@ import com.google.gson.annotations.SerializedName data class InvoiceDetailsDto( @SerializedName("data") - val `data`: List?, + val detailDto: List?, @SerializedName("message") val message: String? ) \ No newline at end of file diff --git a/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/InvoiceListDto.kt b/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/InvoiceListDto.kt index 73f1403..00d892b 100644 --- a/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/InvoiceListDto.kt +++ b/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/InvoiceListDto.kt @@ -9,7 +9,7 @@ data class InvoiceListDto( @SerializedName("hasPrevious") val hasPrevious: Boolean?, @SerializedName("items") - val item: List?, + val itemDto: List?, @SerializedName("pageNumber") val pageNumber: String?, @SerializedName("pageSize") diff --git a/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/Item.kt b/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/ItemDto.kt similarity index 97% rename from Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/Item.kt rename to Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/ItemDto.kt index 3e8bf76..5bb4f6e 100644 --- a/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/Item.kt +++ b/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/remote/ItemDto.kt @@ -3,7 +3,7 @@ package com.example.shoestoreapp.features.invoice.data.remote import com.google.gson.annotations.SerializedName -data class Item( +data class ItemDto( @SerializedName("address") val address: String?, @SerializedName("dateCreated") diff --git a/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/repositories/InvoiceRepositoryImpl.kt b/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/repositories/InvoiceRepositoryImpl.kt new file mode 100644 index 0000000..4a44e5f --- /dev/null +++ b/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/data/repositories/InvoiceRepositoryImpl.kt @@ -0,0 +1,36 @@ +package com.example.shoestoreapp.features.invoice.data.repositories + +import com.example.shoestoreapp.features.invoice.data.remote.InvoiceApi +import com.example.shoestoreapp.features.invoice.data.mapper.toDomain +import com.example.shoestoreapp.features.invoice.data.remote.UpdateStatusRequestDto +import com.example.shoestoreapp.features.invoice.model.Invoice +import com.example.shoestoreapp.features.invoice.model.Detail +class InvoiceRepositoryImpl (private val api : InvoiceApi) { + suspend fun getAllInvoices(): Result> = runCatching { + val response = api.getAllInvoices(pageNumber = 1, pageSize = 10) + if (response.isSuccessful) { + val dtos = response.body()?.itemDto ?: emptyList() + dtos.map { it.toDomain() } + } else { + throw Exception("Lỗi API: ${response.code()} - ${response.message()}") + } + } + + suspend fun updateInvoiceStatus(invoiceGuid: String, status: Int): Result = runCatching { + val request = UpdateStatusRequestDto(status = status) + val response = api.updateInvoiceStatus(invoiceGuid, request) + if (!response.isSuccessful) { + throw Exception("Lỗi update : ${response.code()} - ${response.message()}") + } + } + + suspend fun getInvoiceDetails(invoiceGuid: String): Result> = runCatching { + val response = api.getInvoiceDetails(invoiceGuid) + if (response.isSuccessful) { + val dtos = response.body()?.detailDto ?: emptyList() + dtos.map { it.toDomain() } + } else { + throw Exception("Lỗi : ${response.code()} - ${response.message()}") + } + } +} \ No newline at end of file diff --git a/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/model/InvoiceModels.kt b/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/model/InvoiceModels.kt index 5342047..a2a4858 100644 --- a/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/model/InvoiceModels.kt +++ b/Frontend/app/src/main/java/com/example/shoestoreapp/features/invoice/model/InvoiceModels.kt @@ -16,6 +16,15 @@ data class Invoice( val createdAt: String?, val finalPrice: String?, ) +// Data Details +data class Detail ( + val color: String, + val imageUrl: String, + val productName: String, + val quantity: Int, + val size: Int, + val unitPrice: Int +) fun InvoiceStatus.displayName(): String { return when (this) {