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

Refact/modify token operation #77

Open
wants to merge 13 commits into
base: Refact/modify_token_operation
Choose a base branch
from
Open
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
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package kids.baba.mobile.core.constant
object PrefsKey {
const val ACCESS_TOKEN_KEY = "ACCESS_TOKEN_KEY"
const val REFRESH_TOKEN_KEY = "REFRESH_TOKEN_KEY"
const val SIGN_TOKEN_KEY = "SIGN_TOKEN_KEY"
const val MEMBER_KEY = "MEMBER_KEY"
const val BABY_KEY = "BABY_KEY"
const val BABY_GROUP_TITLE_KEY = "BABY_GROUP_TITLE_KEY"
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package kids.baba.mobile.core.error

import java.lang.Exception

class InvalidAccessTokenException: Exception()
20 changes: 0 additions & 20 deletions app/src/main/java/kids/baba/mobile/data/api/AlbumApi.kt
Original file line number Diff line number Diff line change
@@ -1,34 +1,23 @@
package kids.baba.mobile.data.api

import kids.baba.mobile.core.constant.PrefsKey
import kids.baba.mobile.core.utils.EncryptedPrefs
import kids.baba.mobile.domain.model.*
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.POST
import retrofit2.http.Path
import retrofit2.http.Query
import okhttp3.MultipartBody
import okhttp3.RequestBody
import retrofit2.Response
import retrofit2.http.*

interface AlbumApi {


//성장 앨범 메인
@GET("baby/{babyId}/album")
suspend fun getAlbum(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Path("babyId") id: String,
@Query("year") year: Int,
@Query("month") month: Int
): Response<AlbumResponse>

@GET("baby/{babyId}/album/{albumId}")
suspend fun gatOneAlbum(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Path("babyId") babyId: String,
@Path("contentId") contentId: Int
): Response<Album>
Expand All @@ -37,60 +26,51 @@ interface AlbumApi {
@Multipart
@POST("baby/{babyId}/album")
suspend fun postAlbum(
@Header("Authorization")
accessToken: String,
@Path("babyId") id: String,
@Part photo: MultipartBody.Part,
@PartMap bodyDataHashMap: HashMap<String, RequestBody>
): Response<PostAlbumResponse>

@DELETE("baby/{babyId}/album/{contentId}")
suspend fun deleteAlbum(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Path("babyId") babyId: String,
@Path("contentId") contentId: Int
): Response<Unit>

@POST("baby/{babyId}/album/{contentId}/like")
suspend fun likeAlbum(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Path("babyId") id: String,
@Path("contentId") contentId: Int
): Response<LikeResponse>

@POST("baby/{babyId}/album/{contentId}/comment")
suspend fun addComment(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Path("babyId") id: String,
@Path("contentId") contentId: Int,
@Body commentInput: CommentInput
): Response<Unit>

@DELETE("baby/{babyId}/album/{contentId}/comment/{commentId}")
suspend fun deleteComment(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Path("babyId") id: String,
@Path("contentId") contentId: Int,
@Path("commentId") commentId: String
): Response<Unit>

@GET("baby/{babyId}/album/{contentId}/comments")
suspend fun getComments(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Path("contentId") contentId: Int,
@Path("babyId") id: String
): Response<CommentResponse>

@GET("baby/{babyId}/album/{contentId}/likes")
suspend fun getLikeDetail(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Path("contentId") contentId: Int,
@Path("babyId") id: String
): Response<LikeDetailResponse>

@GET("baby/{babyId}/album/all")
suspend fun getAllAlbum(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Path("babyId") id: String
): Response<AlbumResponse>

Expand Down
6 changes: 1 addition & 5 deletions app/src/main/java/kids/baba/mobile/data/api/BabyApi.kt
Original file line number Diff line number Diff line change
@@ -1,12 +1,9 @@
package kids.baba.mobile.data.api

import kids.baba.mobile.core.constant.PrefsKey
import kids.baba.mobile.core.utils.EncryptedPrefs
import kids.baba.mobile.domain.model.BabiesInfoResponse
import kids.baba.mobile.domain.model.BabyResponse
import retrofit2.Response
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.Query

interface BabyApi {
Expand All @@ -18,7 +15,6 @@ interface BabyApi {

//아기 리스트 가져오기
@GET("baby")
suspend fun getBaby(@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY)): Response<BabyResponse>

suspend fun getBaby(): Response<BabyResponse>

}
24 changes: 1 addition & 23 deletions app/src/main/java/kids/baba/mobile/data/api/MemberApi.kt
Original file line number Diff line number Diff line change
@@ -1,32 +1,10 @@
package kids.baba.mobile.data.api

import kids.baba.mobile.domain.model.MemberModel
import kids.baba.mobile.domain.model.SignUpRequestWithBabiesInfo
import kids.baba.mobile.domain.model.SignUpRequestWithInviteCode
import kids.baba.mobile.domain.model.TokenResponse
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.POST

interface MemberApi {
@GET("members")
suspend fun getMe(@Header("Authorization") accessToken: String): Response<MemberModel>

@POST("members/baby")
suspend fun signUpWithBabiesInfo(
@Header("Authorization")
signToken: String,
@Body
signupRequestWithBabiesInfo: SignUpRequestWithBabiesInfo
): Response<TokenResponse>

@POST("members/baby/invite-code")
suspend fun signUpWithInviteCode(
@Header("Authorization")
signToken: String,
@Body
signUpRequestWithInviteCode: SignUpRequestWithInviteCode
): Response<TokenResponse>
suspend fun getMe(): Response<MemberModel>
}
30 changes: 3 additions & 27 deletions app/src/main/java/kids/baba/mobile/data/api/MyPageApi.kt
Original file line number Diff line number Diff line change
@@ -1,105 +1,81 @@
package kids.baba.mobile.data.api

import kids.baba.mobile.core.constant.PrefsKey
import kids.baba.mobile.core.utils.EncryptedPrefs
import kids.baba.mobile.domain.model.*
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.DELETE
import retrofit2.http.GET
import retrofit2.http.Header
import retrofit2.http.PATCH
import retrofit2.http.POST
import retrofit2.http.PUT
import retrofit2.http.Path
import retrofit2.http.Query
import retrofit2.http.*

interface MyPageApi {

@GET("members/my-page")
suspend fun loadMyPageGroup(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY)
): Response<GroupResponse>

@GET("members/baby-page/{babyId}")
suspend fun loadBabyProfile(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Path("babyId") babyId: String
): Response<BabyProfileResponse>

@POST("members/groups")
suspend fun addGroup(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Body myPageGroup: MyPageGroup
): Response<Unit>

@PUT("members")
suspend fun editProfile(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Body profile: Profile
): Response<Unit>

@PATCH("baby/{babyId}")
suspend fun editBabyName(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Path("babyId") babyId: String,
@Body babyEdit: BabyEdit
): Response<Unit>

@POST("baby")
suspend fun addMyBaby(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Body baby: MyBaby
): Response<Unit>

@POST("baby/code")
suspend fun addBabyWithInviteCode(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Body inviteCode: InviteCode
): Response<Unit>

@DELETE("baby/{babyId}")
suspend fun deleteBaby(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Path("babyId") babyId: String
): Response<Unit>

@PATCH("members/groups")
suspend fun patchGroup(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Query("groupName") groupName: String,
@Body group: GroupInfo
): Response<Unit>

@DELETE("members/groups")
suspend fun deleteGroup(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Query("groupName") groupName: String
): Response<Unit>

@PATCH("members/groups/{groupMemberId}")
suspend fun patchMember(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Path("groupMemberId") memberId: String,
@Body relationName: GroupMemberInfo
): Response<Unit>

//TODO FIX
@DELETE("members/groups/{groupMemberId}")
suspend fun deleteGroupMember(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Path("groupMemberId") memberId: String
): Response<Unit>


@GET("baby/invitation")
suspend fun getInvitationInfo(
@Query("code") inviteCode: String): Response<BabiesInfoResponse>

@Query("code") inviteCode: String
): Response<BabiesInfoResponse>

@POST("baby/invite-code")
suspend fun makeInviteCode(
@Header("Authorization") token: String = EncryptedPrefs.getString(PrefsKey.ACCESS_TOKEN_KEY),
@Body relationInfo: RelationInfo
): Response<InviteCode>

Expand Down
23 changes: 23 additions & 0 deletions app/src/main/java/kids/baba/mobile/data/api/SignUpApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package kids.baba.mobile.data.api

import kids.baba.mobile.domain.model.SignUpRequestWithBabiesInfo
import kids.baba.mobile.domain.model.SignUpRequestWithInviteCode
import kids.baba.mobile.domain.model.TokenResponse
import retrofit2.Response
import retrofit2.http.Body
import retrofit2.http.Header
import retrofit2.http.POST

interface SignUpApi {
@POST("members/baby")
suspend fun signUpWithBabiesInfo(
@Body
signupRequestWithBabiesInfo: SignUpRequestWithBabiesInfo
): Response<TokenResponse>

@POST("members/baby/invite-code")
suspend fun signUpWithInviteCode(
@Body
signUpRequestWithInviteCode: SignUpRequestWithInviteCode
): Response<TokenResponse>
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,30 +5,29 @@ import okhttp3.MultipartBody
import okhttp3.RequestBody

interface AlbumRemoteDataSource {
suspend fun getAlbum(id: String, year: Int, month: Int): Result<List<Album>>
suspend fun getAlbum(id: String, year: Int, month: Int): ApiResult<List<Album>>

suspend fun getOneAlbum(babyId:String, contentId: Int): Result<Album>
suspend fun getOneAlbum(babyId: String, contentId: Int): ApiResult<Album>

suspend fun postAlbum(
accessToken: String,
id: String,
photo: MultipartBody.Part,
bodyDataHashMap: HashMap<String, RequestBody>
): Result<PostAlbumResponse>
): ApiResult<PostAlbumResponse>

suspend fun likeAlbum(id: String, contentId: Int): Result<Boolean>
suspend fun likeAlbum(id: String, contentId: Int): ApiResult<Boolean>
suspend fun deleteAlbum(
babyId: String,
contentId: Int
): Result<Unit>
): ApiResult<Unit>

suspend fun addComment(id: String, contentId: Int, commentInput: CommentInput): Result<Unit>
suspend fun addComment(id: String, contentId: Int, commentInput: CommentInput): ApiResult<Unit>

suspend fun deleteComment(id: String, contentId: Int, commentId: String) : Result<Unit>
suspend fun deleteComment(id: String, contentId: Int, commentId: String): ApiResult<Unit>

suspend fun getComment(id: String, contentId: Int): Result<List<Comment>>
suspend fun getComment(id: String, contentId: Int): ApiResult<List<Comment>>

suspend fun getLikeDetail(id: String, contentId: Int): Result<LikeDetailResponse>
suspend fun getLikeDetail(id: String, contentId: Int): ApiResult<LikeDetailResponse>

suspend fun getAllAlbum(id: String): Result<List<Album>>
suspend fun getAllAlbum(id: String): ApiResult<List<Album>>
}
Loading