mirror of
https://github.com/shaulascr/ecommerce_serang.git
synced 2025-08-16 11:47:25 +00:00
fix address store, address user, add
This commit is contained in:
@ -394,18 +394,8 @@ interface ApiService {
|
|||||||
@PUT("mystore/edit")
|
@PUT("mystore/edit")
|
||||||
suspend fun updateStoreProfileMultipart(
|
suspend fun updateStoreProfileMultipart(
|
||||||
@Part("store_name") storeName: RequestBody,
|
@Part("store_name") storeName: RequestBody,
|
||||||
@Part("store_status") storeStatus: RequestBody,
|
|
||||||
@Part("store_description") storeDescription: RequestBody,
|
@Part("store_description") storeDescription: RequestBody,
|
||||||
@Part("is_on_leave") isOnLeave: RequestBody,
|
@Part("is_on_leave") isOnLeave: RequestBody,
|
||||||
@Part("city_id") cityId: RequestBody,
|
|
||||||
@Part("province_id") provinceId: RequestBody,
|
|
||||||
@Part("street") street: RequestBody,
|
|
||||||
@Part("subdistrict") subdistrict: RequestBody,
|
|
||||||
@Part("detail") detail: RequestBody,
|
|
||||||
@Part("postal_code") postalCode: RequestBody,
|
|
||||||
@Part("latitude") latitude: RequestBody,
|
|
||||||
@Part("longitude") longitude: RequestBody,
|
|
||||||
@Part("user_phone") userPhone: RequestBody,
|
|
||||||
@Part("store_type_id") storeTypeId: RequestBody,
|
@Part("store_type_id") storeTypeId: RequestBody,
|
||||||
@Part storeimg: MultipartBody.Part?
|
@Part storeimg: MultipartBody.Part?
|
||||||
): Response<StoreDataResponse>
|
): Response<StoreDataResponse>
|
||||||
@ -457,10 +447,10 @@ interface ApiService {
|
|||||||
@Body addressData: HashMap<String, Any?>
|
@Body addressData: HashMap<String, Any?>
|
||||||
): Response<StoreAddressResponse>
|
): Response<StoreAddressResponse>
|
||||||
|
|
||||||
@PUT("profile/address/edit/{idAddress}")
|
@PUT("profile/address/edit/{id}")
|
||||||
suspend fun updateAddress(
|
suspend fun updateAddress(
|
||||||
@Path("id") addressId: Int,
|
@Path("id") addressId: Int,
|
||||||
@Body params: Map<String, Any>
|
@Body params: Map<String, @JvmSuppressWildcards Any>
|
||||||
): Response<UpdateAddressResponse>
|
): Response<UpdateAddressResponse>
|
||||||
|
|
||||||
@POST("search")
|
@POST("search")
|
||||||
|
@ -3,6 +3,7 @@ package com.alya.ecommerce_serang.data.repository
|
|||||||
import android.util.Log
|
import android.util.Log
|
||||||
import com.alya.ecommerce_serang.data.api.dto.CityResponse
|
import com.alya.ecommerce_serang.data.api.dto.CityResponse
|
||||||
import com.alya.ecommerce_serang.data.api.dto.ProvinceResponse
|
import com.alya.ecommerce_serang.data.api.dto.ProvinceResponse
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.order.SubdistrictResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressResponse
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.profile.UpdateAddressResponse
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.UpdateAddressResponse
|
||||||
import com.alya.ecommerce_serang.data.api.retrofit.ApiService
|
import com.alya.ecommerce_serang.data.api.retrofit.ApiService
|
||||||
@ -187,4 +188,9 @@ class AddressRepository(private val apiService: ApiService) {
|
|||||||
suspend fun updateAddress(addressId: Int, params: Map<String, Any>): Response<UpdateAddressResponse> {
|
suspend fun updateAddress(addressId: Int, params: Map<String, Any>): Response<UpdateAddressResponse> {
|
||||||
return apiService.updateAddress(addressId, params)
|
return apiService.updateAddress(addressId, params)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
suspend fun getListSubdistrict(cityId : String): SubdistrictResponse? {
|
||||||
|
val response = apiService.getSubdistrict(cityId)
|
||||||
|
return if (response.isSuccessful) response.body() else null
|
||||||
|
}
|
||||||
}
|
}
|
@ -53,48 +53,49 @@ class MyStoreRepository(private val apiService: ApiService) {
|
|||||||
|
|
||||||
suspend fun updateStoreProfile(
|
suspend fun updateStoreProfile(
|
||||||
storeName: RequestBody,
|
storeName: RequestBody,
|
||||||
storeStatus: RequestBody,
|
|
||||||
storeDescription: RequestBody,
|
storeDescription: RequestBody,
|
||||||
isOnLeave: RequestBody,
|
isOnLeave: RequestBody,
|
||||||
cityId: RequestBody,
|
|
||||||
provinceId: RequestBody,
|
|
||||||
street: RequestBody,
|
|
||||||
subdistrict: RequestBody,
|
|
||||||
detail: RequestBody,
|
|
||||||
postalCode: RequestBody,
|
|
||||||
latitude: RequestBody,
|
|
||||||
longitude: RequestBody,
|
|
||||||
userPhone: RequestBody,
|
|
||||||
storeType: RequestBody,
|
storeType: RequestBody,
|
||||||
storeimg: MultipartBody.Part?
|
storeimg: MultipartBody.Part?
|
||||||
): Response<StoreDataResponse> {
|
): Response<StoreDataResponse>? {
|
||||||
return apiService.updateStoreProfileMultipart(
|
|
||||||
storeName, storeStatus, storeDescription, isOnLeave, cityId, provinceId,
|
return try {
|
||||||
street, subdistrict, detail, postalCode, latitude, longitude, userPhone, storeType, storeimg
|
Log.d(TAG, "storeName: $storeName")
|
||||||
)
|
Log.d(TAG, "storeDescription: $storeDescription")
|
||||||
|
Log.d(TAG, "isOnLeave: $isOnLeave")
|
||||||
|
Log.d(TAG, "storeType: $storeType")
|
||||||
|
Log.d(TAG, "storeimg: ${storeimg?.headers}")
|
||||||
|
|
||||||
|
apiService.updateStoreProfileMultipart(
|
||||||
|
storeName, storeDescription, isOnLeave, storeType, storeimg
|
||||||
|
)
|
||||||
|
} catch (e: Exception) {
|
||||||
|
Log.e(TAG, "Error updating store profile", e)
|
||||||
|
null
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun getSellList(status: String): Result<OrderListResponse> {
|
suspend fun getSellList(status: String): Result<OrderListResponse> {
|
||||||
return try {
|
return try {
|
||||||
Log.d("SellsRepository", "Add Evidence : $status")
|
Log.d(TAG, "Add Evidence : $status")
|
||||||
val response = apiService.getSellList(status)
|
val response = apiService.getSellList(status)
|
||||||
|
|
||||||
if (response.isSuccessful) {
|
if (response.isSuccessful) {
|
||||||
val allListSell = response.body()
|
val allListSell = response.body()
|
||||||
if (allListSell != null) {
|
if (allListSell != null) {
|
||||||
Log.d("SellsRepository", "Add Evidence successfully: ${allListSell.message}")
|
Log.d(TAG, "Add Evidence successfully: ${allListSell.message}")
|
||||||
Result.Success(allListSell)
|
Result.Success(allListSell)
|
||||||
} else {
|
} else {
|
||||||
Log.e("SellsRepository", "Response body was null")
|
Log.e(TAG, "Response body was null")
|
||||||
Result.Error(Exception("Empty response from server"))
|
Result.Error(Exception("Empty response from server"))
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
val errorBody = response.errorBody()?.string() ?: "Unknown error"
|
val errorBody = response.errorBody()?.string() ?: "Unknown error"
|
||||||
Log.e("SellsRepository", "Error Add Evidence : $errorBody")
|
Log.e(TAG, "Error Add Evidence : $errorBody")
|
||||||
Result.Error(Exception(errorBody))
|
Result.Error(Exception(errorBody))
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("SellsRepository", "Exception Add Evidence ", e)
|
Log.e(TAG, "Exception Add Evidence ", e)
|
||||||
Result.Error(e)
|
Result.Error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -119,7 +120,7 @@ class MyStoreRepository(private val apiService: ApiService) {
|
|||||||
)
|
)
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("MyStoreRepository", "Error fetching balance", e)
|
Log.e(TAG, "Error fetching balance", e)
|
||||||
Result.Error(e)
|
Result.Error(e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -133,11 +134,15 @@ class MyStoreRepository(private val apiService: ApiService) {
|
|||||||
throw Exception("Failed to fetch store products: ${response.message()}")
|
throw Exception("Failed to fetch store products: ${response.message()}")
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("ProductRepository", "Error fetching store products", e)
|
Log.e(TAG, "Error fetching store products", e)
|
||||||
throw e
|
throw e
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
companion object {
|
||||||
|
private var TAG = "MyStoreRepository"
|
||||||
|
}
|
||||||
|
|
||||||
// private fun fetchBalance() {
|
// private fun fetchBalance() {
|
||||||
// showLoading(true)
|
// showLoading(true)
|
||||||
// lifecycleScope.launch {
|
// lifecycleScope.launch {
|
||||||
|
@ -99,7 +99,6 @@ class AddressActivity : AppCompatActivity() {
|
|||||||
|
|
||||||
viewModel.selectedAddressId.observe(this) { selectedId ->
|
viewModel.selectedAddressId.observe(this) { selectedId ->
|
||||||
adapter.setSelectedAddressId(selectedId)
|
adapter.setSelectedAddressId(selectedId)
|
||||||
finish()
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -120,6 +119,7 @@ class AddressActivity : AppCompatActivity() {
|
|||||||
val intent = Intent()
|
val intent = Intent()
|
||||||
intent.putExtra(EXTRA_ADDRESS_ID, addressId)
|
intent.putExtra(EXTRA_ADDRESS_ID, addressId)
|
||||||
setResult(RESULT_OK, intent)
|
setResult(RESULT_OK, intent)
|
||||||
|
finish()
|
||||||
}
|
}
|
||||||
|
|
||||||
companion object {
|
companion object {
|
||||||
|
@ -21,6 +21,8 @@ class AddressViewModel(private val repository: OrderRepository): ViewModel() {
|
|||||||
val response = repository.getAddress()
|
val response = repository.getAddress()
|
||||||
response?.let {
|
response?.let {
|
||||||
_addresses.value = it.addresses
|
_addresses.value = it.addresses
|
||||||
|
?.filter { address -> address.isStoreLocation == false }
|
||||||
|
?: emptyList()
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -7,8 +7,10 @@ import androidx.lifecycle.ViewModel
|
|||||||
import androidx.lifecycle.viewModelScope
|
import androidx.lifecycle.viewModelScope
|
||||||
import com.alya.ecommerce_serang.data.api.dto.City
|
import com.alya.ecommerce_serang.data.api.dto.City
|
||||||
import com.alya.ecommerce_serang.data.api.dto.Province
|
import com.alya.ecommerce_serang.data.api.dto.Province
|
||||||
|
import com.alya.ecommerce_serang.data.api.response.customer.order.SubdistrictsItem
|
||||||
import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressesItem
|
import com.alya.ecommerce_serang.data.api.response.customer.profile.AddressesItem
|
||||||
import com.alya.ecommerce_serang.data.repository.AddressRepository
|
import com.alya.ecommerce_serang.data.repository.AddressRepository
|
||||||
|
import com.alya.ecommerce_serang.data.repository.Result
|
||||||
import kotlinx.coroutines.launch
|
import kotlinx.coroutines.launch
|
||||||
|
|
||||||
class AddressViewModel(private val addressRepository: AddressRepository) : ViewModel() {
|
class AddressViewModel(private val addressRepository: AddressRepository) : ViewModel() {
|
||||||
@ -33,6 +35,12 @@ class AddressViewModel(private val addressRepository: AddressRepository) : ViewM
|
|||||||
private val _saveSuccess = MutableLiveData<Boolean>()
|
private val _saveSuccess = MutableLiveData<Boolean>()
|
||||||
val saveSuccess: LiveData<Boolean> get() = _saveSuccess
|
val saveSuccess: LiveData<Boolean> get() = _saveSuccess
|
||||||
|
|
||||||
|
private val _subdistrictState = MutableLiveData<Result<List<SubdistrictsItem>>>()
|
||||||
|
val subdistrictState: LiveData<Result<List<SubdistrictsItem>>> = _subdistrictState
|
||||||
|
|
||||||
|
|
||||||
|
var selectedSubdistrict: String? = null
|
||||||
|
val subdistrict = MutableLiveData<String>()
|
||||||
|
|
||||||
fun fetchProvinces() {
|
fun fetchProvinces() {
|
||||||
viewModelScope.launch {
|
viewModelScope.launch {
|
||||||
@ -64,6 +72,29 @@ class AddressViewModel(private val addressRepository: AddressRepository) : ViewM
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fun getSubdistrict(cityId: String) {
|
||||||
|
_subdistrictState.value = Result.Loading
|
||||||
|
viewModelScope.launch {
|
||||||
|
try {
|
||||||
|
|
||||||
|
selectedSubdistrict = cityId
|
||||||
|
val result = addressRepository.getListSubdistrict(cityId)
|
||||||
|
result?.let {
|
||||||
|
_subdistrictState.postValue(Result.Success(it.subdistricts))
|
||||||
|
Log.d(TAG, "Cities loaded for province $cityId: ${it.subdistricts.size}")
|
||||||
|
} ?: run {
|
||||||
|
_subdistrictState.postValue(Result.Error(Exception("Failed to load cities")))
|
||||||
|
Log.e(TAG, "City result was null for province $cityId")
|
||||||
|
}
|
||||||
|
} catch (e: Exception) {
|
||||||
|
_subdistrictState.postValue(Result.Error(Exception(e.message ?: "Error loading cities")))
|
||||||
|
Log.e(TAG, "Error fetching cities for province $cityId", e)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// fun fetchProvinces() {
|
// fun fetchProvinces() {
|
||||||
// Log.d(TAG, "fetchProvinces() called")
|
// Log.d(TAG, "fetchProvinces() called")
|
||||||
// _isLoading.value = true
|
// _isLoading.value = true
|
||||||
@ -223,6 +254,7 @@ class AddressViewModel(private val addressRepository: AddressRepository) : ViewM
|
|||||||
}
|
}
|
||||||
|
|
||||||
private fun buildUpdateBody(oldAddress: AddressesItem, newAddress: AddressesItem): Map<String, Any> {
|
private fun buildUpdateBody(oldAddress: AddressesItem, newAddress: AddressesItem): Map<String, Any> {
|
||||||
|
|
||||||
val params = mutableMapOf<String, Any>()
|
val params = mutableMapOf<String, Any>()
|
||||||
|
|
||||||
fun addIfChanged(key: String, oldValue: Any?, newValue: Any?) {
|
fun addIfChanged(key: String, oldValue: Any?, newValue: Any?) {
|
||||||
|
@ -21,6 +21,8 @@ import java.text.NumberFormat
|
|||||||
import java.util.Locale
|
import java.util.Locale
|
||||||
|
|
||||||
class MyStoreViewModel(private val repository: MyStoreRepository): ViewModel() {
|
class MyStoreViewModel(private val repository: MyStoreRepository): ViewModel() {
|
||||||
|
private var TAG = "MyStoreViewModel"
|
||||||
|
|
||||||
private val _myStoreProfile = MutableLiveData<Store?>()
|
private val _myStoreProfile = MutableLiveData<Store?>()
|
||||||
val myStoreProfile: LiveData<Store?> = _myStoreProfile
|
val myStoreProfile: LiveData<Store?> = _myStoreProfile
|
||||||
|
|
||||||
@ -84,30 +86,40 @@ class MyStoreViewModel(private val repository: MyStoreRepository): ViewModel() {
|
|||||||
|
|
||||||
if (store == null) {
|
if (store == null) {
|
||||||
_errorMessage.postValue("Data toko tidak tersedia")
|
_errorMessage.postValue("Data toko tidak tersedia")
|
||||||
|
Log.e(TAG, "Store data is null")
|
||||||
return@launch
|
return@launch
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Log.d("UpdateStoreProfileVM", "Calling repository with params:")
|
||||||
|
Log.d("UpdateStoreProfileVM", "storeName: $storeName")
|
||||||
|
Log.d("UpdateStoreProfileVM", "description: $description")
|
||||||
|
Log.d("UpdateStoreProfileVM", "isOnLeave: $isOnLeave")
|
||||||
|
Log.d("UpdateStoreProfileVM", "storeType: $storeType")
|
||||||
|
Log.d("UpdateStoreProfileVM", "storeImage: ${storeImage?.headers}")
|
||||||
|
|
||||||
val response = repository.updateStoreProfile(
|
val response = repository.updateStoreProfile(
|
||||||
storeName = storeName,
|
storeName = storeName,
|
||||||
storeStatus = "active".toRequestBody(),
|
|
||||||
storeDescription = description,
|
storeDescription = description,
|
||||||
isOnLeave = isOnLeave,
|
isOnLeave = isOnLeave,
|
||||||
cityId = store.cityId.toString().toRequestBody(),
|
|
||||||
provinceId = store.provinceId.toString().toRequestBody(),
|
|
||||||
street = store.street.toRequestBody(),
|
|
||||||
subdistrict = store.subdistrict.toRequestBody(),
|
|
||||||
detail = store.detail.toRequestBody(),
|
|
||||||
postalCode = store.postalCode.toRequestBody(),
|
|
||||||
latitude = store.latitude.toRequestBody(),
|
|
||||||
longitude = store.longitude.toRequestBody(),
|
|
||||||
userPhone = store.phone.toRequestBody(),
|
|
||||||
storeType = storeType,
|
storeType = storeType,
|
||||||
storeimg = storeImage
|
storeimg = storeImage
|
||||||
)
|
)
|
||||||
if (response.isSuccessful) _updateStoreProfileResult.postValue(response.body())
|
|
||||||
else _errorMessage.postValue("Gagal memperbarui profil")
|
if (response != null) {
|
||||||
|
if (response.isSuccessful) {
|
||||||
|
_updateStoreProfileResult.postValue(response.body())
|
||||||
|
Log.d(TAG, "Update successful: ${response.body()}")
|
||||||
|
} else {
|
||||||
|
_errorMessage.postValue("Gagal memperbarui profil")
|
||||||
|
Log.e(TAG, "Update failed: ${response.errorBody()?.string()}")
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
_errorMessage.postValue("Terjadi kesalahan jaringan atau server")
|
||||||
|
Log.e(TAG, "Repository returned null response")
|
||||||
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
_errorMessage.postValue(e.message ?: "Unexpected error")
|
_errorMessage.postValue(e.message ?: "Unexpected error")
|
||||||
|
Log.e(TAG, "Exception updating store profile", e)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -120,13 +132,13 @@ class MyStoreViewModel(private val repository: MyStoreRepository): ViewModel() {
|
|||||||
result.data.orders.size ?: 0
|
result.data.orders.size ?: 0
|
||||||
}
|
}
|
||||||
is Result.Error -> {
|
is Result.Error -> {
|
||||||
Log.e("SellsViewModel", "Error getting orders count: ${result.exception.message}")
|
Log.e(TAG, "Error getting orders count: ${result.exception.message}")
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
is Result.Loading -> 0
|
is Result.Loading -> 0
|
||||||
}
|
}
|
||||||
} catch (e: Exception) {
|
} catch (e: Exception) {
|
||||||
Log.e("SellsViewModel", "Exception getting orders count", e)
|
Log.e(TAG, "Exception getting orders count", e)
|
||||||
0
|
0
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -138,7 +150,7 @@ class MyStoreViewModel(private val repository: MyStoreRepository): ViewModel() {
|
|||||||
|
|
||||||
statuses.forEach { status ->
|
statuses.forEach { status ->
|
||||||
counts[status] = getTotalOrdersByStatus(status)
|
counts[status] = getTotalOrdersByStatus(status)
|
||||||
Log.d("SellsViewModel", "Status: $status, countOrder=${counts[status]}")
|
Log.d(TAG, "Status: $status, countOrder=${counts[status]}")
|
||||||
}
|
}
|
||||||
|
|
||||||
return counts
|
return counts
|
||||||
|
@ -37,6 +37,7 @@
|
|||||||
android:layout_height="wrap_content"
|
android:layout_height="wrap_content"
|
||||||
android:src="@drawable/baseline_edit_24"
|
android:src="@drawable/baseline_edit_24"
|
||||||
android:layout_marginHorizontal="16dp"
|
android:layout_marginHorizontal="16dp"
|
||||||
|
android:visibility="gone"
|
||||||
app:layout_constraintEnd_toEndOf="parent"
|
app:layout_constraintEnd_toEndOf="parent"
|
||||||
app:layout_constraintTop_toTopOf="parent"/>
|
app:layout_constraintTop_toTopOf="parent"/>
|
||||||
<TextView
|
<TextView
|
||||||
|
Reference in New Issue
Block a user