-
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.
Merge pull request #515 from woowacourse-teams/AN/feature/441-studyth…
…read-remote [스레드뷰] 서버 연결 및 부가 기능 추가
- Loading branch information
Showing
48 changed files
with
928 additions
and
274 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
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
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
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
41 changes: 41 additions & 0 deletions
41
android/app/src/main/java/com/created/team201/data/mapper/ThreadMapper.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,41 @@ | ||
package com.created.team201.data.mapper | ||
|
||
import com.created.domain.model.Feeds | ||
import com.created.domain.model.MustDo | ||
import com.created.domain.model.MustDoCertification | ||
import com.created.team201.data.remote.response.FeedsResponseDto | ||
import com.created.team201.data.remote.response.MustDoCertificationResponseDto | ||
|
||
fun MustDoCertificationResponseDto.toDomain(): MustDoCertification = MustDoCertification( | ||
studyName = studyName, | ||
upcomingRound = upcomingRound.toUpcomingRound(), | ||
me = me.toMustDo(), | ||
others = others.map { it.toMustDo() } | ||
|
||
) | ||
|
||
fun MustDoCertificationResponseDto.UpcomingRound.toUpcomingRound(): MustDoCertification.UpcomingRound = | ||
MustDoCertification.UpcomingRound( | ||
id = id, weekNumber = weekNumber | ||
|
||
) | ||
|
||
fun MustDoCertificationResponseDto.User.toMustDo(): MustDo = MustDo( | ||
id = id, | ||
isCertified = isCertified, | ||
nickname = nickname, | ||
profileImageUrl = profileImageUrl | ||
) | ||
|
||
fun FeedsResponseDto.toFeeds(): Feeds = Feeds( | ||
author = this.author.toAuthor(), | ||
content = content, | ||
createdAt = createdAt, | ||
id = id.toLong(), | ||
imageUrl = imageUrl ?: "" | ||
// 서버 널 확인 | ||
) | ||
|
||
fun FeedsResponseDto.Author.toAuthor(): Feeds.Author = Feeds.Author( | ||
id = id.toLong(), nickname = nickname, profileImageUrl = profileImageUrl | ||
) |
29 changes: 29 additions & 0 deletions
29
android/app/src/main/java/com/created/team201/data/remote/api/ThreadService.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,29 @@ | ||
package com.created.team201.data.remote.api | ||
|
||
import com.created.team201.data.remote.request.FeedRequestDto | ||
import com.created.team201.data.remote.response.FeedsResponseDto | ||
import com.created.team201.data.remote.response.MustDoCertificationResponseDto | ||
import retrofit2.Response | ||
import retrofit2.http.Body | ||
import retrofit2.http.GET | ||
import retrofit2.http.POST | ||
import retrofit2.http.Path | ||
|
||
interface ThreadService { | ||
|
||
@GET("v1/studies/{id}/certifications") | ||
suspend fun getMustDoCertification( | ||
@Path("id") studyId: Long, | ||
): MustDoCertificationResponseDto | ||
|
||
@POST("v1/studies/{id}/feeds") | ||
suspend fun postFeeds( | ||
@Path("id") studyId: Long, | ||
@Body content: FeedRequestDto | ||
): Response<Unit> | ||
|
||
@GET("v1/studies/{id}/feeds") | ||
suspend fun getFeeds( | ||
@Path("id") studyId: Long, | ||
): List<FeedsResponseDto> | ||
} |
12 changes: 12 additions & 0 deletions
12
android/app/src/main/java/com/created/team201/data/remote/request/FeedRequestDto.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,12 @@ | ||
package com.created.team201.data.remote.request | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class FeedRequestDto( | ||
@SerialName("content") | ||
val content: String, | ||
@SerialName("imageUrl") | ||
val imageUrl: String? | ||
) |
29 changes: 29 additions & 0 deletions
29
android/app/src/main/java/com/created/team201/data/remote/response/FeedsResponseDto.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,29 @@ | ||
package com.created.team201.data.remote.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class FeedsResponseDto( | ||
@SerialName("id") | ||
val id: Int, | ||
@SerialName("author") | ||
val author: Author, | ||
@SerialName("imageUrl") | ||
val imageUrl: String?, | ||
@SerialName("content") | ||
val content: String, | ||
@SerialName("createdAt") | ||
val createdAt: String | ||
) { | ||
@Serializable | ||
data class Author( | ||
@SerialName("id") | ||
val id: Int, | ||
@SerialName("nickname") | ||
val nickname: String, | ||
@SerialName("profileImageUrl") | ||
val profileImageUrl: String | ||
) | ||
} | ||
|
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
37 changes: 37 additions & 0 deletions
37
.../src/main/java/com/created/team201/data/remote/response/MustDoCertificationResponseDto.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,37 @@ | ||
package com.created.team201.data.remote.response | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
@Serializable | ||
data class MustDoCertificationResponseDto( | ||
@SerialName("studyName") | ||
val studyName: String, | ||
@SerialName("upcomingRound") | ||
val upcomingRound: UpcomingRound, | ||
@SerialName("me") | ||
val me: User, | ||
@SerialName("others") | ||
val others: List<User> | ||
) { | ||
@Serializable | ||
data class User( | ||
@SerialName("id") | ||
val id: Int, | ||
@SerialName("nickname") | ||
val nickname: String, | ||
@SerialName("profileImageUrl") | ||
val profileImageUrl: String, | ||
@SerialName("isCertified") | ||
val isCertified: Boolean | ||
) | ||
|
||
@Serializable | ||
data class UpcomingRound( | ||
@SerialName("id") | ||
val id: Int, | ||
@SerialName("weekNumber") | ||
val weekNumber: Int, | ||
) | ||
} | ||
|
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
56 changes: 56 additions & 0 deletions
56
android/app/src/main/java/com/created/team201/data/repository/DefaultThreadRepository.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,56 @@ | ||
package com.created.team201.data.repository | ||
|
||
import com.created.domain.model.Feeds | ||
import com.created.domain.model.MustDoCertification | ||
import com.created.domain.repository.ThreadRepository | ||
import com.created.team201.data.mapper.toDomain | ||
import com.created.team201.data.mapper.toFeeds | ||
import com.created.team201.data.remote.api.ThreadService | ||
import com.created.team201.data.remote.request.FeedRequestDto | ||
import kotlinx.coroutines.Dispatchers | ||
import kotlinx.coroutines.delay | ||
import kotlinx.coroutines.flow.Flow | ||
import kotlinx.coroutines.flow.flow | ||
import kotlinx.coroutines.flow.flowOn | ||
import javax.inject.Inject | ||
|
||
class DefaultThreadRepository @Inject constructor( | ||
private val threadService: ThreadService | ||
) : ThreadRepository { | ||
|
||
override suspend fun getMustDoCertification(studyId: Long): MustDoCertification { | ||
val mustDoCertification = threadService.getMustDoCertification(studyId = studyId) | ||
|
||
return mustDoCertification.toDomain() | ||
} | ||
|
||
override fun getFeeds(studyId: Long): Flow<List<Feeds>> = flow { | ||
while (true) { | ||
val feeds = threadService.getFeeds(studyId).map { it.toFeeds() } | ||
|
||
emit(feeds) | ||
delay(1000) | ||
} | ||
}.flowOn(Dispatchers.IO) | ||
|
||
override suspend fun updateFeeds(studyId: Long, content: String, image: String?) { | ||
threadService.postFeeds( | ||
studyId, | ||
FeedRequestDto( | ||
content = content, imageUrl = image | ||
) | ||
) | ||
} | ||
|
||
override fun postMustDoCertification(studyId: Long) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getStudyInfo(studyId: Long) { | ||
TODO("Not yet implemented") | ||
} | ||
|
||
override fun getMustDo(studyId: Long) { | ||
TODO("Not yet implemented") | ||
} | ||
} |
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
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
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.