Skip to content

Commit

Permalink
[Feat] #18 getinfo domain과 data 영역 추가 및 수정
Browse files Browse the repository at this point in the history
  • Loading branch information
cacaocoffee committed Jun 14, 2024
1 parent f4bb9c1 commit 32a8c17
Show file tree
Hide file tree
Showing 7 changed files with 37 additions and 18 deletions.
1 change: 0 additions & 1 deletion app/src/main/java/com/sopt/now/data/api/ApiFactory.kt
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,4 @@ object ApiFactory {

object ServicePool {
val authService: AuthService by lazy { create<AuthService>() }
val infoService: InfoService by lazy { create<InfoService>() }
}
8 changes: 8 additions & 0 deletions app/src/main/java/com/sopt/now/data/api/AuthService.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,11 @@ package com.sopt.now.data.api
import com.sopt.now.data.dto.request.RequestLoginDto
import com.sopt.now.data.dto.request.RequestSignUpDto
import com.sopt.now.data.dto.response.BaseResponse
import com.sopt.now.data.dto.response.ResponseInfoDto
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.POST

interface AuthService {
Expand All @@ -18,4 +21,9 @@ interface AuthService {
suspend fun login(
@Body request: RequestLoginDto,
): Response<BaseResponse<Unit>>

@GET("/member/info")
suspend fun getUserInfo(
@Header("memberid") userId: String,
): Response<ResponseInfoDto>
}
13 changes: 0 additions & 13 deletions app/src/main/java/com/sopt/now/data/api/InfoService.kt

This file was deleted.

8 changes: 8 additions & 0 deletions app/src/main/java/com/sopt/now/data/dto/Mapper.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.sopt.now.data.dto
import com.sopt.now.data.dto.request.RequestLoginDto
import com.sopt.now.data.dto.request.RequestSignUpDto
import com.sopt.now.data.dto.response.BaseResponse
import com.sopt.now.data.dto.response.ResponseInfoDto
import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.domain.entity.BaseResponseEntity

Expand All @@ -25,3 +26,10 @@ internal fun BaseResponse<Unit>.toBaseResponseEntity(): BaseResponseEntity =
code = this.code,
message = this.message
)

internal fun ResponseInfoDto.UserData.toUserEntity(): UserEntity = UserEntity(
authenticationId = authenticationId,
password = "",
nickname = nickname,
phone = phone
)
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.sopt.now.data.dto.response.BaseResponse
import com.sopt.now.data.dto.toBaseResponseEntity
import com.sopt.now.data.dto.toRequestLoginDto
import com.sopt.now.data.dto.toRequestSignUpDto
import com.sopt.now.data.dto.toUserEntity
import com.sopt.now.data.repositoryimpl.extension.getResponseErrorMessage
import com.sopt.now.data.repositoryimpl.extension.handleThrowable
import com.sopt.now.domain.entity.ApiError
Expand All @@ -16,11 +17,11 @@ import retrofit2.Response
class AuthRepositoryImpl(private val authService: AuthService) : AuthRepository {
override suspend fun login(authData: UserEntity): Result<Int?> =
runCatching {
val response: Response<BaseResponse<Unit>> = authService.login(authData.toRequestLoginDto())
val response: Response<BaseResponse<Unit>> =
authService.login(authData.toRequestLoginDto())
if (response.isSuccessful) {
response.headers()["location"]?.toInt()
}
else{
} else {
throw ApiError(response.getResponseErrorMessage())
}
}
Expand All @@ -33,5 +34,11 @@ class AuthRepositoryImpl(private val authService: AuthService) : AuthRepository
}
}

override suspend fun getMemberInfo(userid: String): Result<UserEntity> =
runCatching {
authService.getUserInfo(userid).body()?.data?.toUserEntity()
?: throw Exception("data is null")
}


}
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
package com.sopt.now.domain.repository

import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.domain.entity.BaseResponseEntity
import com.sopt.now.domain.entity.UserEntity

interface AuthRepository {
suspend fun login(authData: UserEntity): Result<Int?>
suspend fun signUp(authData: UserEntity): Result<BaseResponseEntity>
suspend fun getMemberInfo(userid:String): Result<UserEntity>
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.sopt.now.domain.usecase

import com.sopt.now.domain.entity.UserEntity
import com.sopt.now.domain.repository.AuthRepository

class GetUserInfoUseCase(private val authRepository: AuthRepository) {
suspend operator fun invoke(userid: String): Result<UserEntity> =
authRepository.getMemberInfo(userid)
}

0 comments on commit 32a8c17

Please sign in to comment.