Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/attend UI #102

Merged
merged 6 commits into from
Feb 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 18 additions & 20 deletions data/src/main/java/com/kusitms/data/remote/api/KusitmsApi.kt
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package com.kusitms.data.remote.api

import com.kusitms.data.remote.entity.BaseResponse
import com.kusitms.data.remote.entity.request.CommentContentRequestBody
import com.kusitms.data.remote.entity.request.ReportCommentRequestBody
import com.kusitms.data.remote.entity.request.UpdatePasswordRequest
import com.kusitms.data.remote.entity.request.*
import com.kusitms.data.remote.entity.response.CheckPasswordPayload
import com.kusitms.data.remote.entity.response.FindPwCheckEmailResponse
import com.kusitms.data.remote.entity.response.LoginMemberProfileResponse
Expand All @@ -24,10 +22,9 @@ import retrofit2.http.*


interface KusitmsApi {
@GET("v1/auth/login/MEMBER")
@POST("v1/auth/login/MEMBER")
suspend fun loginMember(
@Query("email") email: String,
@Query("password") password: String,
@Body loginRequestBody: LoginRequestBody
): LoginResponse

@Multipart
Expand Down Expand Up @@ -132,39 +129,36 @@ interface KusitmsApi {
): BaseResponse<Int>


// SignInNonMember
// SignInNonMember (회원가입 가능 체크)
@FormUrlEncoded
@POST("v1/member/check/register")
suspend fun signInRequestCheck(
@Field("email") email: String,
@Field("password") password: String,
@Body loginRequestBody: LoginRequestBody
): SignInRequestResponse

@FormUrlEncoded
@FormUrlEncoded //회원가입
@POST("v1/member/register")
suspend fun signInRequest(
@Field("email") email: String,
@Field("password") password: String,
@Body loginRequestBody: LoginRequestBody
): BaseResponse<Unit>

// FindPw
@FormUrlEncoded
@POST("v1/member/email")
@POST("v1/member/email") //이메일 존재 확인
suspend fun verifyEmailCheck(
@Field("email") email: String,
@Body checkEmailRequestBody: CheckEmailRequestBody
): FindPwCheckEmailResponse

@FormUrlEncoded
@POST("v1/member/verify")
suspend fun sendCode(
@Field("email") email: String,
@Body checkEmailRequestBody: CheckEmailRequestBody
): BaseResponse<Unit>

@FormUrlEncoded
@POST("v1/member/verify/code")
@POST("v1/member/verify/code") //이메일 코드 검증
suspend fun verifyCode(
@Field("email") email: String,
@Field("code") code: String,
@Body emailVerifyRequestBody: EmailVerifyRequestBody
): FindPwCodeVerifyResponse

@PUT("v1/member/password/unauthenticated")
Expand All @@ -176,7 +170,7 @@ interface KusitmsApi {

@POST("v1/member/password")
suspend fun checkPassword(
@Query("password") password: String,
@Body passwordRequestBody: PasswordRequestBody
): BaseResponse<CheckPasswordPayload>

@PUT("v1/member/password")
Expand Down Expand Up @@ -207,9 +201,13 @@ interface KusitmsApi {
@GET("v1/attend/info")
suspend fun getAttendInfo(): BaseResponse<AttendInfoPayload>


//커리큘럼 출석 조회
@GET("v1/attend/lists")
suspend fun getAttendCurrentList(): BaseResponse<List<AttendCurrentPayLoad>>

//출석 정보 조회
@GET("v1/attend")
suspend fun getAttendScore(): BaseResponse<AttendPayload>


}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class AuthTokenInterceptor @Inject constructor(
var response = chain.proceed(request)

// 토큰 만료 감지 및 처리
if (response.code == 500 && response.code == 401) {
if (response.code == 500 || response.code == 401) {
// 토큰 매니저 인스턴스를 가져오고 토큰 갱신을 시도
runBlocking {
launch(Dispatchers.IO) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
package com.kusitms.data.remote.entity.request

import com.kusitms.domain.model.login.LoginEmailModel
import com.kusitms.domain.model.login.LoginEmailVerifyModel
import com.kusitms.domain.model.login.LoginMemberModel
import com.kusitms.domain.model.login.LoginPasswordModel

data class LoginRequestBody(
val email: String,
val password: String
)

fun mapToLoginRequestBody(model: LoginMemberModel): LoginRequestBody {
return LoginRequestBody(
email = model.email,
password = model.password
)
}

data class CheckEmailRequestBody(
val email: String
)

fun mapToEmailRequestBody(model: LoginEmailModel): CheckEmailRequestBody {
return CheckEmailRequestBody(
email = model.email
)
}

data class EmailVerifyRequestBody(
val email: String,
val code : String
)


fun mapToEmailVerifyBody(model: LoginEmailVerifyModel): EmailVerifyRequestBody {
return EmailVerifyRequestBody(
email = model.email,
code = model.code
)
}

data class PasswordRequestBody(
val password: String
)

fun mapToPasswordRequestBody(model: LoginPasswordModel): PasswordRequestBody {
return PasswordRequestBody(
password = model.password
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,15 @@ data class AttendInfoPayload(
val curriculumId: Int,
val curriculumName: String,
val isAttended: Boolean,
val date: String
val date: String,
val time: String
)

fun AttendInfoPayload.toModel() =
AttendInfoModel(
curriculumId = curriculumId ?: 0,
curriculumName = curriculumName ?: "",
isAttended = isAttended ?: false,
date = date ?: "2월 17일"
date = date ?: "2월 17일",
time = time ?: "오후 02:00"
)
Original file line number Diff line number Diff line change
Expand Up @@ -2,16 +2,20 @@ package com.kusitms.data.repository

import com.kusitms.data.remote.api.KusitmsApi
import com.kusitms.data.remote.entity.request.UpdatePasswordRequest
import com.kusitms.data.remote.entity.request.mapToPasswordRequestBody
import com.kusitms.domain.model.login.LoginPasswordModel
import com.kusitms.domain.repository.ChangePwRepository
import javax.inject.Inject

class ChangePwRepositoryImpl@Inject constructor(
private val kusitmsApi: KusitmsApi
): ChangePwRepository {

override suspend fun checkPassword(password : String): Result<Boolean> {
override suspend fun checkPassword(password: String): Result<Boolean> {
return try {
val response = kusitmsApi.checkPassword(password)
val model = LoginPasswordModel(password)
val request = mapToPasswordRequestBody(model)
val response = kusitmsApi.checkPassword(request)
if (response.result.code == 200 && response.payload != null) {
Result.success(response.payload.isCorrect)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,14 @@ package com.kusitms.data.repository

import com.kusitms.data.remote.api.KusitmsApi
import com.kusitms.data.remote.entity.request.UpdatePasswordRequest
import com.kusitms.data.remote.entity.request.mapToEmailRequestBody
import com.kusitms.data.remote.entity.request.mapToEmailVerifyBody
import com.kusitms.data.remote.entity.response.notice.toModel
import com.kusitms.data.remote.entity.response.toModel
import com.kusitms.domain.model.findpw.FindPwCheckEmailModel
import com.kusitms.domain.model.findpw.FindPwCodeVerifyModel
import com.kusitms.domain.model.login.LoginEmailModel
import com.kusitms.domain.model.login.LoginEmailVerifyModel
import com.kusitms.domain.repository.FindPwRepository
import javax.inject.Inject

Expand All @@ -17,7 +21,10 @@ class FindPwRepositoryImpl@Inject constructor(
email: String
): Result<FindPwCheckEmailModel> {
return try {
val response = kusitmsApi.verifyEmailCheck(email)
val model = LoginEmailModel(email)
val request = mapToEmailRequestBody(model)
val response = kusitmsApi.verifyEmailCheck(request)

if (response.result.code == 200 && response.payload != null) {
Result.success(response.payload.toModel())
} else {
Expand All @@ -30,7 +37,10 @@ class FindPwRepositoryImpl@Inject constructor(

override suspend fun SendCode(email: String): Result<Unit> {
return try {
val response = kusitmsApi.sendCode(email)
val model = LoginEmailModel(email)
val request = mapToEmailRequestBody(model)
val response = kusitmsApi.sendCode(request)

if(response.result.code == 200) {
Result.success(Unit)
} else {
Expand All @@ -43,7 +53,10 @@ class FindPwRepositoryImpl@Inject constructor(

override suspend fun VerifyCode(email: String, code: String): Result<FindPwCodeVerifyModel> {
return try {
val response = kusitmsApi.verifyCode(email,code)
val model = LoginEmailVerifyModel(email, code)
val request = mapToEmailVerifyBody(model)
val response = kusitmsApi.verifyCode(request)

if(response.result.code == 200) {
Result.success(response.payload.toModel())
} else {
Expand Down Expand Up @@ -72,6 +85,4 @@ class FindPwRepositoryImpl@Inject constructor(
Result.failure(e)
}
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -121,4 +121,17 @@ class HomeRepositoryImpl @Inject constructor(
Result.failure(e)
}
}

override suspend fun getAttendScore(): Result<AttendModel> {
return try {
val response = kusitmsApi.getAttendScore()
if(response.result.code == 200) {
Result.success(response.payload.toModel())
} else {
Result.failure(RuntimeException("출석 정보 조회 실패: ${response.result.message}"))
}
} catch (e: Exception) {
Result.failure(e)
}
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,11 @@
package com.kusitms.data.repository

import android.util.Log
import com.kusitms.data.local.AuthDataStore
import com.kusitms.data.remote.api.KusitmsApi
import com.kusitms.data.remote.entity.request.LoginRequestBody
import com.kusitms.data.remote.entity.request.mapToLoginRequestBody
import com.kusitms.domain.model.login.LoginMemberModel
import com.kusitms.domain.repository.LoginRepository
import javax.inject.Inject

Expand All @@ -14,8 +18,11 @@ class LoginRepositoryImpl @Inject constructor(
password: String
): Result<Unit> {
return try {
val response = kusitmsApi.loginMember(email, password)
val model = LoginMemberModel(email,password)
val request = mapToLoginRequestBody(model)
val response = kusitmsApi.loginMember(request)
if (response.result.code == 200 && response.payload != null) {
Log.d("auth", response.payload.accessToken.toString())
AuthDataStore().authToken = response.payload.accessToken
AuthDataStore().refreshToken = response.payload.refreshToken
Result.success(Unit)
Expand All @@ -26,7 +33,4 @@ class LoginRepositoryImpl @Inject constructor(
Result.failure(e)
}
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,11 @@ import android.util.Log
import com.google.gson.Gson
import com.kusitms.data.local.AuthDataStore
import com.kusitms.data.remote.api.KusitmsApi
import com.kusitms.data.remote.entity.request.mapToLoginRequestBody
import com.kusitms.data.remote.entity.request.toBody
import com.kusitms.data.remote.entity.response.toModel
import com.kusitms.domain.model.SignInProfile
import com.kusitms.domain.model.login.LoginMemberModel
import com.kusitms.domain.model.login.LoginMemberProfile
import com.kusitms.domain.model.signin.SignInRequestCheckModel
import com.kusitms.domain.repository.SignInRepository
Expand Down Expand Up @@ -47,7 +49,9 @@ class SignInRepositoryImpl @Inject constructor(
password: String
): Result<SignInRequestCheckModel> {
return try {
val response = kusitmsApi.signInRequestCheck(email, password)
val model = LoginMemberModel(email, password)
val request = mapToLoginRequestBody(model)
val response = kusitmsApi.signInRequestCheck(request)
if(response.payload == null) {
Result.failure(RuntimeException("올바른 데이터를 받지 못했습니다."))
} else {
Expand All @@ -63,7 +67,9 @@ class SignInRepositoryImpl @Inject constructor(
password: String
): Result<Unit> {
return try {
val response = kusitmsApi.signInRequest(email, password)
val model = LoginMemberModel(email, password)
val request = mapToLoginRequestBody(model)
val response = kusitmsApi.signInRequest(request)
if(response.result == null) {
Result.failure(RuntimeException("올바른 데이터를 받지 못했습니다."))
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,5 +20,6 @@ data class AttendInfoModel(
val curriculumId: Int,
val curriculumName: String,
val isAttended: Boolean,
val date: String
val date: String,
val time:String
)
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,22 @@ data class LoginMemberProfile(
val period: String?,
val phoneNumber: String,
val memberDetailExist: Boolean
)

data class LoginMemberModel(
val email:String,
val password: String
)

data class LoginEmailModel(
val email:String
)

data class LoginPasswordModel(
val password: String
)

data class LoginEmailVerifyModel(
val email: String,
val code : String
)
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,5 @@ interface HomeRepository {
): Result<List<ProfileModel>>
suspend fun getAttendCurrentList(): Result<List<AttendCurrentModel>>
suspend fun getAttendInfo(): Result<AttendInfoModel>
suspend fun getAttendScore(): Result<AttendModel>
}
Loading