Skip to content

Commit

Permalink
Merge pull request #305 from Runnect/feature/feat-get-user-profile
Browse files Browse the repository at this point in the history
[FEAT] 코스 발견 / 상세페이지 타 유저 프로필 조회
  • Loading branch information
sxunea authored Jan 10, 2024
2 parents 8327d2b + b9df77d commit f676d4c
Show file tree
Hide file tree
Showing 25 changed files with 519 additions and 134 deletions.
3 changes: 3 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -134,6 +134,9 @@
<activity
android:name=".presentation.mypage.upload.MyUploadActivity"
android:exported="false" />
<activity
android:name=".presentation.profile.ProfileActivity"
android:exported="false" />

<provider
android:name="androidx.core.content.FileProvider"
Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,9 @@ data class ResponseGetCourseDetail(
@SerialName("image")
val image: String,
@SerialName("isNowUser")
val isNowUser: Boolean
val isNowUser: Boolean,
@SerialName("id")
val id: Int
)

@Serializable
Expand Down Expand Up @@ -65,6 +67,7 @@ data class ResponseGetCourseDetail(
level = user.level.toString(),
nickname = user.nickname,
isNowUser = user.isNowUser,
userId = user.id,
id = publicCourse.id,
courseId = publicCourse.courseId,
departure = publicCourse.departure.region + ' ' +
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package com.runnect.runnect.data.dto.response

import com.runnect.runnect.domain.entity.Departure
import com.runnect.runnect.domain.entity.UserCourse
import com.runnect.runnect.domain.entity.UserProfile
import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponseGetUserProfile(
@SerialName("user")
val user: User,
@SerialName("courses")
val courses: List<CourseData>
) {
@Serializable
data class User(
@SerialName("nickname")
val nickname: String,
@SerialName("level")
val level: Int,
@SerialName("levelPercent")
val levelPercent: Int,
@SerialName("latestStamp")
val latestStamp: String,
@SerialName("userId")
val userId: Int
)

@Serializable
data class CourseData(
@SerialName("publicCourseId")
val publicCourseId: Int,
@SerialName("courseId")
val courseId: Int,
@SerialName("title")
val title: String,
@SerialName("image")
val image: String,
@SerialName("departure")
val departure: Departure,
@SerialName("scrapTF")
val scrapTF: Boolean,
) {
@Serializable
data class Departure(
@SerialName("region")
val region: String,
@SerialName("city")
val city: String,
@SerialName("town")
val town: String,
@SerialName("name")
val name: String?,
@SerialName("detail")
val detail: String?
)
}

fun toUserProfile(): UserProfile {
val userCourseLists: List<UserCourse> = courses.map { course ->
UserCourse(
publicCourseId = course.publicCourseId,
courseId = course.courseId,
title = course.title,
image = course.image,
departure = Departure(
region = course.departure.region,
city = course.departure.city,
town = course.departure.town,
detail = course.departure.detail,
name = course.departure.name ?: ""
),
scrapTF = course.scrapTF
)
}

return UserProfile(
nickname = user.nickname,
level = user.level,
levelPercent = user.levelPercent,
latestStamp = user.latestStamp,
courseData = userCourseLists
)
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.runnect.runnect.data.dto.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable

@Serializable
data class ResponsePostScrap(
@SerialName("publicCourseId")
val publicCourseId: Long,
@SerialName("scrapCount")
val scrapCount: Long,
@SerialName("scrapTF")
val scrapTF: Boolean
)
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ import com.runnect.runnect.data.dto.response.ResponsePostMyDrawCourse
import com.runnect.runnect.data.dto.response.ResponsePostMyHistory
import com.runnect.runnect.data.dto.response.ResponsePutMyDrawCourse
import com.runnect.runnect.data.dto.response.ResponsePostDiscoverUpload
import com.runnect.runnect.data.dto.response.ResponsePostScrap
import com.runnect.runnect.data.source.remote.RemoteCourseDataSource
import com.runnect.runnect.domain.entity.DiscoverSearchCourse
import com.runnect.runnect.domain.entity.DiscoverMultiViewItem.*
Expand Down Expand Up @@ -100,7 +101,7 @@ class CourseRepositoryImpl @Inject constructor(private val remoteCourseDataSourc

override suspend fun postCourseScrap(
requestPostCourseScrap: RequestPostCourseScrap
): Result<Unit?> = runCatching {
): Result<ResponsePostScrap?> = runCatching {
remoteCourseDataSource.postCourseScrap(requestPostCourseScrap = requestPostCourseScrap).data
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.runnect.runnect.data.repository

import com.runnect.runnect.data.dto.HistoryInfoDTO
import com.runnect.runnect.domain.entity.UserProfile
import com.runnect.runnect.data.dto.UserUploadCourseDTO
import com.runnect.runnect.data.dto.request.RequestDeleteHistory
import com.runnect.runnect.data.dto.request.RequestDeleteUploadCourse
Expand All @@ -9,9 +10,9 @@ import com.runnect.runnect.data.dto.request.RequestPatchNickName
import com.runnect.runnect.data.dto.response.ResponseDeleteHistory
import com.runnect.runnect.data.dto.response.ResponseDeleteUploadCourse
import com.runnect.runnect.data.dto.response.ResponseDeleteUser
import com.runnect.runnect.data.dto.response.ResponseGetUser
import com.runnect.runnect.data.dto.response.ResponsePatchHistoryTitle
import com.runnect.runnect.data.dto.response.ResponsePatchUserNickName
import com.runnect.runnect.data.dto.response.ResponseGetUser
import com.runnect.runnect.data.source.remote.RemoteUserDataSource
import com.runnect.runnect.domain.repository.UserRepository
import com.runnect.runnect.util.extension.toData
Expand All @@ -36,6 +37,11 @@ class UserRepositoryImpl @Inject constructor(private val remoteUserDataSource: R
.toMutableList()
}

override suspend fun getUserProfile(userId: Int): Result<UserProfile?> =
runCatching {
remoteUserDataSource.getUserProfile(userId).data?.toUserProfile()
}

override suspend fun putDeleteUploadCourse(
requestDeleteUploadCourse: RequestDeleteUploadCourse
): Result<ResponseDeleteUploadCourse?> = runCatching {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package com.runnect.runnect.data.service

import com.runnect.runnect.data.dto.request.RequestPatchPublicCourse
import com.runnect.runnect.data.dto.request.RequestPostCourseScrap
import com.runnect.runnect.data.dto.request.RequestPostPublicCourse
import com.runnect.runnect.data.dto.request.RequestPostRunningHistory
import com.runnect.runnect.data.dto.request.RequestPutMyDrawCourse
import com.runnect.runnect.data.dto.request.RequestPatchPublicCourse
import com.runnect.runnect.data.dto.request.RequestPostPublicCourse
import com.runnect.runnect.data.dto.response.*
import com.runnect.runnect.data.dto.response.base.BaseResponse
import okhttp3.MultipartBody
Expand All @@ -25,7 +25,7 @@ interface CourseService {
@POST("/api/scrap")
suspend fun postCourseScrap(
@Body requestPostCourseScrap: RequestPostCourseScrap,
): BaseResponse<Unit>
): BaseResponse<ResponsePostScrap>

@GET("/api/public-course/search?")
suspend fun getCourseSearch(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,4 +48,10 @@ interface UserService {

@DELETE("api/user")
suspend fun deleteUser(): ResponseDeleteUser

// 유저 프로필 조회
@GET("/api/user/{profileUserId}")
suspend fun getUserProfile(
@Path("profileUserId") userId: Int,
): BaseResponse<ResponseGetUserProfile>
}
Original file line number Diff line number Diff line change
@@ -1,16 +1,17 @@
package com.runnect.runnect.data.source.remote

import com.runnect.runnect.data.service.CourseService
import com.runnect.runnect.data.dto.request.RequestPatchPublicCourse
import com.runnect.runnect.data.dto.request.RequestPostCourseScrap
import com.runnect.runnect.data.dto.request.RequestPostPublicCourse
import com.runnect.runnect.data.dto.request.RequestPostRunningHistory
import com.runnect.runnect.data.dto.request.RequestPutMyDrawCourse
import com.runnect.runnect.data.dto.request.RequestPatchPublicCourse
import com.runnect.runnect.data.dto.request.RequestPostPublicCourse
import com.runnect.runnect.data.dto.response.ResponseGetCourseDetail
import com.runnect.runnect.data.dto.response.ResponseGetDiscoverMarathon
import com.runnect.runnect.data.dto.response.ResponsePatchPublicCourse
import com.runnect.runnect.data.dto.response.ResponseGetDiscoverRecommend
import com.runnect.runnect.data.dto.response.ResponsePatchPublicCourse
import com.runnect.runnect.data.dto.response.ResponsePostScrap
import com.runnect.runnect.data.dto.response.base.BaseResponse
import com.runnect.runnect.data.service.CourseService
import okhttp3.MultipartBody
import okhttp3.RequestBody
import javax.inject.Inject
Expand All @@ -27,7 +28,7 @@ class RemoteCourseDataSource @Inject constructor(
): BaseResponse<ResponseGetDiscoverRecommend> =
courseService.getRecommendCourse(pageNo = pageNo, ordering = ordering)

suspend fun postCourseScrap(requestPostCourseScrap: RequestPostCourseScrap): BaseResponse<Unit> =
suspend fun postCourseScrap(requestPostCourseScrap: RequestPostCourseScrap): BaseResponse<ResponsePostScrap> =
courseService.postCourseScrap(requestPostCourseScrap)

suspend fun getCourseSearch(keyword: String) = courseService.getCourseSearch(keyword)
Expand Down
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
package com.runnect.runnect.data.source.remote

import com.runnect.runnect.data.service.UserService
import com.runnect.runnect.data.dto.request.RequestDeleteHistory
import com.runnect.runnect.data.dto.request.RequestDeleteUploadCourse
import com.runnect.runnect.data.dto.request.RequestPatchHistoryTitle
import com.runnect.runnect.data.dto.request.RequestPatchNickName
import com.runnect.runnect.data.dto.response.*
import com.runnect.runnect.data.dto.response.ResponseDeleteHistory
import com.runnect.runnect.data.dto.response.ResponseDeleteUploadCourse
import com.runnect.runnect.data.dto.response.ResponseDeleteUser
import com.runnect.runnect.data.dto.response.ResponseGetMyHistory
import com.runnect.runnect.data.dto.response.ResponseGetMyStamp
import com.runnect.runnect.data.dto.response.ResponseGetUser
import com.runnect.runnect.data.dto.response.ResponseGetUserProfile
import com.runnect.runnect.data.dto.response.ResponseGetUserUploadCourse
import com.runnect.runnect.data.dto.response.ResponsePatchHistoryTitle
import com.runnect.runnect.data.dto.response.ResponsePatchUserNickName
import com.runnect.runnect.data.dto.response.base.BaseResponse
import com.runnect.runnect.data.service.UserService
import javax.inject.Inject

class RemoteUserDataSource @Inject constructor(private val userService: UserService) {
Expand All @@ -16,7 +25,11 @@ class RemoteUserDataSource @Inject constructor(private val userService: UserServ

suspend fun getMyStamp(): ResponseGetMyStamp = userService.getMyStamp()
suspend fun getRecord(): ResponseGetMyHistory = userService.getRecord()
suspend fun getUserUploadCourse(): ResponseGetUserUploadCourse = userService.getUserUploadCourse()
suspend fun getUserUploadCourse(): ResponseGetUserUploadCourse =
userService.getUserUploadCourse()

suspend fun getUserProfile(userId: Int): BaseResponse<ResponseGetUserProfile> =
userService.getUserProfile(userId)

suspend fun putDeleteUploadCourse(
requestDeleteUploadCourse: RequestDeleteUploadCourse
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,4 +15,5 @@ data class CourseDetail(
val path: List<List<Double>>,
val distance: String,
val departure: String,
val userId: Int
)
26 changes: 26 additions & 0 deletions app/src/main/java/com/runnect/runnect/domain/entity/UserProfile.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.runnect.runnect.domain.entity

data class UserProfile(
val nickname: String,
val level: Int,
val levelPercent: Int,
val latestStamp: String,
val courseData: List<UserCourse>
)

data class UserCourse(
val publicCourseId: Int,
val courseId: Int,
val title: String,
val image: String,
val departure: Departure,
var scrapTF: Boolean,
)

data class Departure(
val region: String,
val city: String,
val town: String,
val detail: String?,
val name: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -10,20 +10,24 @@ import com.runnect.runnect.data.dto.response.ResponseGetMyDrawDetail
import com.runnect.runnect.data.dto.response.ResponsePostDiscoverUpload
import com.runnect.runnect.data.dto.response.ResponsePostMyDrawCourse
import com.runnect.runnect.data.dto.response.ResponsePostMyHistory
import com.runnect.runnect.data.dto.response.ResponsePostScrap
import com.runnect.runnect.data.dto.response.ResponsePutMyDrawCourse
import com.runnect.runnect.domain.entity.CourseDetail
import com.runnect.runnect.domain.entity.DiscoverMultiViewItem.MarathonCourse
import com.runnect.runnect.domain.entity.DiscoverSearchCourse
import com.runnect.runnect.domain.entity.DiscoverMultiViewItem.*
import com.runnect.runnect.domain.entity.RecommendCoursePagingData
import com.runnect.runnect.domain.entity.EditableCourseDetail
import com.runnect.runnect.domain.entity.RecommendCoursePagingData
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.Response

interface CourseRepository {
suspend fun getMarathonCourse(): Result<List<MarathonCourse>?>

suspend fun getRecommendCourse(pageNo: String, ordering: String): Result<RecommendCoursePagingData?>
suspend fun getRecommendCourse(
pageNo: String,
ordering: String
): Result<RecommendCoursePagingData?>

suspend fun getCourseSearch(keyword: String): Result<List<DiscoverSearchCourse>?>

Expand All @@ -40,12 +44,13 @@ interface CourseRepository {
suspend fun uploadCourse(
image: MultipartBody.Part, courseCreateRequestDto: RequestBody
): Response<ResponsePostMyDrawCourse>

suspend fun getCourseDetail(publicCourseId: Int): Result<CourseDetail?>

suspend fun patchPublicCourse(
publicCourseId: Int,
requestPatchPublicCourse: RequestPatchPublicCourse
): Result<EditableCourseDetail?>

suspend fun postCourseScrap(requestPostCourseScrap: RequestPostCourseScrap): Result<Unit?>
suspend fun postCourseScrap(requestPostCourseScrap: RequestPostCourseScrap): Result<ResponsePostScrap?>
}
Loading

0 comments on commit f676d4c

Please sign in to comment.