-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[AN] feat: 내 강아지 조회 및 추가하기 API 연결 (#183)
- Loading branch information
1 parent
c1e441c
commit f3b7300
Showing
48 changed files
with
719 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
22 changes: 22 additions & 0 deletions
22
android/app/src/main/java/com/woowacourse/friendogly/data/mapper/GenderMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.woowacourse.friendogly.data.mapper | ||
|
||
import com.woowacourse.friendogly.data.model.GenderDto | ||
import com.woowacourse.friendogly.domain.model.Gender | ||
|
||
fun GenderDto.toDomain(): Gender { | ||
return when (this) { | ||
GenderDto.MALE -> Gender.MALE | ||
GenderDto.FEMALE -> Gender.FEMALE | ||
GenderDto.MALE_NEUTERED -> Gender.MALE_NEUTERED | ||
GenderDto.FEMALE_NEUTERED -> Gender.FEMALE_NEUTERED | ||
} | ||
} | ||
|
||
fun Gender.toData(): GenderDto { | ||
return when (this) { | ||
Gender.MALE -> GenderDto.MALE | ||
Gender.FEMALE -> GenderDto.FEMALE | ||
Gender.MALE_NEUTERED -> GenderDto.MALE_NEUTERED | ||
Gender.FEMALE_NEUTERED -> GenderDto.FEMALE_NEUTERED | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
android/app/src/main/java/com/woowacourse/friendogly/data/mapper/PetMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.woowacourse.friendogly.data.mapper | ||
|
||
import com.woowacourse.friendogly.data.model.PetDto | ||
import com.woowacourse.friendogly.domain.model.Pet | ||
|
||
fun PetDto.toDomain(): Pet { | ||
return Pet( | ||
id = this.id, | ||
memberId = this.memberId, | ||
name = this.name, | ||
description = this.description, | ||
birthDate = this.birthDate, | ||
sizeType = this.sizeType.toDomain(), | ||
gender = this.gender.toDomain(), | ||
imageUrl = this.imageUrl, | ||
) | ||
} |
13 changes: 13 additions & 0 deletions
13
android/app/src/main/java/com/woowacourse/friendogly/data/mapper/PetsMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.woowacourse.friendogly.data.mapper | ||
|
||
import com.woowacourse.friendogly.data.model.PetsDto | ||
import com.woowacourse.friendogly.domain.model.Pets | ||
|
||
fun PetsDto.toDomain(): Pets { | ||
return Pets( | ||
contents = | ||
this.contents.map { petResponse -> | ||
petResponse.toDomain() | ||
}, | ||
) | ||
} |
20 changes: 20 additions & 0 deletions
20
android/app/src/main/java/com/woowacourse/friendogly/data/mapper/SizeTypeMapper.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.woowacourse.friendogly.data.mapper | ||
|
||
import com.woowacourse.friendogly.data.model.SizeTypeDto | ||
import com.woowacourse.friendogly.domain.model.SizeType | ||
|
||
fun SizeTypeDto.toDomain(): SizeType { | ||
return when (this) { | ||
SizeTypeDto.SMALL -> SizeType.SMALL | ||
SizeTypeDto.MEDIUM -> SizeType.MEDIUM | ||
SizeTypeDto.LARGE -> SizeType.LARGE | ||
} | ||
} | ||
|
||
fun SizeType.toData(): SizeTypeDto { | ||
return when (this) { | ||
SizeType.SMALL -> SizeTypeDto.SMALL | ||
SizeType.MEDIUM -> SizeTypeDto.MEDIUM | ||
SizeType.LARGE -> SizeTypeDto.LARGE | ||
} | ||
} |
8 changes: 8 additions & 0 deletions
8
android/app/src/main/java/com/woowacourse/friendogly/data/model/GenderDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.woowacourse.friendogly.data.model | ||
|
||
enum class GenderDto { | ||
MALE, | ||
FEMALE, | ||
MALE_NEUTERED, | ||
FEMALE_NEUTERED, | ||
} |
17 changes: 17 additions & 0 deletions
17
android/app/src/main/java/com/woowacourse/friendogly/data/model/PetDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.woowacourse.friendogly.data.model | ||
|
||
import com.woowacourse.friendogly.remote.util.LocalDateSerializer | ||
import kotlinx.datetime.LocalDate | ||
import kotlinx.serialization.Serializable | ||
|
||
data class PetDto( | ||
val id: Long, | ||
val memberId: Long, | ||
val name: String, | ||
val description: String, | ||
@Serializable(with = LocalDateSerializer::class) | ||
val birthDate: LocalDate, | ||
val sizeType: SizeTypeDto, | ||
val gender: GenderDto, | ||
val imageUrl: String, | ||
) |
5 changes: 5 additions & 0 deletions
5
android/app/src/main/java/com/woowacourse/friendogly/data/model/PetsDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.woowacourse.friendogly.data.model | ||
|
||
data class PetsDto( | ||
val contents: List<PetDto>, | ||
) |
7 changes: 7 additions & 0 deletions
7
android/app/src/main/java/com/woowacourse/friendogly/data/model/SizeTypeDto.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.woowacourse.friendogly.data.model | ||
|
||
enum class SizeTypeDto { | ||
SMALL, | ||
MEDIUM, | ||
LARGE, | ||
} |
32 changes: 32 additions & 0 deletions
32
android/app/src/main/java/com/woowacourse/friendogly/data/repository/PetRepositoryImpl.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package com.woowacourse.friendogly.data.repository | ||
|
||
import com.woowacourse.friendogly.data.mapper.toData | ||
import com.woowacourse.friendogly.data.mapper.toDomain | ||
import com.woowacourse.friendogly.data.source.PetDataSource | ||
import com.woowacourse.friendogly.domain.model.Gender | ||
import com.woowacourse.friendogly.domain.model.Pet | ||
import com.woowacourse.friendogly.domain.model.SizeType | ||
import com.woowacourse.friendogly.domain.repository.PetRepository | ||
import kotlinx.datetime.LocalDate | ||
|
||
class PetRepositoryImpl(private val source: PetDataSource) : PetRepository { | ||
override suspend fun getPetsMine(): Result<List<Pet>> = | ||
source.getPetsMine().mapCatching { result -> result.map { petDto -> petDto.toDomain() } } | ||
|
||
override suspend fun postPet( | ||
name: String, | ||
description: String, | ||
birthday: LocalDate, | ||
sizeType: SizeType, | ||
gender: Gender, | ||
imageUrl: String, | ||
): Result<Pet> = | ||
source.postPet( | ||
name = name, | ||
description = description, | ||
birthday = birthday, | ||
sizeType = sizeType.toData(), | ||
gender = gender.toData(), | ||
imageUrl = imageUrl, | ||
).mapCatching { result -> result.toDomain() } | ||
} |
19 changes: 19 additions & 0 deletions
19
android/app/src/main/java/com/woowacourse/friendogly/data/source/PetDataSource.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.woowacourse.friendogly.data.source | ||
|
||
import com.woowacourse.friendogly.data.model.GenderDto | ||
import com.woowacourse.friendogly.data.model.PetDto | ||
import com.woowacourse.friendogly.data.model.SizeTypeDto | ||
import kotlinx.datetime.LocalDate | ||
|
||
interface PetDataSource { | ||
suspend fun getPetsMine(): Result<List<PetDto>> | ||
|
||
suspend fun postPet( | ||
name: String, | ||
description: String, | ||
birthday: LocalDate, | ||
sizeType: SizeTypeDto, | ||
gender: GenderDto, | ||
imageUrl: String, | ||
): Result<PetDto> | ||
} |
8 changes: 8 additions & 0 deletions
8
android/app/src/main/java/com/woowacourse/friendogly/domain/model/Gender.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
package com.woowacourse.friendogly.domain.model | ||
|
||
enum class Gender { | ||
MALE, | ||
FEMALE, | ||
MALE_NEUTERED, | ||
FEMALE_NEUTERED, | ||
} |
14 changes: 14 additions & 0 deletions
14
android/app/src/main/java/com/woowacourse/friendogly/domain/model/Pet.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package com.woowacourse.friendogly.domain.model | ||
|
||
import kotlinx.datetime.LocalDate | ||
|
||
data class Pet( | ||
val id: Long, | ||
val memberId: Long, | ||
val name: String, | ||
val description: String, | ||
val birthDate: LocalDate, | ||
val sizeType: SizeType, | ||
val gender: Gender, | ||
val imageUrl: String, | ||
) |
5 changes: 5 additions & 0 deletions
5
android/app/src/main/java/com/woowacourse/friendogly/domain/model/Pets.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
package com.woowacourse.friendogly.domain.model | ||
|
||
data class Pets( | ||
val contents: List<Pet>, | ||
) |
7 changes: 7 additions & 0 deletions
7
android/app/src/main/java/com/woowacourse/friendogly/domain/model/SizeType.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.woowacourse.friendogly.domain.model | ||
|
||
enum class SizeType { | ||
SMALL, | ||
MEDIUM, | ||
LARGE, | ||
} |
19 changes: 19 additions & 0 deletions
19
android/app/src/main/java/com/woowacourse/friendogly/domain/repository/PetRepository.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package com.woowacourse.friendogly.domain.repository | ||
|
||
import com.woowacourse.friendogly.domain.model.Gender | ||
import com.woowacourse.friendogly.domain.model.Pet | ||
import com.woowacourse.friendogly.domain.model.SizeType | ||
import kotlinx.datetime.LocalDate | ||
|
||
interface PetRepository { | ||
suspend fun getPetsMine(): Result<List<Pet>> | ||
|
||
suspend fun postPet( | ||
name: String, | ||
description: String, | ||
birthday: LocalDate, | ||
sizeType: SizeType, | ||
gender: Gender, | ||
imageUrl: String, | ||
): Result<Pet> | ||
} |
10 changes: 10 additions & 0 deletions
10
android/app/src/main/java/com/woowacourse/friendogly/domain/usecase/GetPetsMineUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
package com.woowacourse.friendogly.domain.usecase | ||
|
||
import com.woowacourse.friendogly.domain.model.Pet | ||
import com.woowacourse.friendogly.domain.repository.PetRepository | ||
|
||
class GetPetsMineUseCase( | ||
private val repository: PetRepository, | ||
) { | ||
suspend operator fun invoke(): Result<List<Pet>> = repository.getPetsMine() | ||
} |
28 changes: 28 additions & 0 deletions
28
android/app/src/main/java/com/woowacourse/friendogly/domain/usecase/PostPetUseCase.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
package com.woowacourse.friendogly.domain.usecase | ||
|
||
import com.woowacourse.friendogly.domain.model.Gender | ||
import com.woowacourse.friendogly.domain.model.Pet | ||
import com.woowacourse.friendogly.domain.model.SizeType | ||
import com.woowacourse.friendogly.domain.repository.PetRepository | ||
import kotlinx.datetime.LocalDate | ||
|
||
class PostPetUseCase( | ||
private val repository: PetRepository, | ||
) { | ||
suspend operator fun invoke( | ||
name: String, | ||
description: String, | ||
birthday: LocalDate, | ||
sizeType: SizeType, | ||
gender: Gender, | ||
imageUrl: String, | ||
): Result<Pet> = | ||
repository.postPet( | ||
name = name, | ||
description = description, | ||
birthday = birthday, | ||
sizeType = sizeType, | ||
gender = gender, | ||
imageUrl = imageUrl, | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.