From 181106eaf511a95da56a195e6720837982b102e9 Mon Sep 17 00:00:00 2001 From: Gracia Date: Sat, 19 Apr 2025 20:49:38 +0700 Subject: [PATCH] update product --- app/src/main/AndroidManifest.xml | 2 +- .../data/api/dto/CheckoutData.kt | 2 +- .../ecommerce_serang/data/api/dto/Preorder.kt | 15 ++ .../ecommerce_serang/data/api/dto/Product.kt | 5 +- .../{ => customer}/cart/AddCartResponse.kt | 2 +- .../{ => customer}/cart/CartActivity.kt | 2 +- .../{ => customer}/cart/ListCartResponse.kt | 2 +- .../{ => customer}/cart/UpdateCartResponse.kt | 2 +- .../order/CourierCostResponse.kt | 2 +- .../order/CreateOrderResponse.kt | 2 +- .../{ => customer}/order/ListCityResponse.kt | 2 +- .../order/ListProvinceResponse.kt | 2 +- .../order/OrderDetailResponse.kt | 2 +- .../{ => customer}/order/OrderListResponse.kt | 2 +- .../product/AllProductResponse.kt | 2 +- .../product/AllStoreResponse.kt | 2 +- .../product/CategoryResponse.kt | 2 +- .../product/DetailStoreProductResponse.kt | 2 +- .../{ => customer}/product/ProductResponse.kt | 2 +- .../product/ReviewProductResponse.kt | 2 +- .../{ => customer}/product/StoreResponse.kt | 2 +- .../{ => customer}/profile/AddressResponse.kt | 2 +- .../profile/CreateAddressResponse.kt | 2 +- .../{ => customer}/profile/ProfileResponse.kt | 2 +- .../orders/AddShippingReceiptResponse.kt | 9 + .../store/orders/KonfirmasiTagihanResponse.kt | 48 +++++ .../store/orders/OrderListResponse.kt | 168 ++++++++++++++++ .../orders/PaymentConfirmationResponse.kt | 9 + .../store/orders/UpdateOrderItemResponse.kt | 75 +++++++ .../product/CreateProductResponse.kt | 16 +- .../store/product/DeleteProductResponse.kt | 9 + .../store/product/UpdateProductResponse.kt | 13 ++ .../product}/ViewStoreProductsResponse.kt | 4 +- .../data/api/retrofit/ApiService.kt | 54 ++++-- .../data/repository/MyStoreRepository.kt | 2 +- .../data/repository/OrderRepository.kt | 20 +- .../data/repository/ProductRepository.kt | 45 ++++- .../ui/order/CartCheckoutAdapter.kt | 2 +- .../ui/order/CheckoutActivity.kt | 2 +- .../ui/order/CheckoutViewModel.kt | 8 +- .../ui/order/PaymentMethodAdapter.kt | 2 +- .../ui/order/ShippingAdapter.kt | 4 +- .../ui/order/ShippingViewModel.kt | 2 +- .../ui/order/SingleItemCartAdapter.kt | 2 +- .../ui/order/address/AddAddressActivity.kt | 4 +- .../ui/order/address/AddAddressViewModel.kt | 4 +- .../ui/order/address/AddressAdapter.kt | 2 +- .../ui/order/address/AddressViewModel.kt | 2 +- .../ui/order/address/ProvinceAdapter.kt | 4 +- .../ui/product/DetailProductActivity.kt | 6 +- .../ui/product/ProductUserViewModel.kt | 8 +- .../ui/product/ReviewsAdapter.kt | 2 +- .../mystore/product/ProductActivity.kt | 7 +- .../ProductOptionsBottomSheetFragment.kt | 25 ++- .../product/StoreProductDetailActivity.kt | 183 +++++++++++++----- .../utils/viewmodel/ProductViewModel.kt | 43 +++- app/src/main/res/layout/activity_cart.xml | 2 +- .../layout/activity_store_product_detail.xml | 102 +++++----- 58 files changed, 731 insertions(+), 221 deletions(-) create mode 100644 app/src/main/java/com/alya/ecommerce_serang/data/api/dto/Preorder.kt rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/cart/AddCartResponse.kt (88%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/cart/CartActivity.kt (91%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/cart/ListCartResponse.kt (93%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/cart/UpdateCartResponse.kt (68%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/order/CourierCostResponse.kt (89%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/order/CreateOrderResponse.kt (96%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/order/ListCityResponse.kt (83%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/order/ListProvinceResponse.kt (84%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/order/OrderDetailResponse.kt (97%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/order/OrderListResponse.kt (96%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/product/AllProductResponse.kt (79%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/product/AllStoreResponse.kt (89%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/product/CategoryResponse.kt (79%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/product/DetailStoreProductResponse.kt (94%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/product/ProductResponse.kt (94%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/product/ReviewProductResponse.kt (91%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/product/StoreResponse.kt (97%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/profile/AddressResponse.kt (93%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/profile/CreateAddressResponse.kt (67%) rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => customer}/profile/ProfileResponse.kt (78%) create mode 100644 app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/orders/AddShippingReceiptResponse.kt create mode 100644 app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/orders/KonfirmasiTagihanResponse.kt create mode 100644 app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/orders/OrderListResponse.kt create mode 100644 app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/orders/PaymentConfirmationResponse.kt create mode 100644 app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/orders/UpdateOrderItemResponse.kt rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => store}/product/CreateProductResponse.kt (51%) create mode 100644 app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/product/DeleteProductResponse.kt create mode 100644 app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/product/UpdateProductResponse.kt rename app/src/main/java/com/alya/ecommerce_serang/data/api/response/{ => store/product}/ViewStoreProductsResponse.kt (81%) diff --git a/app/src/main/AndroidManifest.xml b/app/src/main/AndroidManifest.xml index 4fb8fce..f53b801 100644 --- a/app/src/main/AndroidManifest.xml +++ b/app/src/main/AndroidManifest.xml @@ -22,7 +22,7 @@ android:usesCleartextTraffic="true" tools:targetApi="31"> ? = null +) + +data class UpdatedOrder( + + @field:SerializedName("payment_method_id") + val paymentMethodId: Int? = null, + + @field:SerializedName("updated_at") + val updatedAt: String? = null, + + @field:SerializedName("total_amount") + val totalAmount: String? = null, + + @field:SerializedName("user_id") + val userId: Int? = null, + + @field:SerializedName("address_id") + val addressId: Int? = null, + + @field:SerializedName("is_negotiable") + val isNegotiable: Boolean? = null, + + @field:SerializedName("created_at") + val createdAt: String? = null, + + @field:SerializedName("voucher_id") + val voucherId: Any? = null, + + @field:SerializedName("id") + val id: Int? = null, + + @field:SerializedName("status") + val status: String? = null +) diff --git a/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/orders/OrderListResponse.kt b/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/orders/OrderListResponse.kt new file mode 100644 index 0000000..ec5d048 --- /dev/null +++ b/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/orders/OrderListResponse.kt @@ -0,0 +1,168 @@ +package com.alya.ecommerce_serang.data.api.response.store.orders + +import com.google.gson.annotations.SerializedName + +data class OrderListResponse( + + @field:SerializedName("orders") + val orders: List? = null, + + @field:SerializedName("message") + val message: String? = null +) + +data class Voucher( + + @field:SerializedName("name") + val name: Any? = null, + + @field:SerializedName("voucher_id") + val voucherId: Any? = null, + + @field:SerializedName("voucher_code") + val voucherCode: Any? = null +) + +data class Shipment( + + @field:SerializedName("receipt_num") + val receiptNum: Any? = null, + + @field:SerializedName("courier") + val courier: Any? = null, + + @field:SerializedName("price") + val price: Any? = null, + + @field:SerializedName("service") + val service: Any? = null, + + @field:SerializedName("shipment_id") + val shipmentId: Any? = null, + + @field:SerializedName("status") + val status: Any? = null +) + +data class OrderItemsItem( + + @field:SerializedName("review_id") + val reviewId: Int? = null, + + @field:SerializedName("quantity") + val quantity: Int? = null, + + @field:SerializedName("price") + val price: Int? = null, + + @field:SerializedName("subtotal") + val subtotal: Int? = null, + + @field:SerializedName("product_image") + val productImage: String? = null, + + @field:SerializedName("store_name") + val storeName: String? = null, + + @field:SerializedName("product_price") + val productPrice: Int? = null, + + @field:SerializedName("product_name") + val productName: String? = null +) + +data class Address( + + @field:SerializedName("is_store_location") + val isStoreLocation: Boolean? = null, + + @field:SerializedName("province_id") + val provinceId: Int? = null, + + @field:SerializedName("street") + val street: String? = null, + + @field:SerializedName("subdistrict") + val subdistrict: String? = null, + + @field:SerializedName("latitude") + val latitude: Any? = null, + + @field:SerializedName("address_id") + val addressId: Int? = null, + + @field:SerializedName("detail") + val detail: String? = null, + + @field:SerializedName("postal_code") + val postalCode: String? = null, + + @field:SerializedName("longitude") + val longitude: Any? = null, + + @field:SerializedName("city_id") + val cityId: Int? = null +) + +data class Payment( + + @field:SerializedName("evidence") + val evidence: Any? = null, + + @field:SerializedName("uploaded_at") + val uploadedAt: Any? = null, + + @field:SerializedName("payment_id") + val paymentId: Any? = null +) + +data class OrdersItem( + + @field:SerializedName("address") + val address: Address? = null, + + @field:SerializedName("shipment") + val shipment: Shipment? = null, + + @field:SerializedName("voucher") + val voucher: Voucher? = null, + + @field:SerializedName("address_id") + val addressId: Int? = null, + + @field:SerializedName("is_negotiable") + val isNegotiable: Boolean? = null, + + @field:SerializedName("created_at") + val createdAt: String? = null, + + @field:SerializedName("payment_method_id") + val paymentMethodId: Int? = null, + + @field:SerializedName("updated_at") + val updatedAt: String? = null, + + @field:SerializedName("user_id") + val userId: Int? = null, + + @field:SerializedName("total_amount") + val totalAmount: String? = null, + + @field:SerializedName("voucher_id") + val voucherId: Any? = null, + + @field:SerializedName("payment") + val payment: Payment? = null, + + @field:SerializedName("order_id") + val orderId: Int? = null, + + @field:SerializedName("username") + val username: String? = null, + + @field:SerializedName("status") + val status: String? = null, + + @field:SerializedName("order_items") + val orderItems: List? = null +) diff --git a/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/orders/PaymentConfirmationResponse.kt b/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/orders/PaymentConfirmationResponse.kt new file mode 100644 index 0000000..498cb6f --- /dev/null +++ b/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/orders/PaymentConfirmationResponse.kt @@ -0,0 +1,9 @@ +package com.alya.ecommerce_serang.data.api.response.store.orders + +import com.google.gson.annotations.SerializedName + +data class PaymentConfirmationResponse( + + @field:SerializedName("message") + val message: String? = null +) diff --git a/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/orders/UpdateOrderItemResponse.kt b/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/orders/UpdateOrderItemResponse.kt new file mode 100644 index 0000000..9e6b08c --- /dev/null +++ b/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/orders/UpdateOrderItemResponse.kt @@ -0,0 +1,75 @@ +package com.alya.ecommerce_serang.data.api.response.store.orders + +import com.google.gson.annotations.SerializedName + +data class UpdateOrderItemResponse( + + @field:SerializedName("message") + val message: String? = null, + + @field:SerializedName("updatedOrder") + val updatedOrder: UpdatedOrder? = null, + + @field:SerializedName("updatedItems") + val updatedItems: List? = null +) + +data class UpdatedItemsItem( + + @field:SerializedName("quantity") + val quantity: Int? = null, + + @field:SerializedName("price") + val price: String? = null, + + @field:SerializedName("subtotal") + val subtotal: String? = null, + + @field:SerializedName("product_id") + val productId: Int? = null, + + @field:SerializedName("id") + val id: Int? = null, + + @field:SerializedName("order_id") + val orderId: Int? = null +) + +data class UpdatedOrder( + + @field:SerializedName("auto_canceled_at") + val autoCanceledAt: String? = null, + + @field:SerializedName("payment_method_id") + val paymentMethodId: Int? = null, + + @field:SerializedName("auto_completed_at") + val autoCompletedAt: String? = null, + + @field:SerializedName("updated_at") + val updatedAt: String? = null, + + @field:SerializedName("total_amount") + val totalAmount: String? = null, + + @field:SerializedName("user_id") + val userId: Int? = null, + + @field:SerializedName("address_id") + val addressId: Int? = null, + + @field:SerializedName("is_negotiable") + val isNegotiable: Boolean? = null, + + @field:SerializedName("created_at") + val createdAt: String? = null, + + @field:SerializedName("voucher_id") + val voucherId: Any? = null, + + @field:SerializedName("id") + val id: Int? = null, + + @field:SerializedName("status") + val status: String? = null +) diff --git a/app/src/main/java/com/alya/ecommerce_serang/data/api/response/product/CreateProductResponse.kt b/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/product/CreateProductResponse.kt similarity index 51% rename from app/src/main/java/com/alya/ecommerce_serang/data/api/response/product/CreateProductResponse.kt rename to app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/product/CreateProductResponse.kt index fcd9aec..53d6bf6 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/data/api/response/product/CreateProductResponse.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/product/CreateProductResponse.kt @@ -1,5 +1,7 @@ -package com.alya.ecommerce_serang.data.api.response.product +package com.alya.ecommerce_serang.data.api.response.store.product +import com.alya.ecommerce_serang.data.api.dto.Preorder +import com.alya.ecommerce_serang.data.api.dto.Product import com.google.gson.annotations.SerializedName data class CreateProductResponse( @@ -13,15 +15,3 @@ data class CreateProductResponse( @field:SerializedName("preorder") val preorder: Preorder? = null ) - -data class Preorder( - - @field:SerializedName("duration") - val duration: Int? = null, - - @field:SerializedName("product_id") - val productId: Int? = null, - - @field:SerializedName("id") - val id: Int? = null -) diff --git a/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/product/DeleteProductResponse.kt b/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/product/DeleteProductResponse.kt new file mode 100644 index 0000000..2365d34 --- /dev/null +++ b/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/product/DeleteProductResponse.kt @@ -0,0 +1,9 @@ +package com.alya.ecommerce_serang.data.api.response.store.product + +import com.google.gson.annotations.SerializedName + +data class DeleteProductResponse( + + @field:SerializedName("message") + val message: String? = null +) diff --git a/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/product/UpdateProductResponse.kt b/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/product/UpdateProductResponse.kt new file mode 100644 index 0000000..b20fe20 --- /dev/null +++ b/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/product/UpdateProductResponse.kt @@ -0,0 +1,13 @@ +package com.alya.ecommerce_serang.data.api.response.store.product + +import com.alya.ecommerce_serang.data.api.dto.Product +import com.google.gson.annotations.SerializedName + +data class UpdateProductResponse( + + @field:SerializedName("product") + val product: Product? = null, + + @field:SerializedName("message") + val message: String? = null +) diff --git a/app/src/main/java/com/alya/ecommerce_serang/data/api/response/ViewStoreProductsResponse.kt b/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/product/ViewStoreProductsResponse.kt similarity index 81% rename from app/src/main/java/com/alya/ecommerce_serang/data/api/response/ViewStoreProductsResponse.kt rename to app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/product/ViewStoreProductsResponse.kt index c933ac7..1566de1 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/data/api/response/ViewStoreProductsResponse.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/data/api/response/store/product/ViewStoreProductsResponse.kt @@ -1,4 +1,4 @@ -package com.alya.ecommerce_serang.data.api.response +package com.alya.ecommerce_serang.data.api.response.store.product import com.alya.ecommerce_serang.data.api.dto.ProductsItem import com.google.gson.annotations.SerializedName @@ -10,4 +10,4 @@ data class ViewStoreProductsResponse( @field:SerializedName("products") val products: List? = null -) +) \ No newline at end of file diff --git a/app/src/main/java/com/alya/ecommerce_serang/data/api/retrofit/ApiService.kt b/app/src/main/java/com/alya/ecommerce_serang/data/api/retrofit/ApiService.kt index 50344b0..43528f2 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/data/api/retrofit/ApiService.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/data/api/retrofit/ApiService.kt @@ -9,40 +9,42 @@ import com.alya.ecommerce_serang.data.api.dto.OrderRequestBuy import com.alya.ecommerce_serang.data.api.dto.OtpRequest import com.alya.ecommerce_serang.data.api.dto.RegisterRequest import com.alya.ecommerce_serang.data.api.dto.UpdateCart -import com.alya.ecommerce_serang.data.api.response.product.CreateProductResponse -import com.alya.ecommerce_serang.data.api.response.ViewStoreProductsResponse +import com.alya.ecommerce_serang.data.api.response.store.product.CreateProductResponse +import com.alya.ecommerce_serang.data.api.response.store.product.ViewStoreProductsResponse import okhttp3.MultipartBody import okhttp3.RequestBody import com.alya.ecommerce_serang.data.api.response.auth.LoginResponse import com.alya.ecommerce_serang.data.api.response.auth.OtpResponse import com.alya.ecommerce_serang.data.api.response.auth.RegisterResponse -import com.alya.ecommerce_serang.data.api.response.cart.AddCartResponse -import com.alya.ecommerce_serang.data.api.response.cart.ListCartResponse -import com.alya.ecommerce_serang.data.api.response.cart.UpdateCartResponse -import com.alya.ecommerce_serang.data.api.response.order.CourierCostResponse -import com.alya.ecommerce_serang.data.api.response.order.CreateOrderResponse -import com.alya.ecommerce_serang.data.api.response.order.ListCityResponse -import com.alya.ecommerce_serang.data.api.response.order.ListProvinceResponse -import com.alya.ecommerce_serang.data.api.response.product.AllProductResponse -import com.alya.ecommerce_serang.data.api.response.product.CategoryResponse -import com.alya.ecommerce_serang.data.api.response.product.DetailStoreProductResponse -import com.alya.ecommerce_serang.data.api.response.product.ProductResponse -import com.alya.ecommerce_serang.data.api.response.product.ReviewProductResponse -import com.alya.ecommerce_serang.data.api.response.product.StoreResponse -import com.alya.ecommerce_serang.data.api.response.profile.AddressResponse -import com.alya.ecommerce_serang.data.api.response.profile.CreateAddressResponse -import com.alya.ecommerce_serang.data.api.response.profile.ProfileResponse +import com.alya.ecommerce_serang.data.api.response.customer.cart.AddCartResponse +import com.alya.ecommerce_serang.data.api.response.customer.cart.ListCartResponse +import com.alya.ecommerce_serang.data.api.response.customer.cart.UpdateCartResponse +import com.alya.ecommerce_serang.data.api.response.customer.order.CourierCostResponse +import com.alya.ecommerce_serang.data.api.response.customer.order.CreateOrderResponse +import com.alya.ecommerce_serang.data.api.response.customer.order.ListCityResponse +import com.alya.ecommerce_serang.data.api.response.customer.order.ListProvinceResponse +import com.alya.ecommerce_serang.data.api.response.customer.product.AllProductResponse +import com.alya.ecommerce_serang.data.api.response.customer.product.CategoryResponse +import com.alya.ecommerce_serang.data.api.response.customer.product.DetailStoreProductResponse +import com.alya.ecommerce_serang.data.api.response.customer.product.ProductResponse +import com.alya.ecommerce_serang.data.api.response.customer.product.ReviewProductResponse +import com.alya.ecommerce_serang.data.api.response.customer.product.StoreResponse +import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressResponse +import com.alya.ecommerce_serang.data.api.response.customer.profile.CreateAddressResponse +import com.alya.ecommerce_serang.data.api.response.customer.profile.ProfileResponse +import com.alya.ecommerce_serang.data.api.response.store.product.DeleteProductResponse +import com.alya.ecommerce_serang.data.api.response.store.product.UpdateProductResponse import retrofit2.Call import retrofit2.Response import retrofit2.http.Body +import retrofit2.http.DELETE import retrofit2.http.GET -import retrofit2.http.Header -import retrofit2.http.HeaderMap import retrofit2.http.Multipart import retrofit2.http.POST import retrofit2.http.Part import retrofit2.http.PUT import retrofit2.http.Path +import retrofit2.http.Query interface ApiService { @POST("registeruser") @@ -126,11 +128,23 @@ interface ApiService { @Part("duration") duration: RequestBody, @Part("category_id") categoryId: RequestBody, @Part("status") status: RequestBody, + @Part("condition") condition: RequestBody, @Part image: MultipartBody.Part?, @Part sppirt: MultipartBody.Part?, @Part halal: MultipartBody.Part? ): Response + @PUT("store/editproduct/{id}") + suspend fun updateProduct( + @Path("id") productId: Int?, + @Body updatedProduct: Map + ): Response + + @DELETE("store/deleteproduct/{id}") + suspend fun deleteProduct( + @Path("id") productId: Int + ): Response + @GET("cart_item") suspend fun getCart (): Response diff --git a/app/src/main/java/com/alya/ecommerce_serang/data/repository/MyStoreRepository.kt b/app/src/main/java/com/alya/ecommerce_serang/data/repository/MyStoreRepository.kt index 71dd35c..c14a0fd 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/data/repository/MyStoreRepository.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/data/repository/MyStoreRepository.kt @@ -2,7 +2,7 @@ package com.alya.ecommerce_serang.data.repository import android.util.Log import com.alya.ecommerce_serang.data.api.dto.Store -import com.alya.ecommerce_serang.data.api.response.product.StoreResponse +import com.alya.ecommerce_serang.data.api.response.customer.product.StoreResponse import com.alya.ecommerce_serang.data.api.retrofit.ApiService import retrofit2.HttpException import java.io.IOException diff --git a/app/src/main/java/com/alya/ecommerce_serang/data/repository/OrderRepository.kt b/app/src/main/java/com/alya/ecommerce_serang/data/repository/OrderRepository.kt index d2aad68..f3b2bcf 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/data/repository/OrderRepository.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/data/repository/OrderRepository.kt @@ -5,16 +5,16 @@ import com.alya.ecommerce_serang.data.api.dto.CourierCostRequest import com.alya.ecommerce_serang.data.api.dto.CreateAddressRequest import com.alya.ecommerce_serang.data.api.dto.OrderRequest import com.alya.ecommerce_serang.data.api.dto.OrderRequestBuy -import com.alya.ecommerce_serang.data.api.response.cart.DataItem -import com.alya.ecommerce_serang.data.api.response.order.CourierCostResponse -import com.alya.ecommerce_serang.data.api.response.order.CreateOrderResponse -import com.alya.ecommerce_serang.data.api.response.order.ListCityResponse -import com.alya.ecommerce_serang.data.api.response.order.ListProvinceResponse -import com.alya.ecommerce_serang.data.api.response.product.ProductResponse -import com.alya.ecommerce_serang.data.api.response.product.StoreProduct -import com.alya.ecommerce_serang.data.api.response.product.StoreResponse -import com.alya.ecommerce_serang.data.api.response.profile.AddressResponse -import com.alya.ecommerce_serang.data.api.response.profile.CreateAddressResponse +import com.alya.ecommerce_serang.data.api.response.customer.cart.DataItem +import com.alya.ecommerce_serang.data.api.response.customer.order.CourierCostResponse +import com.alya.ecommerce_serang.data.api.response.customer.order.CreateOrderResponse +import com.alya.ecommerce_serang.data.api.response.customer.order.ListCityResponse +import com.alya.ecommerce_serang.data.api.response.customer.order.ListProvinceResponse +import com.alya.ecommerce_serang.data.api.response.customer.product.ProductResponse +import com.alya.ecommerce_serang.data.api.response.customer.product.StoreProduct +import com.alya.ecommerce_serang.data.api.response.customer.product.StoreResponse +import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressResponse +import com.alya.ecommerce_serang.data.api.response.customer.profile.CreateAddressResponse import com.alya.ecommerce_serang.data.api.retrofit.ApiService import retrofit2.Response diff --git a/app/src/main/java/com/alya/ecommerce_serang/data/repository/ProductRepository.kt b/app/src/main/java/com/alya/ecommerce_serang/data/repository/ProductRepository.kt index 1a8781c..dbf61cc 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/data/repository/ProductRepository.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/data/repository/ProductRepository.kt @@ -3,20 +3,20 @@ package com.alya.ecommerce_serang.data.repository import android.util.Log import com.alya.ecommerce_serang.data.api.dto.CartItem import com.alya.ecommerce_serang.data.api.dto.CategoryItem +import com.alya.ecommerce_serang.data.api.dto.Preorder import com.alya.ecommerce_serang.data.api.dto.ProductsItem -import com.alya.ecommerce_serang.data.api.response.product.CreateProductResponse -import com.alya.ecommerce_serang.data.api.response.cart.AddCartResponse -import com.alya.ecommerce_serang.data.api.response.product.ProductResponse -import com.alya.ecommerce_serang.data.api.response.product.ReviewsItem -import com.alya.ecommerce_serang.data.api.response.product.StoreProduct +import com.alya.ecommerce_serang.data.api.response.store.product.CreateProductResponse +import com.alya.ecommerce_serang.data.api.response.customer.cart.AddCartResponse +import com.alya.ecommerce_serang.data.api.response.customer.product.ProductResponse +import com.alya.ecommerce_serang.data.api.response.customer.product.ReviewsItem +import com.alya.ecommerce_serang.data.api.response.customer.product.StoreProduct +import com.alya.ecommerce_serang.data.api.response.store.product.UpdateProductResponse import com.alya.ecommerce_serang.data.api.retrofit.ApiService -import com.alya.ecommerce_serang.utils.SessionManager import kotlinx.coroutines.Dispatchers import kotlinx.coroutines.withContext import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MultipartBody import okhttp3.RequestBody -import java.io.File class ProductRepository(private val apiService: ApiService) { suspend fun getAllProducts(): Result> = @@ -158,9 +158,10 @@ class ProductRepository(private val apiService: ApiService) { minOrder: Int, weight: Int, isPreOrder: Boolean, - duration: Int, + preorder: Preorder, categoryId: Int, status: String, + condition: String, imagePart: MultipartBody.Part?, sppirtPart: MultipartBody.Part?, halalPart: MultipartBody.Part? @@ -174,9 +175,10 @@ class ProductRepository(private val apiService: ApiService) { minOrder = RequestBody.create("text/plain".toMediaTypeOrNull(), minOrder.toString()), weight = RequestBody.create("text/plain".toMediaTypeOrNull(), weight.toString()), isPreOrder = RequestBody.create("text/plain".toMediaTypeOrNull(), isPreOrder.toString()), - duration = RequestBody.create("text/plain".toMediaTypeOrNull(), duration.toString()), + duration = RequestBody.create("text/plain".toMediaTypeOrNull(), preorder.duration.toString()), categoryId = RequestBody.create("text/plain".toMediaTypeOrNull(), categoryId.toString()), status = RequestBody.create("text/plain".toMediaTypeOrNull(), status), + condition = RequestBody.create("text/plain".toMediaTypeOrNull(), condition), image = imagePart, sppirt = sppirtPart, halal = halalPart @@ -192,6 +194,31 @@ class ProductRepository(private val apiService: ApiService) { } } + suspend fun updateProduct(productId: Int?, updatedProduct: Map) : UpdateProductResponse { + // Build the request with the updated fields + val response = apiService.updateProduct(productId, updatedProduct) + if (response.isSuccessful) { + return response.body()!! + } else { + throw Exception("Gagal memperbarui produk: ${response.code()}") + } + } + + + suspend fun deleteProduct(productId: Int): Result { + return withContext(Dispatchers.IO) { + try { + val response = apiService.deleteProduct(productId) + if (response.isSuccessful) { + Result.Success(Unit) + } else { + Result.Error(Exception("Gagal menghapus produk: ${response.code()}")) + } + } catch (e: Exception) { + Result.Error(e) + } + } + } companion object { private const val TAG = "ProductRepository" diff --git a/app/src/main/java/com/alya/ecommerce_serang/ui/order/CartCheckoutAdapter.kt b/app/src/main/java/com/alya/ecommerce_serang/ui/order/CartCheckoutAdapter.kt index ee71da9..ca38224 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/ui/order/CartCheckoutAdapter.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/ui/order/CartCheckoutAdapter.kt @@ -6,7 +6,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import androidx.recyclerview.widget.RecyclerView import com.alya.ecommerce_serang.R import com.alya.ecommerce_serang.data.api.dto.CheckoutData -import com.alya.ecommerce_serang.data.api.response.cart.CartItemsItem +import com.alya.ecommerce_serang.data.api.response.customer.cart.CartItemsItem import com.alya.ecommerce_serang.databinding.ItemOrderProductBinding import com.alya.ecommerce_serang.databinding.ItemOrderSellerBinding import com.bumptech.glide.Glide diff --git a/app/src/main/java/com/alya/ecommerce_serang/ui/order/CheckoutActivity.kt b/app/src/main/java/com/alya/ecommerce_serang/ui/order/CheckoutActivity.kt index 19cc599..2afa448 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/ui/order/CheckoutActivity.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/ui/order/CheckoutActivity.kt @@ -11,7 +11,7 @@ import androidx.recyclerview.widget.LinearLayoutManager import com.alya.ecommerce_serang.data.api.dto.CheckoutData import com.alya.ecommerce_serang.data.api.dto.OrderRequest import com.alya.ecommerce_serang.data.api.dto.OrderRequestBuy -import com.alya.ecommerce_serang.data.api.response.product.PaymentInfoItem +import com.alya.ecommerce_serang.data.api.response.customer.product.PaymentInfoItem import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig import com.alya.ecommerce_serang.data.repository.OrderRepository import com.alya.ecommerce_serang.databinding.ActivityCheckoutBinding diff --git a/app/src/main/java/com/alya/ecommerce_serang/ui/order/CheckoutViewModel.kt b/app/src/main/java/com/alya/ecommerce_serang/ui/order/CheckoutViewModel.kt index e470bcf..8a27c2d 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/ui/order/CheckoutViewModel.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/ui/order/CheckoutViewModel.kt @@ -8,10 +8,10 @@ import androidx.lifecycle.viewModelScope import com.alya.ecommerce_serang.data.api.dto.CheckoutData import com.alya.ecommerce_serang.data.api.dto.OrderRequest import com.alya.ecommerce_serang.data.api.dto.OrderRequestBuy -import com.alya.ecommerce_serang.data.api.response.cart.CartItemsItem -import com.alya.ecommerce_serang.data.api.response.cart.DataItem -import com.alya.ecommerce_serang.data.api.response.product.PaymentInfoItem -import com.alya.ecommerce_serang.data.api.response.profile.AddressesItem +import com.alya.ecommerce_serang.data.api.response.customer.cart.CartItemsItem +import com.alya.ecommerce_serang.data.api.response.customer.cart.DataItem +import com.alya.ecommerce_serang.data.api.response.customer.product.PaymentInfoItem +import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressesItem import com.alya.ecommerce_serang.data.repository.OrderRepository import com.alya.ecommerce_serang.data.repository.Result import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/alya/ecommerce_serang/ui/order/PaymentMethodAdapter.kt b/app/src/main/java/com/alya/ecommerce_serang/ui/order/PaymentMethodAdapter.kt index 8621f0e..5222e26 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/ui/order/PaymentMethodAdapter.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/ui/order/PaymentMethodAdapter.kt @@ -4,7 +4,7 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.alya.ecommerce_serang.R -import com.alya.ecommerce_serang.data.api.response.product.PaymentInfoItem +import com.alya.ecommerce_serang.data.api.response.customer.product.PaymentInfoItem import com.alya.ecommerce_serang.databinding.ItemPaymentMethodBinding import com.bumptech.glide.Glide import com.bumptech.glide.request.RequestOptions diff --git a/app/src/main/java/com/alya/ecommerce_serang/ui/order/ShippingAdapter.kt b/app/src/main/java/com/alya/ecommerce_serang/ui/order/ShippingAdapter.kt index cfbf401..bea432b 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/ui/order/ShippingAdapter.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/ui/order/ShippingAdapter.kt @@ -3,8 +3,8 @@ package com.alya.ecommerce_serang.ui.order import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView -import com.alya.ecommerce_serang.data.api.response.order.CourierCostsItem -import com.alya.ecommerce_serang.data.api.response.order.ServicesItem +import com.alya.ecommerce_serang.data.api.response.customer.order.CourierCostsItem +import com.alya.ecommerce_serang.data.api.response.customer.order.ServicesItem import com.alya.ecommerce_serang.databinding.ItemShippingOrderBinding class ShippingAdapter( diff --git a/app/src/main/java/com/alya/ecommerce_serang/ui/order/ShippingViewModel.kt b/app/src/main/java/com/alya/ecommerce_serang/ui/order/ShippingViewModel.kt index 17696c7..572c087 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/ui/order/ShippingViewModel.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/ui/order/ShippingViewModel.kt @@ -6,7 +6,7 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.alya.ecommerce_serang.data.api.dto.CostProduct import com.alya.ecommerce_serang.data.api.dto.CourierCostRequest -import com.alya.ecommerce_serang.data.api.response.order.CourierCostsItem +import com.alya.ecommerce_serang.data.api.response.customer.order.CourierCostsItem import com.alya.ecommerce_serang.data.repository.OrderRepository import com.alya.ecommerce_serang.data.repository.Result import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/alya/ecommerce_serang/ui/order/SingleItemCartAdapter.kt b/app/src/main/java/com/alya/ecommerce_serang/ui/order/SingleItemCartAdapter.kt index 7f4d17e..e5872a3 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/ui/order/SingleItemCartAdapter.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/ui/order/SingleItemCartAdapter.kt @@ -4,7 +4,7 @@ import android.view.LayoutInflater import android.view.ViewGroup import androidx.recyclerview.widget.RecyclerView import com.alya.ecommerce_serang.R -import com.alya.ecommerce_serang.data.api.response.cart.CartItemsItem +import com.alya.ecommerce_serang.data.api.response.customer.cart.CartItemsItem import com.alya.ecommerce_serang.databinding.ItemOrderProductBinding import com.bumptech.glide.Glide import java.text.NumberFormat diff --git a/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/AddAddressActivity.kt b/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/AddAddressActivity.kt index c4b3587..3c8f2dc 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/AddAddressActivity.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/AddAddressActivity.kt @@ -15,8 +15,8 @@ import androidx.lifecycle.lifecycleScope import androidx.lifecycle.repeatOnLifecycle import com.alya.ecommerce_serang.data.api.dto.CreateAddressRequest import com.alya.ecommerce_serang.data.api.dto.UserProfile -import com.alya.ecommerce_serang.data.api.response.order.CitiesItem -import com.alya.ecommerce_serang.data.api.response.order.ProvincesItem +import com.alya.ecommerce_serang.data.api.response.customer.order.CitiesItem +import com.alya.ecommerce_serang.data.api.response.customer.order.ProvincesItem import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig import com.alya.ecommerce_serang.data.api.retrofit.ApiService import com.alya.ecommerce_serang.data.repository.OrderRepository diff --git a/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/AddAddressViewModel.kt b/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/AddAddressViewModel.kt index fd462d2..a9839d8 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/AddAddressViewModel.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/AddAddressViewModel.kt @@ -5,8 +5,8 @@ import androidx.lifecycle.SavedStateHandle import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.alya.ecommerce_serang.data.api.dto.CreateAddressRequest -import com.alya.ecommerce_serang.data.api.response.order.CitiesItem -import com.alya.ecommerce_serang.data.api.response.order.ProvincesItem +import com.alya.ecommerce_serang.data.api.response.customer.order.CitiesItem +import com.alya.ecommerce_serang.data.api.response.customer.order.ProvincesItem import com.alya.ecommerce_serang.data.repository.OrderRepository import com.alya.ecommerce_serang.data.repository.Result import kotlinx.coroutines.flow.MutableStateFlow diff --git a/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/AddressAdapter.kt b/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/AddressAdapter.kt index 297a3e7..e319cc0 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/AddressAdapter.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/AddressAdapter.kt @@ -9,7 +9,7 @@ import androidx.recyclerview.widget.DiffUtil import androidx.recyclerview.widget.ListAdapter import androidx.recyclerview.widget.RecyclerView import com.alya.ecommerce_serang.R -import com.alya.ecommerce_serang.data.api.response.profile.AddressesItem +import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressesItem import com.google.android.material.card.MaterialCardView class AddressAdapter( diff --git a/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/AddressViewModel.kt b/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/AddressViewModel.kt index 0898e2f..7aec2cc 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/AddressViewModel.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/AddressViewModel.kt @@ -4,7 +4,7 @@ import androidx.lifecycle.LiveData import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope -import com.alya.ecommerce_serang.data.api.response.profile.AddressesItem +import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressesItem import com.alya.ecommerce_serang.data.repository.OrderRepository import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/ProvinceAdapter.kt b/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/ProvinceAdapter.kt index 44f7c29..7ba4660 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/ProvinceAdapter.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/ui/order/address/ProvinceAdapter.kt @@ -2,8 +2,8 @@ package com.alya.ecommerce_serang.ui.order.address import android.content.Context import android.widget.ArrayAdapter -import com.alya.ecommerce_serang.data.api.response.order.CitiesItem -import com.alya.ecommerce_serang.data.api.response.order.ProvincesItem +import com.alya.ecommerce_serang.data.api.response.customer.order.CitiesItem +import com.alya.ecommerce_serang.data.api.response.customer.order.ProvincesItem // UI adapters and helpers class ProvinceAdapter( diff --git a/app/src/main/java/com/alya/ecommerce_serang/ui/product/DetailProductActivity.kt b/app/src/main/java/com/alya/ecommerce_serang/ui/product/DetailProductActivity.kt index bb10bdb..257e479 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/ui/product/DetailProductActivity.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/ui/product/DetailProductActivity.kt @@ -16,9 +16,9 @@ import com.alya.ecommerce_serang.BuildConfig.BASE_URL import com.alya.ecommerce_serang.R import com.alya.ecommerce_serang.data.api.dto.CartItem import com.alya.ecommerce_serang.data.api.dto.ProductsItem -import com.alya.ecommerce_serang.data.api.response.product.Product -import com.alya.ecommerce_serang.data.api.response.product.ReviewsItem -import com.alya.ecommerce_serang.data.api.response.product.StoreProduct +import com.alya.ecommerce_serang.data.api.response.customer.product.Product +import com.alya.ecommerce_serang.data.api.response.customer.product.ReviewsItem +import com.alya.ecommerce_serang.data.api.response.customer.product.StoreProduct import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig import com.alya.ecommerce_serang.data.api.retrofit.ApiService import com.alya.ecommerce_serang.data.repository.ProductRepository diff --git a/app/src/main/java/com/alya/ecommerce_serang/ui/product/ProductUserViewModel.kt b/app/src/main/java/com/alya/ecommerce_serang/ui/product/ProductUserViewModel.kt index 9679488..5d5c27e 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/ui/product/ProductUserViewModel.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/ui/product/ProductUserViewModel.kt @@ -7,10 +7,10 @@ import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.alya.ecommerce_serang.data.api.dto.CartItem import com.alya.ecommerce_serang.data.api.dto.ProductsItem -import com.alya.ecommerce_serang.data.api.response.cart.AddCartResponse -import com.alya.ecommerce_serang.data.api.response.product.Product -import com.alya.ecommerce_serang.data.api.response.product.ReviewsItem -import com.alya.ecommerce_serang.data.api.response.product.StoreProduct +import com.alya.ecommerce_serang.data.api.response.customer.cart.AddCartResponse +import com.alya.ecommerce_serang.data.api.response.customer.product.Product +import com.alya.ecommerce_serang.data.api.response.customer.product.ReviewsItem +import com.alya.ecommerce_serang.data.api.response.customer.product.StoreProduct import com.alya.ecommerce_serang.data.repository.ProductRepository import com.alya.ecommerce_serang.data.repository.Result import kotlinx.coroutines.launch diff --git a/app/src/main/java/com/alya/ecommerce_serang/ui/product/ReviewsAdapter.kt b/app/src/main/java/com/alya/ecommerce_serang/ui/product/ReviewsAdapter.kt index 7e4554e..8b22a8f 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/ui/product/ReviewsAdapter.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/ui/product/ReviewsAdapter.kt @@ -6,7 +6,7 @@ import android.view.ViewGroup import android.widget.TextView import androidx.recyclerview.widget.RecyclerView import com.alya.ecommerce_serang.R -import com.alya.ecommerce_serang.data.api.response.product.ReviewsItem +import com.alya.ecommerce_serang.data.api.response.customer.product.ReviewsItem import java.text.SimpleDateFormat import java.util.Locale import java.util.TimeZone diff --git a/app/src/main/java/com/alya/ecommerce_serang/ui/profile/mystore/product/ProductActivity.kt b/app/src/main/java/com/alya/ecommerce_serang/ui/profile/mystore/product/ProductActivity.kt index 4239a9d..0eee6be 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/ui/profile/mystore/product/ProductActivity.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/ui/profile/mystore/product/ProductActivity.kt @@ -36,7 +36,6 @@ class ProductActivity : AppCompatActivity() { setupHeader() setupRecyclerView() - observeViewModel() binding.progressBar.visibility = View.VISIBLE @@ -59,7 +58,7 @@ class ProductActivity : AppCompatActivity() { } is Result.Error -> { binding.progressBar.visibility = View.GONE - Toast.makeText(this, "Failed to load products: ${result.exception.message}", Toast.LENGTH_SHORT).show() + Toast.makeText(this, "Gagal memuat produk: ${result.exception.message}", Toast.LENGTH_SHORT).show() } } } @@ -74,7 +73,9 @@ class ProductActivity : AppCompatActivity() { } binding.header.headerRightText.setOnClickListener { - startActivity(Intent(this, StoreProductDetailActivity::class.java)) + val intent = Intent(this, StoreProductDetailActivity::class.java) + intent.putExtra("is_editing", false) + startActivity(intent) } } diff --git a/app/src/main/java/com/alya/ecommerce_serang/ui/profile/mystore/product/ProductOptionsBottomSheetFragment.kt b/app/src/main/java/com/alya/ecommerce_serang/ui/profile/mystore/product/ProductOptionsBottomSheetFragment.kt index f2d348a..7e1cf10 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/ui/profile/mystore/product/ProductOptionsBottomSheetFragment.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/ui/profile/mystore/product/ProductOptionsBottomSheetFragment.kt @@ -1,13 +1,18 @@ package com.alya.ecommerce_serang.ui.profile.mystore.product +import android.app.AlertDialog +import android.content.Intent import android.os.Bundle import androidx.fragment.app.Fragment import android.view.LayoutInflater import android.view.View import android.view.ViewGroup +import android.widget.Toast +import androidx.lifecycle.ViewModelProvider import com.alya.ecommerce_serang.R import com.alya.ecommerce_serang.data.api.dto.ProductsItem import com.alya.ecommerce_serang.databinding.FragmentProductOptionsBottomSheetBinding +import com.alya.ecommerce_serang.utils.viewmodel.ProductViewModel import com.google.android.material.bottomsheet.BottomSheetDialogFragment class ProductOptionsBottomSheetFragment(private val product: ProductsItem) : BottomSheetDialogFragment() { @@ -27,15 +32,25 @@ class ProductOptionsBottomSheetFragment(private val product: ProductsItem) : Bot super.onViewCreated(view, savedInstanceState) binding.btnEditProduct.setOnClickListener { - // Handle editing product - // Example: Open the edit activity or fragment + val intent = Intent(requireContext(), StoreProductDetailActivity::class.java) + intent.putExtra("product_id", product.id) + intent.putExtra("is_editing", true) + startActivity(intent) dismiss() } binding.btnDeleteProduct.setOnClickListener { - // Handle deleting product - // Example: Show confirmation dialog - dismiss() + AlertDialog.Builder(requireContext()) + .setTitle("Hapus Produk?") + .setMessage("Produk yang dihapus tidak dapat dikembalikan.") + .setPositiveButton("Ya, Hapus") { _, _ -> + val viewModel = ViewModelProvider(this).get(ProductViewModel::class.java) + viewModel.deleteProduct(product.id) + Toast.makeText(context, "Produk berhasil dihapus", Toast.LENGTH_SHORT).show() + dismiss() + } + .setNegativeButton("Batalkan", null) + .show() } } diff --git a/app/src/main/java/com/alya/ecommerce_serang/ui/profile/mystore/product/StoreProductDetailActivity.kt b/app/src/main/java/com/alya/ecommerce_serang/ui/profile/mystore/product/StoreProductDetailActivity.kt index a22d850..41bef9a 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/ui/profile/mystore/product/StoreProductDetailActivity.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/ui/profile/mystore/product/StoreProductDetailActivity.kt @@ -15,6 +15,8 @@ import androidx.activity.viewModels import androidx.appcompat.app.AppCompatActivity import androidx.core.content.ContextCompat import com.alya.ecommerce_serang.data.api.dto.CategoryItem +import com.alya.ecommerce_serang.data.api.dto.Preorder +import com.alya.ecommerce_serang.data.api.dto.Product import com.alya.ecommerce_serang.data.api.retrofit.ApiConfig import com.alya.ecommerce_serang.data.repository.ProductRepository import com.alya.ecommerce_serang.data.repository.Result @@ -22,12 +24,14 @@ import com.alya.ecommerce_serang.databinding.ActivityStoreProductDetailBinding import com.alya.ecommerce_serang.utils.viewmodel.ProductViewModel import com.alya.ecommerce_serang.utils.BaseViewModelFactory import com.alya.ecommerce_serang.utils.SessionManager +import com.bumptech.glide.Glide import okhttp3.MediaType.Companion.toMediaTypeOrNull import okhttp3.MultipartBody import okhttp3.RequestBody import java.io.File import java.io.FileOutputStream import kotlin.getValue +import androidx.core.net.toUri class StoreProductDetailActivity : AppCompatActivity() { @@ -37,6 +41,7 @@ class StoreProductDetailActivity : AppCompatActivity() { private var imageUri: Uri? = null private var sppirtUri: Uri? = null private var halalUri: Uri? = null + private var productId: Int? = null private val viewModel: ProductViewModel by viewModels { BaseViewModelFactory { @@ -79,9 +84,50 @@ class StoreProductDetailActivity : AppCompatActivity() { binding = ActivityStoreProductDetailBinding.inflate(layoutInflater) setContentView(binding.root) - setupHeader() + val isEditing = intent.getBooleanExtra("is_editing", false) + productId = intent.getIntExtra("product_id", -1) - // Fetch categories + binding.header.headerTitle.text = if (isEditing) "Ubah Produk" else "Tambah Produk" + +// if (isEditing && productId != null) { +// viewModel.productDetail.observe(this) { product -> +// product?.let { +// populateForm(it) +// } +// } +// viewModel.loadProductDetail(productId!!) +// } + + setupCategorySpinner() + setupImagePickers() + + var conditionList = listOf("Baru", "Pernah Dipakai") + val adapterCondition = ArrayAdapter(this, android.R.layout.simple_spinner_item, conditionList) + adapterCondition.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item) + binding.spinnerKondisiProduk.adapter = adapterCondition + + // Setup Pre-Order visibility + binding.switchIsPreOrder.setOnCheckedChangeListener { _, isChecked -> + binding.layoutDurasi.visibility = if (isChecked) View.VISIBLE else View.GONE + validateForm() + } + + validateForm() + + binding.btnSaveProduct.setOnClickListener { + if (isEditing) { + updateProduct(productId) + } else { + addProduct() + } + } + + binding.header.headerLeftIcon.setOnClickListener { + onBackPressedDispatcher.onBackPressed() + } + } + + private fun setupCategorySpinner() { viewModel.loadCategories() viewModel.categoryList.observe(this) { result -> if (result is Result.Success) { @@ -91,13 +137,9 @@ class StoreProductDetailActivity : AppCompatActivity() { binding.spinnerKategoriProduk.adapter = adapter } } + } - // Setup Pre-Order visibility - binding.switchIsPreOrder.setOnCheckedChangeListener { _, isChecked -> - binding.layoutDurasi.visibility = if (isChecked) View.VISIBLE else View.GONE - validateForm() - } - + private fun setupImagePickers() { binding.tvTambahFoto.setOnClickListener { val intent = Intent(Intent.ACTION_PICK).apply { type = "image/*" } imagePickerLauncher.launch(intent) @@ -125,15 +167,37 @@ class StoreProductDetailActivity : AppCompatActivity() { halalUri = null binding.switcherHalal.showPrevious() } + } + + private fun populateForm(product: Product) { + binding.edtNamaProduk.setText(product.name) + binding.edtDeskripsiProduk.setText(product.description) + binding.edtHargaProduk.setText(product.price.toString()) + binding.edtStokProduk.setText(product.stock.toString()) + binding.edtMinOrder.setText(product.minOrder.toString()) + binding.edtBeratProduk.setText(product.weight.toString()) + binding.switchIsPreOrder.isChecked = product.isPreOrder ?: false + binding.switchIsActive.isChecked = product.status == "active" + binding.spinnerKondisiProduk.setSelection(if (product.condition == "Baru") 0 else 1) + + product.categoryId?.let { + binding.spinnerKategoriProduk.setSelection(categoryList.indexOfFirst { it.id == product.categoryId }) + } + + Glide.with(this).load(product.image).into(binding.ivPreviewFoto) + binding.switcherFotoProduk.showNext() + + product.sppirt?.let { + binding.tvSppirtName.text = getFileName(it.toUri()) + binding.switcherSppirt.showNext() + } + + product.halal?.let { + binding.tvHalalName.text = getFileName(it.toUri()) + binding.switcherHalal.showNext() + } validateForm() - - binding.btnSaveProduct.setOnClickListener { - if (!binding.btnSaveProduct.isEnabled) { - return@setOnClickListener - } - submitProduct() - } } private fun isValidFile(uri: Uri): Boolean { @@ -145,6 +209,36 @@ class StoreProductDetailActivity : AppCompatActivity() { return uri.lastPathSegment?.split("/")?.last() ?: "unknown_file" } + private fun uriToNamedFile(uri: Uri, context: Context, prefix: String): File { + val extension = context.contentResolver.getType(uri)?.substringAfter("/") ?: "jpg" + val filename = "$prefix-${System.currentTimeMillis()}.$extension" + val file = File(context.cacheDir, filename) + + context.contentResolver.openInputStream(uri)?.use { input -> + FileOutputStream(file).use { output -> input.copyTo(output) } + } + + return file + } + + fun getMimeType(file: File): String { + val extension = file.extension + return when (extension.lowercase()) { + "jpg", "jpeg" -> "image/jpeg" + "png" -> "image/png" + "pdf" -> "application/pdf" + else -> "application/octet-stream" + } + } + + fun createPartFromFile(field: String, file: File?): MultipartBody.Part? { + return file?.let { + val mimeType = getMimeType(it).toMediaTypeOrNull() + val requestBody = RequestBody.create(mimeType, it) + MultipartBody.Part.createFormData(field, it.name, requestBody) + } + } + private fun validateForm() { val valid = binding.edtNamaProduk.text.isNotBlank() && binding.edtDeskripsiProduk.text.isNotBlank() && @@ -164,19 +258,7 @@ class StoreProductDetailActivity : AppCompatActivity() { ) } - private fun uriToNamedFile(uri: Uri, context: Context, prefix: String): File { - val extension = context.contentResolver.getType(uri)?.substringAfter("/") ?: "jpg" - val filename = "$prefix-${System.currentTimeMillis()}.$extension" - val file = File(context.cacheDir, filename) - - context.contentResolver.openInputStream(uri)?.use { input -> - FileOutputStream(file).use { output -> input.copyTo(output) } - } - - return file - } - - private fun submitProduct() { + private fun addProduct() { val name = binding.edtNamaProduk.text.toString() val description = binding.edtDeskripsiProduk.text.toString() val price = binding.edtHargaProduk.text.toString().toInt() @@ -186,6 +268,7 @@ class StoreProductDetailActivity : AppCompatActivity() { val isPreOrder = binding.switchIsPreOrder.isChecked val duration = if (isPreOrder) binding.edtDurasi.text.toString().toInt() else 0 val status = if (binding.switchIsActive.isChecked) "active" else "inactive" + val condition = binding.spinnerKondisiProduk.selectedItem.toString() val categoryId = categoryList.getOrNull(binding.spinnerKategoriProduk.selectedItemPosition)?.id ?: 0 val imageFile = imageUri?.let { uriToNamedFile(it, this, "productimg") } @@ -199,8 +282,10 @@ class StoreProductDetailActivity : AppCompatActivity() { val sppirtPart = sppirtFile?.let { createPartFromFile("sppirt", it) } val halalPart = halalFile?.let { createPartFromFile("halal", it) } + val preorder = Preorder(productId = productId, duration = duration) + viewModel.addProduct( - name, description, price, stock, minOrder, weight, isPreOrder, duration, categoryId, status, imagePart, sppirtPart, halalPart + name, description, price, stock, minOrder, weight, isPreOrder, preorder, categoryId, status, condition, imagePart, sppirtPart, halalPart ) viewModel.productCreationResult.observe(this) { result -> @@ -208,7 +293,7 @@ class StoreProductDetailActivity : AppCompatActivity() { is Result.Loading -> binding.btnSaveProduct.isEnabled = false is Result.Success -> { val product = result.data.product - Toast.makeText(this, "Product Created: ${product?.productName}", Toast.LENGTH_SHORT).show() + Toast.makeText(this, "Product Created: ${product?.name}", Toast.LENGTH_SHORT).show() finish() } is Result.Error -> { @@ -219,26 +304,24 @@ class StoreProductDetailActivity : AppCompatActivity() { } } - fun getMimeType(file: File): String { - val extension = file.extension - return when (extension.lowercase()) { - "jpg", "jpeg" -> "image/jpeg" - "png" -> "image/png" - "pdf" -> "application/pdf" - else -> "application/octet-stream" - } - } + private fun updateProduct(productId: Int?) { + val updatedProduct = mapOf( + "name" to binding.edtNamaProduk.text.toString(), + "description" to binding.edtDeskripsiProduk.text.toString(), + "price" to binding.edtHargaProduk.text.toString(), + "stock" to binding.edtStokProduk.text.toString().toInt(), + "min_order" to binding.edtMinOrder.text.toString().toInt(), + "weight" to binding.edtBeratProduk.text.toString().toInt(), + "is_pre_order" to binding.switchIsPreOrder.isChecked, + "duration" to binding.edtDurasi.text.toString().toInt(), + "category_id" to categoryList[binding.spinnerKategoriProduk.selectedItemPosition].id, + "status" to if (binding.switchIsActive.isChecked) "active" else "inactive", + "condition" to binding.spinnerKondisiProduk.selectedItem.toString(), + "productimg" to imageUri?.path, + "sppirt" to sppirtUri?.path, + "halal" to halalUri?.path + ) - fun createPartFromFile(field: String, file: File?): MultipartBody.Part? { - return file?.let { - val mimeType = getMimeType(it).toMediaTypeOrNull() - val requestBody = RequestBody.create(mimeType, it) - MultipartBody.Part.createFormData(field, it.name, requestBody) - } - } - - private fun setupHeader() { - binding.header.headerTitle.text = "Tambah Produk" - binding.header.headerLeftIcon.setOnClickListener { onBackPressedDispatcher.onBackPressed() } + viewModel.updateProduct(productId, updatedProduct) } } \ No newline at end of file diff --git a/app/src/main/java/com/alya/ecommerce_serang/utils/viewmodel/ProductViewModel.kt b/app/src/main/java/com/alya/ecommerce_serang/utils/viewmodel/ProductViewModel.kt index f8f6d9c..703db21 100644 --- a/app/src/main/java/com/alya/ecommerce_serang/utils/viewmodel/ProductViewModel.kt +++ b/app/src/main/java/com/alya/ecommerce_serang/utils/viewmodel/ProductViewModel.kt @@ -5,11 +5,13 @@ import androidx.lifecycle.MutableLiveData import androidx.lifecycle.ViewModel import androidx.lifecycle.viewModelScope import com.alya.ecommerce_serang.data.api.dto.CategoryItem +import com.alya.ecommerce_serang.data.api.dto.Preorder import com.alya.ecommerce_serang.data.api.dto.ProductsItem -import com.alya.ecommerce_serang.data.api.response.product.CreateProductResponse -import com.alya.ecommerce_serang.data.api.response.product.Product -import com.alya.ecommerce_serang.data.api.response.product.ReviewsItem -import com.alya.ecommerce_serang.data.api.response.product.StoreProduct +import com.alya.ecommerce_serang.data.api.response.store.product.CreateProductResponse +import com.alya.ecommerce_serang.data.api.response.customer.product.Product +import com.alya.ecommerce_serang.data.api.response.customer.product.ReviewsItem +import com.alya.ecommerce_serang.data.api.response.customer.product.StoreProduct +import com.alya.ecommerce_serang.data.api.response.store.product.UpdateProductResponse import com.alya.ecommerce_serang.data.repository.ProductRepository import com.alya.ecommerce_serang.data.repository.Result import kotlinx.coroutines.launch @@ -20,6 +22,9 @@ class ProductViewModel(private val repository: ProductRepository) : ViewModel() private val _productCreationResult = MutableLiveData>() val productCreationResult: LiveData> get() = _productCreationResult + private val _productUpdateResult = MutableLiveData>() + val productUpdateResult: LiveData> get() = _productUpdateResult + private val _productDetail = MutableLiveData() val productDetail: LiveData get() = _productDetail @@ -49,6 +54,12 @@ class ProductViewModel(private val repository: ProductRepository) : ViewModel() } } + fun loadPreorderProducts(productId: Int) { + viewModelScope.launch { + + } + } + fun loadMyStoreProducts() { viewModelScope.launch { _productList.value = Result.Loading @@ -76,9 +87,10 @@ class ProductViewModel(private val repository: ProductRepository) : ViewModel() minOrder: Int, weight: Int, isPreOrder: Boolean, - duration: Int, + preorder: Preorder, categoryId: Int, status: String, + condition: String, imagePart: MultipartBody.Part?, sppirtPart: MultipartBody.Part?, halalPart: MultipartBody.Part? @@ -86,12 +98,31 @@ class ProductViewModel(private val repository: ProductRepository) : ViewModel() _productCreationResult.value = Result.Loading viewModelScope.launch { val result = repository.addProduct( - name, description, price, stock, minOrder, weight, isPreOrder, duration, categoryId, status, imagePart, sppirtPart, halalPart + name, description, price, stock, minOrder, weight, isPreOrder, preorder, categoryId, status, condition, imagePart, sppirtPart, halalPart ) _productCreationResult.value = result } } + fun updateProduct(productId: Int?, updatedProduct: Map) { + _productUpdateResult.value = Result.Loading + viewModelScope.launch { + try { + val response = repository.updateProduct(productId, updatedProduct) + _productUpdateResult.value = Result.Success(response) + } catch (e: Exception) { + _productUpdateResult.value = Result.Error(e) + } + } + } + + fun deleteProduct(productId: Int) { + viewModelScope.launch { + val result = repository.deleteProduct(productId) + // handle the response (loading, success, or error) + } + } + // Optional: for store detail if you need it later // fun loadStoreDetail(storeId: Int) { // viewModelScope.launch { diff --git a/app/src/main/res/layout/activity_cart.xml b/app/src/main/res/layout/activity_cart.xml index 3735ec2..246f39a 100644 --- a/app/src/main/res/layout/activity_cart.xml +++ b/app/src/main/res/layout/activity_cart.xml @@ -5,6 +5,6 @@ android:id="@+id/main" android:layout_width="match_parent" android:layout_height="match_parent" - tools:context=".data.api.response.cart.CartActivity"> + tools:context=".data.api.response.customer.cart.CartActivity"> \ No newline at end of file diff --git a/app/src/main/res/layout/activity_store_product_detail.xml b/app/src/main/res/layout/activity_store_product_detail.xml index 4a1a522..7076979 100644 --- a/app/src/main/res/layout/activity_store_product_detail.xml +++ b/app/src/main/res/layout/activity_store_product_detail.xml @@ -481,66 +481,66 @@ - - - - - - + + - - - - - + + - - - - - - + - - - - - - - - + - + - - - - - - - - + + - - - - - - - - + - - - - - - - + + - + - +