Skip to content

Commit

Permalink
Merge pull request #10 from DO-SOPT-ANDROID/appjam-refactor
Browse files Browse the repository at this point in the history
Appjam refactor
  • Loading branch information
minemi00 authored Jan 29, 2024
2 parents 2cd4ffc + 04a661b commit 9fafa8c
Show file tree
Hide file tree
Showing 53 changed files with 532 additions and 249 deletions.
15 changes: 12 additions & 3 deletions app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ plugins {
id 'com.android.application'
id 'org.jetbrains.kotlin.android'
id 'org.jetbrains.kotlin.plugin.serialization' version '1.8.20'
id 'kotlin-kapt'
id 'dagger.hilt.android.plugin'
}

Properties properties = new Properties()
Expand Down Expand Up @@ -36,11 +38,11 @@ android {
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_11
targetCompatibility JavaVersion.VERSION_11
sourceCompatibility JavaVersion.VERSION_17
targetCompatibility JavaVersion.VERSION_17
}
kotlinOptions {
jvmTarget = '11'
jvmTarget = '17'
}
}

Expand All @@ -67,4 +69,11 @@ dependencies {
implementation('com.squareup.okhttp3:okhttp:4.9.1')
implementation("io.coil-kt:coil:2.0.0-rc03")
implementation 'org.jetbrains.kotlinx:kotlinx-coroutines-android:1.3.9'
implementation 'com.jakewharton.timber:timber:4.7.1'
implementation "com.google.dagger:hilt-android:2.44"
kapt "com.google.dagger:hilt-compiler:2.44"
}

kapt {
correctErrorTypes true
}
7 changes: 4 additions & 3 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
<uses-permission android:name="android.permission.INTERNET" />

<application
android:name=".App"
android:allowBackup="true"
android:dataExtractionRules="@xml/data_extraction_rules"
android:fullBackupContent="@xml/backup_rules"
Expand All @@ -16,11 +17,11 @@
android:usesCleartextTraffic="true"
tools:targetApi="31">
<activity
android:name=".presentation.auth.SignUpActivity"
android:name=".ui.auth.SignUpActivity"
android:windowSoftInputMode="adjustPan"
android:exported="false" />
<activity
android:name=".presentation.auth.LoginActivity"
android:name=".ui.auth.LoginActivity"
android:windowSoftInputMode="adjustResize"
android:exported="true">
<intent-filter>
Expand All @@ -30,7 +31,7 @@
</intent-filter>
</activity>
<activity
android:name=".presentation.home.HomeActivity"
android:name=".ui.home.HomeActivity"
android:windowSoftInputMode="adjustResize"
android:exported="false" />
</application>
Expand Down
13 changes: 13 additions & 0 deletions app/src/main/java/org/sopt/dosopttemplate/App.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.sopt.dosopttemplate

import android.app.Application
import androidx.appcompat.app.AppCompatDelegate
import dagger.hilt.android.HiltAndroidApp

