feat(#6): Implement full CRUD for Locations and Labels
This commit is contained in:
@@ -65,6 +65,29 @@ interface HomeboxApiService {
|
||||
suspend fun createLabel(@Body newLabel: LabelCreateDto): LabelSummaryDto
|
||||
// [END_ENTITY: ApiEndpoint('createLabel')]
|
||||
|
||||
// [ENTITY: ApiEndpoint('updateLabel')]
|
||||
@PUT("v1/labels/{id}")
|
||||
suspend fun updateLabel(@Path("id") labelId: String, @Body label: LabelUpdateDto): LabelOutDto
|
||||
// [END_ENTITY: ApiEndpoint('updateLabel')]
|
||||
|
||||
// [ENTITY: ApiEndpoint('deleteLabel')]
|
||||
@DELETE("v1/labels/{id}")
|
||||
suspend fun deleteLabel(@Path("id") labelId: String): Response<Unit>
|
||||
|
||||
// [ENTITY: ApiEndpoint('createLocation')]
|
||||
@POST("v1/locations")
|
||||
suspend fun createLocation(@Body newLocation: LocationCreateDto): LocationOutDto
|
||||
// [END_ENTITY: ApiEndpoint('createLocation')]
|
||||
|
||||
// [ENTITY: ApiEndpoint('updateLocation')]
|
||||
@PUT("v1/locations/{id}")
|
||||
suspend fun updateLocation(@Path("id") locationId: String, @Body location: LocationUpdateDto): LocationOutDto
|
||||
// [END_ENTITY: ApiEndpoint('updateLocation')]
|
||||
|
||||
// [ENTITY: ApiEndpoint('deleteLocation')]
|
||||
@DELETE("v1/locations/{id}")
|
||||
suspend fun deleteLocation(@Path("id") locationId: String): Response<Unit>
|
||||
|
||||
// [ENTITY: ApiEndpoint('getStatistics')]
|
||||
@GET("v1/groups/statistics")
|
||||
suspend fun getStatistics(): GroupStatisticsDto
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// [PACKAGE] com.homebox.lens.data.api.dto
|
||||
// [FILE] LabelUpdateDto.kt
|
||||
// [SEMANTICS] data_transfer_object, label, update
|
||||
package com.homebox.lens.data.api.dto
|
||||
|
||||
// [IMPORTS]
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import com.homebox.lens.domain.model.LabelUpdate
|
||||
// [END_IMPORTS]
|
||||
|
||||
// [ENTITY: DataClass('LabelUpdateDto')]
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class LabelUpdateDto(
|
||||
@Json(name = "name")
|
||||
val name: String?,
|
||||
@Json(name = "color")
|
||||
val color: String?
|
||||
)
|
||||
// [END_ENTITY: DataClass('LabelUpdateDto')]
|
||||
|
||||
// [ENTITY: Function('toDto')]
|
||||
// [RELATION: Function('toDto')] -> [RETURNS] -> [DataClass('LabelUpdateDto')]
|
||||
fun LabelUpdate.toDto(): LabelUpdateDto {
|
||||
return LabelUpdateDto(
|
||||
name = this.name,
|
||||
color = this.color
|
||||
)
|
||||
}
|
||||
// [END_ENTITY: Function('toDto')]
|
||||
// [END_FILE_LabelUpdateDto.kt]
|
||||
@@ -0,0 +1,22 @@
|
||||
// [PACKAGE] com.homebox.lens.data.api.dto
|
||||
// [FILE] LocationCreateDto.kt
|
||||
// [SEMANTICS] data_transfer_object, location, create
|
||||
package com.homebox.lens.data.api.dto
|
||||
|
||||
// [IMPORTS]
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
// [END_IMPORTS]
|
||||
|
||||
// [ENTITY: DataClass('LocationCreateDto')]
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class LocationCreateDto(
|
||||
@Json(name = "name")
|
||||
val name: String,
|
||||
@Json(name = "color")
|
||||
val color: String?,
|
||||
@Json(name = "description")
|
||||
val description: String? // Assuming description can be null for creation
|
||||
)
|
||||
// [END_ENTITY: DataClass('LocationCreateDto')]
|
||||
// [END_FILE_LocationCreateDto.kt]
|
||||
@@ -1,7 +1,6 @@
|
||||
// [PACKAGE] com.homebox.lens.data.api.dto
|
||||
// [FILE] LocationOutDto.kt
|
||||
// [SEMANTICS] data_transfer_object, location
|
||||
|
||||
// [SEMANTICS] data_transfer_object, location, output
|
||||
package com.homebox.lens.data.api.dto
|
||||
|
||||
// [IMPORTS]
|
||||
@@ -11,25 +10,25 @@ import com.homebox.lens.domain.model.LocationOut
|
||||
// [END_IMPORTS]
|
||||
|
||||
// [ENTITY: DataClass('LocationOutDto')]
|
||||
/**
|
||||
* @summary DTO для местоположения.
|
||||
*/
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class LocationOutDto(
|
||||
@Json(name = "id") val id: String,
|
||||
@Json(name = "name") val name: String,
|
||||
@Json(name = "color") val color: String,
|
||||
@Json(name = "isArchived") val isArchived: Boolean,
|
||||
@Json(name = "createdAt") val createdAt: String,
|
||||
@Json(name = "updatedAt") val updatedAt: String
|
||||
@Json(name = "id")
|
||||
val id: String,
|
||||
@Json(name = "name")
|
||||
val name: String,
|
||||
@Json(name = "color")
|
||||
val color: String,
|
||||
@Json(name = "isArchived")
|
||||
val isArchived: Boolean,
|
||||
@Json(name = "createdAt")
|
||||
val createdAt: String,
|
||||
@Json(name = "updatedAt")
|
||||
val updatedAt: String
|
||||
)
|
||||
// [END_ENTITY: DataClass('LocationOutDto')]
|
||||
|
||||
// [ENTITY: Function('toDomain')]
|
||||
// [RELATION: Function('toDomain')] -> [RETURNS] -> [DataClass('LocationOut')]
|
||||
/**
|
||||
* @summary Маппер из LocationOutDto в доменную модель LocationOut.
|
||||
*/
|
||||
fun LocationOutDto.toDomain(): LocationOut {
|
||||
return LocationOut(
|
||||
id = this.id,
|
||||
@@ -40,4 +39,5 @@ fun LocationOutDto.toDomain(): LocationOut {
|
||||
updatedAt = this.updatedAt
|
||||
)
|
||||
}
|
||||
// [END_ENTITY: Function('toDomain')]
|
||||
// [END_ENTITY: Function('toDomain')]
|
||||
// [END_FILE_LocationOutDto.kt]
|
||||
|
||||
@@ -0,0 +1,31 @@
|
||||
// [PACKAGE] com.homebox.lens.data.api.dto
|
||||
// [FILE] LocationUpdateDto.kt
|
||||
// [SEMANTICS] data_transfer_object, location, update
|
||||
package com.homebox.lens.data.api.dto
|
||||
|
||||
// [IMPORTS]
|
||||
import com.squareup.moshi.Json
|
||||
import com.squareup.moshi.JsonClass
|
||||
import com.homebox.lens.domain.model.LocationUpdate
|
||||
// [END_IMPORTS]
|
||||
|
||||
// [ENTITY: DataClass('LocationUpdateDto')]
|
||||
@JsonClass(generateAdapter = true)
|
||||
data class LocationUpdateDto(
|
||||
@Json(name = "name")
|
||||
val name: String?,
|
||||
@Json(name = "color")
|
||||
val color: String?
|
||||
)
|
||||
// [END_ENTITY: DataClass('LocationUpdateDto')]
|
||||
|
||||
// [ENTITY: Function('toDto')]
|
||||
// [RELATION: Function('toDto')] -> [RETURNS] -> [DataClass('LocationUpdateDto')]
|
||||
fun LocationUpdate.toDto(): LocationUpdateDto {
|
||||
return LocationUpdateDto(
|
||||
name = this.name,
|
||||
color = this.color
|
||||
)
|
||||
}
|
||||
// [END_ENTITY: Function('toDto')]
|
||||
// [END_FILE_LocationUpdateDto.kt]
|
||||
@@ -8,6 +8,10 @@ import com.homebox.lens.data.api.HomeboxApiService
|
||||
import com.homebox.lens.data.api.dto.LabelCreateDto
|
||||
import com.homebox.lens.data.api.dto.toDomain
|
||||
import com.homebox.lens.data.api.dto.toDto
|
||||
import com.homebox.lens.data.api.dto.LocationCreateDto
|
||||
import com.homebox.lens.data.api.dto.LocationUpdateDto
|
||||
import com.homebox.lens.data.api.dto.LabelUpdateDto
|
||||
import com.homebox.lens.data.api.dto.LocationOutDto
|
||||
import com.homebox.lens.data.db.dao.ItemDao
|
||||
import com.homebox.lens.data.db.entity.toDomain
|
||||
import com.homebox.lens.domain.model.*
|
||||
@@ -101,6 +105,32 @@ class ItemRepositoryImpl @Inject constructor(
|
||||
}
|
||||
// [END_ENTITY: Function('createLabel')]
|
||||
|
||||
override suspend fun updateLabel(labelId: String, labelData: LabelUpdate): LabelOut {
|
||||
val labelDto = labelData.toDto()
|
||||
val resultDto = apiService.updateLabel(labelId, labelDto)
|
||||
return resultDto.toDomain()
|
||||
}
|
||||
|
||||
override suspend fun deleteLabel(labelId: String) {
|
||||
apiService.deleteLabel(labelId)
|
||||
}
|
||||
|
||||
override suspend fun createLocation(newLocationData: LocationCreate): LocationOut {
|
||||
val locationDto = newLocationData.toDto()
|
||||
val resultDto = apiService.createLocation(locationDto)
|
||||
return resultDto.toDomain()
|
||||
}
|
||||
|
||||
override suspend fun updateLocation(locationId: String, locationData: LocationUpdate): LocationOut {
|
||||
val locationDto = locationData.toDto()
|
||||
val resultDto = apiService.updateLocation(locationId, locationDto)
|
||||
return resultDto.toDomain()
|
||||
}
|
||||
|
||||
override suspend fun deleteLocation(locationId: String) {
|
||||
apiService.deleteLocation(locationId)
|
||||
}
|
||||
|
||||
// [ENTITY: Function('searchItems')]
|
||||
// [RELATION: Function('searchItems')] -> [RETURNS] -> [DataClass('PaginationResult<ItemSummary>')]
|
||||
override suspend fun searchItems(query: String): PaginationResult<ItemSummary> {
|
||||
@@ -131,4 +161,25 @@ private fun LabelCreate.toDto(): LabelCreateDto {
|
||||
}
|
||||
// [END_ENTITY: Function('toDto')]
|
||||
|
||||
// [ENTITY: Function('toDto')]
|
||||
// [RELATION: Function('toDto')] -> [RETURNS] -> [DataClass('LocationCreateDto')]
|
||||
private fun LocationCreate.toDto(): LocationCreateDto {
|
||||
return LocationCreateDto(
|
||||
name = this.name,
|
||||
color = this.color,
|
||||
description = null // Description is not part of the domain model for creation.
|
||||
)
|
||||
}
|
||||
// [END_ENTITY: Function('toDto')]
|
||||
|
||||
// [ENTITY: Function('toDto')]
|
||||
// [RELATION: Function('toDto')] -> [RETURNS] -> [DataClass('LabelUpdateDto')]
|
||||
private fun LabelUpdate.toDto(): LabelUpdateDto {
|
||||
return LabelUpdateDto(
|
||||
name = this.name,
|
||||
color = this.color
|
||||
)
|
||||
}
|
||||
// [END_ENTITY: Function('toDto')]
|
||||
|
||||
// [END_FILE_ItemRepositoryImpl.kt]
|
||||
Reference in New Issue
Block a user