generated from AND-SOPT-ANDROID/and-sopt-android-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from AND-SOPT-ANDROID/week4
Week4
- Loading branch information
Showing
18 changed files
with
557 additions
and
98 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package org.sopt.and | ||
|
||
import android.app.Application | ||
import dagger.hilt.android.HiltAndroidApp | ||
|
||
@HiltAndroidApp | ||
class MyApplication : Application() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package org.sopt.and.api | ||
|
||
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory | ||
import dagger.Module | ||
import dagger.Provides | ||
import dagger.hilt.InstallIn | ||
import dagger.hilt.components.SingletonComponent | ||
import kotlinx.serialization.json.Json | ||
import okhttp3.MediaType.Companion.toMediaType | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import org.sopt.and.BuildConfig | ||
import retrofit2.Retrofit | ||
import javax.inject.Singleton | ||
|
||
@Module | ||
@InstallIn(SingletonComponent::class) | ||
object ApiFactory { | ||
private const val BASE_URL: String = BuildConfig.BASE_URL | ||
|
||
@Provides | ||
@Singleton | ||
fun provideOkHttpClient(): OkHttpClient { | ||
val loggingInterceptor = HttpLoggingInterceptor().apply { | ||
level = HttpLoggingInterceptor.Level.BODY | ||
} | ||
return OkHttpClient.Builder() | ||
.addInterceptor(loggingInterceptor) | ||
.build() | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideRetrofit(client: OkHttpClient): Retrofit { | ||
return Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.client(client) | ||
.addConverterFactory(Json.asConverterFactory("application/json".toMediaType())) | ||
.build() | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideUserRegistrationService(retrofit: Retrofit): UserRegistrationService { | ||
return retrofit.create(UserRegistrationService::class.java) | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideLoginService(retrofit: Retrofit): LoginService { | ||
return retrofit.create(LoginService::class.java) | ||
} | ||
|
||
@Provides | ||
@Singleton | ||
fun provideHobbyService(retrofit: Retrofit): HobbyService { | ||
return retrofit.create(HobbyService::class.java) | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package org.sopt.and.api | ||
|
||
import org.sopt.and.dto.RequestLoginData | ||
import org.sopt.and.dto.RequestUserRegistrationData | ||
import org.sopt.and.dto.ResponseLogin | ||
import org.sopt.and.dto.ResponseUserRegistration | ||
import retrofit2.Response | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
|
||
interface UserRegistrationService { | ||
@POST("/user") | ||
suspend fun postUserRegistration( | ||
@Body userRequest: RequestUserRegistrationData | ||
): Response<ResponseUserRegistration> | ||
} | ||
|
||
interface LoginService { | ||
@POST("/login") | ||
suspend fun postLogin( | ||
@Body loginRequeset: RequestLoginData | ||
): Response<ResponseLogin> | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package org.sopt.and.api | ||
|
||
import org.sopt.and.dto.ResponseMyHobbyData | ||
import retrofit2.Response | ||
import retrofit2.http.GET | ||
import retrofit2.http.Header | ||
|
||
interface HobbyService { | ||
@GET("/user/my-hobby") | ||
suspend fun getHobby( | ||
@Header("token") token: String? | ||
): Response<ResponseMyHobbyData> | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
package org.sopt.and.dto | ||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
/* 유저 등록 */ | ||
@Serializable | ||
data class RequestUserRegistrationData( | ||
@SerialName("username") | ||
val userName: String, | ||
@SerialName("password") | ||
val password: String, | ||
@SerialName("hobby") | ||
val hobby: String | ||
) | ||
|
||
@Serializable | ||
data class ResponseUserRegistration( | ||
@SerialName("result") | ||
val result: ResultUserNo | ||
) | ||
|
||
@Serializable | ||
data class ResultUserNo( | ||
@SerialName("no") | ||
val no: Int | ||
) | ||
|
||
/* 로그인 */ | ||
@Serializable | ||
data class RequestLoginData( | ||
@SerialName("username") | ||
val userName: String, | ||
@SerialName("password") | ||
val password: String | ||
) | ||
|
||
@Serializable | ||
data class ResponseLogin( | ||
@SerialName("result") | ||
val result: ResultToken | ||
) | ||
|
||
@Serializable | ||
data class ResultToken( | ||
@SerialName("token") | ||
val token: String | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package org.sopt.and.dto | ||
|
||
|
||
import kotlinx.serialization.SerialName | ||
import kotlinx.serialization.Serializable | ||
|
||
/* 내 취미 조회 */ | ||
@Serializable | ||
data class ResponseMyHobbyData( | ||
@SerialName("result") | ||
val result: ResponseMyHobbyDataResult | ||
) | ||
|
||
@Serializable | ||
data class ResponseMyHobbyDataResult( | ||
@SerialName("hobby") | ||
val hobby: String | ||
) |
Oops, something went wrong.