@HiltAndroidApp
class App : Application() {
override fun onCreate() {
super.onCreate()
AppCompatDelegate.setDefaultNightMode(AppCompatDelegate.MODE_NIGHT_NO)
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sopt.dosopttemplate.data.datasource

import org.sopt.dosopttemplate.data.entity.response.ResponseFollowerDto
import org.sopt.dosopttemplate.data.entity.service.FollowerService
import javax.inject.Inject

class FollowerDataSource @Inject constructor(
private val followerService: FollowerService
) {
suspend fun follower(): ResponseFollowerDto =
followerService.follower()
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.sopt.dosopttemplate.data.datasource

import org.sopt.dosopttemplate.data.entity.request.RequestLoginDto
import org.sopt.dosopttemplate.data.entity.response.ResponseLoginDto
import org.sopt.dosopttemplate.data.entity.service.LoginService
import javax.inject.Inject

class LoginDataSource @Inject constructor(
private val loginService: LoginService
) {
suspend fun login(request: RequestLoginDto): ResponseLoginDto =
loginService.login(request)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package org.sopt.dosopttemplate.data.datasource

import org.sopt.dosopttemplate.data.entity.request.RequestSignUpDto
import org.sopt.dosopttemplate.data.entity.service.SignUpService
import javax.inject.Inject

class SignUpDataSource @Inject constructor(
private val signUpService: SignUpService
) {
suspend fun signUp(request: RequestSignUpDto) = signUpService.signUp(request)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package org.sopt.dosopttemplate.data.entity

import org.sopt.dosopttemplate.data.entity.response.ResponseLoginDto

sealed class LoginState {
object Loading : LoginState()
data class Success(val data: ResponseLoginDto.UserInfo) : LoginState()
object Error : LoginState()
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.dosopttemplate.data.model.request
package org.sopt.dosopttemplate.data.entity.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.dosopttemplate.data.model.request
package org.sopt.dosopttemplate.data.entity.request

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
package org.sopt.dosopttemplate.data.model.response
package org.sopt.dosopttemplate.data.entity.response

import kotlinx.serialization.SerialName
import kotlinx.serialization.Serializable
import org.sopt.dosopttemplate.domain.model.Follower

@Serializable
data class ResponseFollowerDto(
Expand Down Expand Up @@ -40,5 +41,13 @@ data class ResponseFollowerDto(
val text: String
)

fun toFollower() = data.map { data ->
Follower(
id = data.id,
avatar = data.avatar,
email = data.email,
firstName = data.firstName
)
}
}

Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package org.sopt.dosopttemplate.data.entity.response

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

@Serializable
data class ResponseLoginDto(
@SerialName("status")
val status: Int,
@SerialName("message")
val message: String,
@SerialName("data")
val data: UserInfo,
) {
@Serializable
data class UserInfo(
@SerialName("id")
val id: Int,
@SerialName("username")
val username: String,
@SerialName("nickname")
val nickname: String
)
}

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.dosopttemplate.data.model.response
package org.sopt.dosopttemplate.data.entity.response

data class ResponseSignUpDto(
val success: Unit
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sopt.dosopttemplate.data.entity.service

import org.sopt.dosopttemplate.data.entity.response.ResponseFollowerDto
import retrofit2.http.GET
import retrofit2.http.Query

interface FollowerService {
@GET("api/users")
suspend fun follower(
@Query("page") num: Int = 2
): ResponseFollowerDto
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.sopt.dosopttemplate.data.entity.service

import org.sopt.dosopttemplate.data.entity.request.RequestLoginDto
import org.sopt.dosopttemplate.data.entity.response.ResponseLoginDto
import retrofit2.http.Body
import retrofit2.http.POST

interface LoginService {
@POST("api/v1/members/sign-in")
suspend fun login(
@Body request: RequestLoginDto,
): ResponseLoginDto
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package org.sopt.dosopttemplate.data.entity.service

import org.sopt.dosopttemplate.data.entity.request.RequestSignUpDto
import retrofit2.http.Body
import retrofit2.http.POST

interface SignUpService {
@POST("api/v1/members")
suspend fun signUp(
@Body signUpReq: RequestSignUpDto,
)
}

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package org.sopt.dosopttemplate.data.repositoryimpl

import org.sopt.dosopttemplate.data.datasource.FollowerDataSource
import org.sopt.dosopttemplate.domain.model.Follower
import org.sopt.dosopttemplate.domain.repository.FollowerRepository
import javax.inject.Inject

class FollowerRepositoryImpl @Inject constructor(private val followerDataSource: FollowerDataSource) :
FollowerRepository {
override suspend fun loadFollowerData(): Result<List<Follower>> =
runCatching {
followerDataSource.follower().toFollower()
}
}


Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package org.sopt.dosopttemplate.data.repositoryimpl

import org.sopt.dosopttemplate.data.datasource.LoginDataSource
import org.sopt.dosopttemplate.data.entity.request.RequestLoginDto
import org.sopt.dosopttemplate.data.entity.response.ResponseLoginDto
import org.sopt.dosopttemplate.domain.repository.LoginRepository
import javax.inject.Inject

class LoginRepositoryImpl @Inject constructor(private val loginDataSource: LoginDataSource) :
LoginRepository {
override suspend fun login(
username: String,
password: String
): Result<ResponseLoginDto.UserInfo> =
runCatching {
loginDataSource.login(RequestLoginDto(username, password)).data
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package org.sopt.dosopttemplate.data.repositoryimpl

import org.sopt.dosopttemplate.data.datasource.SignUpDataSource
import org.sopt.dosopttemplate.data.entity.request.RequestSignUpDto
import org.sopt.dosopttemplate.domain.repository.SignUpRepository
import javax.inject.Inject

class SignUpRepositoryImpl @Inject constructor(private val signUpDataSource: SignUpDataSource) :
SignUpRepository {
override suspend fun signUp(id: String, password: String, nickname: String): Result<Unit> =
runCatching {
signUpDataSource.signUp(RequestSignUpDto(id, password, nickname))
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package org.sopt.dosopttemplate.data.model.service
package org.sopt.dosopttemplate.di

import android.util.Log
import com.jakewharton.retrofit2.converter.kotlinx.serialization.asConverterFactory
Expand All @@ -8,6 +8,9 @@ import okhttp3.MediaType.Companion.toMediaType
import okhttp3.OkHttpClient
import okhttp3.logging.HttpLoggingInterceptor
import org.sopt.dosopttemplate.BuildConfig
import org.sopt.dosopttemplate.data.entity.service.FollowerService
import org.sopt.dosopttemplate.data.entity.service.LoginService
import org.sopt.dosopttemplate.data.entity.service.SignUpService
import retrofit2.Retrofit

object ApiFactory {
Expand Down Expand Up @@ -49,6 +52,7 @@ object ReqresApiFactory {
}

object ServicePool {
val authService = ApiFactory.create<AuthService>()
val loginService = ApiFactory.create<LoginService>()
val signUpService = ApiFactory.create<SignUpService>()
val followerService = ReqresApiFactory.create<FollowerService>()
}
Loading

0 comments on commit 9fafa8c

Please sign in to comment.