Skip to content

Commit

Permalink
Merge pull request #106 from SOPT-all/feat-#99-home-api
Browse files Browse the repository at this point in the history
[Feat/#99] "홈 화면" API를 연결합니다
  • Loading branch information
wjdrjs00 authored Jan 23, 2025
2 parents 35419ed + dc04de4 commit cb71271
Show file tree
Hide file tree
Showing 49 changed files with 853 additions and 60 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.sopt.gongbaek.data.local.datasource

interface LectureTimetableLocalDataSource {
fun getTimetable(): Map<String, List<Int>>
fun setTimetable(lectureTimetable: Map<String, List<Int>>)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.sopt.gongbaek.data.local.datasourceimpl

import android.content.SharedPreferences
import com.sopt.gongbaek.data.local.datasource.LectureTimetableLocalDataSource
import com.sopt.gongbaek.di.qualifier.LectureTimetablePrefs
import kotlinx.serialization.SerializationException
import kotlinx.serialization.encodeToString
import kotlinx.serialization.json.Json
import javax.inject.Inject

class LectureTimetableLocalDataSourceImpl @Inject constructor(
@LectureTimetablePrefs private val sharedPreferences: SharedPreferences
) : LectureTimetableLocalDataSource {

override fun setTimetable(lectureTimetable: Map<String, List<Int>>) {
val jsonString = Json.encodeToString(lectureTimetable)
sharedPreferences.edit().putString(KEY, jsonString).apply()
}

override fun getTimetable(): Map<String, List<Int>> {
val jsonString = sharedPreferences.getString(KEY, null) ?: return emptyMap()
return try {
Json.decodeFromString(jsonString)
} catch (e: SerializationException) {
emptyMap()
}
}

companion object {
private const val KEY = "lecture_timetable"
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,11 @@ package com.sopt.gongbaek.data.local.datasourceimpl

import android.content.SharedPreferences
import com.sopt.gongbaek.data.local.datasource.TokenLocalDataSource
import com.sopt.gongbaek.di.qualifier.TokenPrefs
import javax.inject.Inject

class TokenLocalDataSourceImpl @Inject constructor(
private val sharedPreferences: SharedPreferences
@TokenPrefs private val sharedPreferences: SharedPreferences
) : TokenLocalDataSource {
override var accessToken: String
get() = sharedPreferences.getString(ACCESS_TOKEN, "eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiIxIiwiZXhwIjoxODIzNDQyODE0LCJ1c2VySWQiOjF9.piiJ8o2pXY-_A6ZjvxQ7MOyfnYOsnM-FQwMmC3m4qWIzK0wlxBb6tEfT3HzLuIU1SoZTveGeCEq7g6JABYmx2A") ?: ""
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package com.sopt.gongbaek.data.mapper.todomain

import com.sopt.gongbaek.data.remote.dto.response.NearestGroupResponseDto
import com.sopt.gongbaek.domain.model.NearestGroup

fun NearestGroupResponseDto.toDomain() = NearestGroup(
groupId = groupId,
category = category,
groupType = groupType,
groupTitle = groupTitle,
weekDay = weekDay ?: "",
weekDate = weekDate ?: "",
currentPeopleCount = currentPeopleCount,
maxPeopleCount = maxPeopleCount,
startTime = startTime,
endTime = endTime,
location = location
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.sopt.gongbaek.data.mapper.todomain

import com.sopt.gongbaek.data.remote.dto.response.RecommendGroupInfoResponseDto
import com.sopt.gongbaek.domain.model.RecommendGroupInfo

fun RecommendGroupInfoResponseDto.toDomain() =
RecommendGroupInfo(
groupId = groupId,
category = category,
coverImg = coverImg,
profileImg = profileImg,
nickname = nickname,
groupType = groupType,
groupTitle = groupTitle,
weekDay = weekDay ?: "",
weekDate = weekDate ?: "",
startTime = startTime,
endTime = endTime,
location = location
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.sopt.gongbaek.data.mapper.todomain

import com.sopt.gongbaek.data.remote.dto.response.UserProfileResponseDto
import com.sopt.gongbaek.domain.model.UserProfile

fun UserProfileResponseDto.toDomain(): UserProfile =
UserProfile(
nickname = nickname,
schoolName = schoolName
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package com.sopt.gongbaek.data.mapper.todomain

import com.sopt.gongbaek.data.remote.dto.response.UserTimeTableResponseDto
import com.sopt.gongbaek.domain.model.UserLectureTimeTable

fun UserTimeTableResponseDto.toDomain(): List<UserLectureTimeTable> =
timeTable.map { lectureTimeTable ->
UserLectureTimeTable(
idx = lectureTimeTable.idx,
weekDay = lectureTimeTable.weekDay,
startTime = lectureTimeTable.startTime,
endTime = lectureTimeTable.endTime
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,12 @@ import com.sopt.gongbaek.data.remote.dto.base.ApiResponse
import com.sopt.gongbaek.data.remote.dto.base.NullableApiResponse
import com.sopt.gongbaek.data.remote.dto.request.RegisterUserInfoRequestDto
import com.sopt.gongbaek.data.remote.dto.response.RegisterUserInfoResponseDto
import com.sopt.gongbaek.data.remote.dto.response.UserProfileResponseDto
import com.sopt.gongbaek.data.remote.dto.response.UserTimeTableResponseDto

interface AuthRemoteDataSource {
suspend fun registerUserInfo(registerUserInfoRequestDto: RegisterUserInfoRequestDto): ApiResponse<RegisterUserInfoResponseDto>
suspend fun validateNickname(nickname: String): NullableApiResponse<Unit>
suspend fun getUserProfile(): ApiResponse<UserProfileResponseDto>
suspend fun getUserLectureTimeTable(): ApiResponse<UserTimeTableResponseDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,19 @@ import com.sopt.gongbaek.data.remote.dto.response.GroupListGroupResponseDto
import com.sopt.gongbaek.data.remote.dto.response.GroupMembersResponseDto
import com.sopt.gongbaek.data.remote.dto.response.GroupRegisterResponseDto
import com.sopt.gongbaek.data.remote.dto.response.MyGroupsResponseDto
import com.sopt.gongbaek.data.remote.dto.response.NearestGroupResponseDto
import com.sopt.gongbaek.data.remote.dto.response.RecommendGroupInfoResponseDto

interface GroupRemoteDataSource {
suspend fun getMyGroups(category: String, status: Boolean): ApiResponse<MyGroupsResponseDto>
suspend fun getGroupDetail(groupId: Int, groupType: String): ApiResponse<GroupDetailResponseDto>
suspend fun getGroupHost(groupId: Int, groupType: String): ApiResponse<GroupHostResponseDto>
suspend fun applyGroup(applyGroupRequestDto: ApplyGroupRequestDto): NullableApiResponse<Unit>
suspend fun getGroups(category: String?): ApiResponse<List<GroupListGroupResponseDto>>

suspend fun getNearestGroup(): ApiResponse<NearestGroupResponseDto>

suspend fun getLatestGroup(groupType: String): ApiResponse<List<RecommendGroupInfoResponseDto>>
suspend fun postGroup(groupRegisterRequestDto: GroupRegisterRequestDto): ApiResponse<GroupRegisterResponseDto>
suspend fun getGroupMembers(groupId: Int, groupType: String): ApiResponse<GroupMembersResponseDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@ import com.sopt.gongbaek.data.remote.dto.base.ApiResponse
import com.sopt.gongbaek.data.remote.dto.base.NullableApiResponse
import com.sopt.gongbaek.data.remote.dto.request.RegisterUserInfoRequestDto
import com.sopt.gongbaek.data.remote.dto.response.RegisterUserInfoResponseDto
import com.sopt.gongbaek.data.remote.dto.response.UserProfileResponseDto
import com.sopt.gongbaek.data.remote.dto.response.UserTimeTableResponseDto
import com.sopt.gongbaek.data.remote.service.AuthService
import javax.inject.Inject

Expand All @@ -17,4 +19,10 @@ class AuthRemoteDatasourceImpl @Inject constructor(

override suspend fun validateNickname(nickname: String): NullableApiResponse<Unit> =
authService.validateNickname(nickname)

override suspend fun getUserProfile(): ApiResponse<UserProfileResponseDto> =
authService.getUserProfile()

override suspend fun getUserLectureTimeTable(): ApiResponse<UserTimeTableResponseDto> =
authService.getUserLectureTimeTable()
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import com.sopt.gongbaek.data.remote.dto.response.GroupListGroupResponseDto
import com.sopt.gongbaek.data.remote.dto.response.GroupMembersResponseDto
import com.sopt.gongbaek.data.remote.dto.response.GroupRegisterResponseDto
import com.sopt.gongbaek.data.remote.dto.response.MyGroupsResponseDto
import com.sopt.gongbaek.data.remote.dto.response.NearestGroupResponseDto
import com.sopt.gongbaek.data.remote.dto.response.RecommendGroupInfoResponseDto
import com.sopt.gongbaek.data.remote.service.GroupService
import javax.inject.Inject

Expand All @@ -32,6 +34,12 @@ class GroupRemoteDataSourceImpl @Inject constructor(
override suspend fun getGroups(category: String?): ApiResponse<List<GroupListGroupResponseDto>> =
groupService.getGroups(category = category)

override suspend fun getNearestGroup(): ApiResponse<NearestGroupResponseDto> =
groupService.getNearestGroup()

override suspend fun getLatestGroup(groupType: String): ApiResponse<List<RecommendGroupInfoResponseDto>> =
groupService.getLatestGroup(groupType = groupType)

override suspend fun postGroup(groupRegisterRequestDto: GroupRegisterRequestDto): ApiResponse<GroupRegisterResponseDto> =
groupService.postGroup(groupRegisterRequestDto = groupRegisterRequestDto)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ data class RegisterTimeTableRequestDto(
@SerialName("weekDay")
val weekDay: String,
@SerialName("startTime")
val startTime: Float,
val startTime: Double,
@SerialName("endTime")
val endTime: Float
val endTime: Double
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.sopt.gongbaek.data.remote.dto.response

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

@Serializable
data class UserTimeTableResponseDto(
@SerialName("timeTable")
val timeTable: List<LectureTimeTable>
)

@Serializable
data class LectureTimeTable(
@SerialName("idx")
val idx: Int,
@SerialName("weekDay")
val weekDay: String,
@SerialName("startTime")
val startTime: Double,
@SerialName("endTime")
val endTime: Double
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.sopt.gongbaek.data.remote.dto.response

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

@Serializable
data class NearestGroupResponseDto(
@SerialName("groupId")
val groupId: Int,
@SerialName("category")
val category: String,
@SerialName("groupType")
val groupType: String,
@SerialName("groupTitle")
val groupTitle: String,
@SerialName("weekDay")
val weekDay: String?,
@SerialName("weekDate")
val weekDate: String?,
@SerialName("currentPeopleCount")
val currentPeopleCount: Int,
@SerialName("maxPeopleCount")
val maxPeopleCount: Int,
@SerialName("startTime")
val startTime: Double,
@SerialName("endTime")
val endTime: Double,
@SerialName("location")
val location: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.sopt.gongbaek.data.remote.dto.response

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

@Serializable
data class RecommendGroupInfoResponseDto(
@SerialName("groupId")
val groupId: Int,
@SerialName("category")
val category: String,
@SerialName("coverImg")
val coverImg: Int,
@SerialName("profileImg")
val profileImg: Int,
@SerialName("nickname")
val nickname: String,
@SerialName("groupType")
val groupType: String,
@SerialName("groupTitle")
val groupTitle: String,
@SerialName("weekDay")
val weekDay: String,
@SerialName("weekDate")
val weekDate: String?,
@SerialName("startTime")
val startTime: Double,
@SerialName("endTime")
val endTime: Double,
@SerialName("location")
val location: String
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.sopt.gongbaek.data.remote.dto.response

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

@Serializable
data class UserProfileResponseDto(
@SerialName("nickname")
val nickname: String,
@SerialName("schoolName")
val schoolName: String
)
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,10 @@ import com.sopt.gongbaek.data.remote.dto.base.ApiResponse
import com.sopt.gongbaek.data.remote.dto.base.NullableApiResponse
import com.sopt.gongbaek.data.remote.dto.request.RegisterUserInfoRequestDto
import com.sopt.gongbaek.data.remote.dto.response.RegisterUserInfoResponseDto
import com.sopt.gongbaek.data.remote.dto.response.UserProfileResponseDto
import com.sopt.gongbaek.data.remote.dto.response.UserTimeTableResponseDto
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
import retrofit2.http.Query

Expand All @@ -19,4 +22,10 @@ interface AuthService {
suspend fun validateNickname(
@Query("nickname") nickname: String
): NullableApiResponse<Unit>

@GET("/api/v1/user/home/profile")
suspend fun getUserProfile(): ApiResponse<UserProfileResponseDto>

@GET("/api/v1/my/timeTable")
suspend fun getUserLectureTimeTable(): ApiResponse<UserTimeTableResponseDto>
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ import com.sopt.gongbaek.data.remote.dto.response.GroupListGroupResponseDto
import com.sopt.gongbaek.data.remote.dto.response.GroupMembersResponseDto
import com.sopt.gongbaek.data.remote.dto.response.GroupRegisterResponseDto
import com.sopt.gongbaek.data.remote.dto.response.MyGroupsResponseDto
import com.sopt.gongbaek.data.remote.dto.response.NearestGroupResponseDto
import com.sopt.gongbaek.data.remote.dto.response.RecommendGroupInfoResponseDto
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.POST
Expand Down Expand Up @@ -44,6 +46,14 @@ interface GroupService {
@Query("category") category: String? = null
): ApiResponse<List<GroupListGroupResponseDto>>

@GET("/api/v1/group/my/participation")
suspend fun getNearestGroup(): ApiResponse<NearestGroupResponseDto>

@GET("/api/v1/group/latest")
suspend fun getLatestGroup(
@Query("groupType") groupType: String
): ApiResponse<List<RecommendGroupInfoResponseDto>>

@POST("/api/v1/gongbaek")
suspend fun postGroup(
@Body groupRegisterRequestDto: GroupRegisterRequestDto
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import com.sopt.gongbaek.data.remote.util.handleApiResponse
import com.sopt.gongbaek.data.remote.util.handleNullableApiResponse
import com.sopt.gongbaek.domain.model.UserAuth
import com.sopt.gongbaek.domain.model.UserInfo
import com.sopt.gongbaek.domain.model.UserProfile
import com.sopt.gongbaek.domain.repository.AuthRepository
import javax.inject.Inject

Expand All @@ -25,4 +26,14 @@ class AuthRepositoryImpl @Inject constructor(
runCatching {
authRemoteDatasource.validateNickname(nickname = nickname).handleNullableApiResponse().exceptionOrNull()
}

override suspend fun getUserProfile(): Result<UserProfile> =
runCatching {
authRemoteDatasource.getUserProfile().handleApiResponse().getOrThrow().toDomain()
}

override suspend fun getUserLectureTimeTable() =
runCatching {
authRemoteDatasource.getUserLectureTimeTable().handleApiResponse().getOrThrow().toDomain()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,8 @@ import com.sopt.gongbaek.data.remote.util.handleApiResponse
import com.sopt.gongbaek.data.remote.util.handleNullableApiResponse
import com.sopt.gongbaek.domain.model.GroupHost
import com.sopt.gongbaek.domain.model.GroupInfo
import com.sopt.gongbaek.domain.model.NearestGroup
import com.sopt.gongbaek.domain.model.RecommendGroupInfo
import com.sopt.gongbaek.domain.model.GroupMembers
import com.sopt.gongbaek.domain.model.GroupRegisterInfo
import com.sopt.gongbaek.domain.repository.GroupRepository
Expand Down Expand Up @@ -45,6 +47,16 @@ class GroupRepositoryImpl @Inject constructor(
}
}

override suspend fun getNearestGroup(): Result<NearestGroup> =
runCatching {
groupDataSource.getNearestGroup().handleApiResponse().getOrThrow().toDomain()
}

override suspend fun getLatestGroup(groupType: String): Result<List<RecommendGroupInfo>> =
runCatching {
groupDataSource.getLatestGroup(groupType = groupType).handleApiResponse().getOrThrow().map { group -> group.toDomain() }
}

override suspend fun postGroup(groupRegisterInfo: GroupRegisterInfo): Result<GroupRegisterResponseDto> {
return runCatching {
groupDataSource.postGroup(
Expand Down
Loading

0 comments on commit cb71271

Please sign in to comment.