Skip to content

Commit

Permalink
검색, 요일별 리스트 api 정의 (#2)
Browse files Browse the repository at this point in the history
* add pull request template

* [feat] 검색, 요일별 리스트에 사용할 api response 추가
  • Loading branch information
LeeOhHyung authored May 19, 2021
1 parent b58ab5e commit b2cfd5e
Show file tree
Hide file tree
Showing 21 changed files with 221 additions and 17 deletions.
12 changes: 12 additions & 0 deletions .github/PULL_REQUEST_TEMPLATE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# PULL REQUEST

## Description


## ScreenShots
<p>
<img src="", width="300" />
</p>

## Reference
-
14 changes: 13 additions & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ android {
versionCode versionMajor * 10000 + versionMinor * 1000 + versionPatch * 100 + versionBuild
versionName "${versionMajor}.${versionMinor}.${versionPatch}"

buildConfigField "String", "BASE_URL", "\"\""
buildConfigField "String", "BASE_URL", getBaseUrl("BASE_URL")
project.archivesBaseName = "android-" + defaultConfig.versionCode
testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner"
vectorDrawables.useSupportLibrary = true
Expand Down Expand Up @@ -129,3 +129,15 @@ dependencies {
testImplementation deps.test.archCore
testImplementation deps.test.robolectric
}

String getBaseUrl(String name) {
try {
def properties = new Properties()
properties.load(new FileInputStream(rootProject.file("./local.properties")))
def baseUrl = properties.getProperty(name)
if(baseUrl != null) baseUrl else "\"https://fake.api.com\""
} catch(FileNotFoundException e) {
e.printStackTrace()
"\"https://fake.api.com\""
}
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Created by Leo on 2021. 05. 19 ..
*/
package kr.tooni.tooni.extensions
package kr.tooni.tooni.core.extensions

import androidx.appcompat.app.AppCompatActivity
import androidx.lifecycle.LiveData
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Created by Leo on 2021. 05. 19 ..
*/
package kr.tooni.tooni.extensions
package kr.tooni.tooni.core.extensions

import android.content.Context
import androidx.annotation.DrawableRes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Created by Leo on 2021. 04. 17 ..
*/
package kr.tooni.tooni.extensions
package kr.tooni.tooni.core.extensions

import android.graphics.drawable.Drawable
import androidx.annotation.ColorRes
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Created by Leo on 2021. 04. 17 ..
*/
package kr.tooni.tooni.extensions
package kr.tooni.tooni.core.extensions

import android.graphics.drawable.Drawable
import android.widget.ImageView
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Created by Leo on 2021. 04. 17 ..
*/
package kr.tooni.tooni.extensions
package kr.tooni.tooni.core.extensions

import android.graphics.drawable.Drawable
import android.widget.ImageView
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Created by Leo on 2021. 04. 17 ..
*/
package kr.tooni.tooni.extensions
package kr.tooni.tooni.core.extensions

import android.content.Context
import android.content.res.Resources
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Created by Leo on 2021. 04. 17 ..
*/
package kr.tooni.tooni.extensions
package kr.tooni.tooni.core.extensions

import android.content.Context
import androidx.recyclerview.widget.RecyclerView
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
/*
* Created by Leo on 2021. 04. 17 ..
*/
package kr.tooni.tooni.extensions
package kr.tooni.tooni.core.extensions

import android.content.Context
import android.widget.Toast
Expand Down
18 changes: 18 additions & 0 deletions app/src/main/kotlin/kr/tooni/tooni/core/model/Author.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Created by Leo on 2021. 05. 19 ..
*/
package kr.tooni.tooni.core.model

data class Author(
val id: Long,
val name: String,
) {

companion object {

val EMPTY = Author(
id = 0,
name = ""
)
}
}
29 changes: 29 additions & 0 deletions app/src/main/kotlin/kr/tooni/tooni/core/model/Site.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
/*
* Created by Leo on 2021. 05. 19 ..
*/
package kr.tooni.tooni.core.model

import com.google.gson.annotations.SerializedName

data class Site(
val site: Type?,
val thumbnail: String?
) {

enum class Type {
@SerializedName("NAVER")
NAVER,
@SerializedName("DAUM")
DAUM,
@SerializedName("NONE")
NONE
}

companion object {

val EMPTY = Site(
site = Type.NONE,
thumbnail = null
)
}
}
27 changes: 27 additions & 0 deletions app/src/main/kotlin/kr/tooni/tooni/core/model/Webtoon.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
/*
* Created by Leo on 2021. 05. 19 ..
*/
package kr.tooni.tooni.core.model

data class Webtoon(
val id: Long,
val authors: List<Author>,
val site: Site,
val thumbnail: String,
val title: String
) {

companion object {

val EMPTY = Webtoon(
id = 0,
authors = listOf(),
site = Site(
site = null,
thumbnail = null
),
thumbnail = "",
title = ""
)
}
}
14 changes: 14 additions & 0 deletions app/src/main/kotlin/kr/tooni/tooni/core/model/WeekDay.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
/*
* Created by Leo on 2021. 05. 19 ..
*/
package kr.tooni.tooni.core.model

enum class WeekDay(val value: String) {
MON("mon"),
TUE("thu"),
WED("wed"),
THU("thu"),
FRI("fri"),
SAT("sat"),
SUN("sun")
}
24 changes: 24 additions & 0 deletions app/src/main/kotlin/kr/tooni/tooni/data/api/ListApi.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
/*
* Created by Leo on 2021. 05. 19 ..
*/
package kr.tooni.tooni.data.api

import io.reactivex.rxjava3.core.Single
import kr.tooni.tooni.data.response.WebtoonSearchResponse
import kr.tooni.tooni.data.response.WebtoonWeekDayResponse
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query

interface ListApi : Api {

@GET("search")
fun search(
@Query("query") query: String
): Single<WebtoonSearchResponse>

@GET("weekday/{weekday}")
fun getWebtoonsByDay(
@Path("weekday") weekday: String
): Single<WebtoonWeekDayResponse>
}
22 changes: 22 additions & 0 deletions app/src/main/kotlin/kr/tooni/tooni/data/response/BaseResponse.kt
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
/*
* Created by Leo on 2021. 05. 19 ..
*/
package kr.tooni.tooni.data.response

import com.google.gson.annotations.SerializedName

abstract class BaseResponse {
val status: Status? = null
val message: String? = null

enum class Status {
@SerializedName("OK")
OK,

@SerializedName("CLIENT_ERROR")
CLIENT_ERROR,

@SerializedName("SERVER_ERROR")
SERVER_ERROR
}
}
6 changes: 0 additions & 6 deletions app/src/main/kotlin/kr/tooni/tooni/data/response/Response.kt

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
/*
* Created by Leo on 2021. 05. 19 ..
*/
package kr.tooni.tooni.data.response

import kr.tooni.tooni.core.model.Webtoon

data class WebtoonSearchResponse(
val data: WebtoonSearch?
) : BaseResponse() {

data class WebtoonSearch(
val query: String,
val webtoons: List<Webtoon>
)
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
/*
* Created by Leo on 2021. 05. 19 ..
*/
package kr.tooni.tooni.data.response

import kr.tooni.tooni.core.model.Site
import kr.tooni.tooni.core.model.Webtoon

data class WebtoonWeekDayResponse(
val data: WebtoonWeekDay
) : BaseResponse() {

data class WebtoonWeekDay(
val sites: List<Site>,
val webtoons: List<Webtoon>
)
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,15 @@ import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import androidx.fragment.app.viewModels
import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.disposables.CompositeDisposable
import io.reactivex.rxjava3.schedulers.Schedulers
import kr.tooni.tooni.R
import kr.tooni.tooni.base.BaseFragment
import kr.tooni.tooni.data.ApiProvider
import kr.tooni.tooni.data.api.ListApi
import kr.tooni.tooni.databinding.FragmentWebtoonByDayBinding
import timber.log.Timber

class DayWebtoonFragment :
BaseFragment<FragmentWebtoonByDayBinding>(R.layout.fragment_webtoon_by_day) {
Expand All @@ -30,8 +36,6 @@ class DayWebtoonFragment :

override fun onViewCreated(view: View, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)

// do LiveData observe
}

companion object {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,22 @@
*/
package kr.tooni.tooni.features.day

import io.reactivex.rxjava3.android.schedulers.AndroidSchedulers
import io.reactivex.rxjava3.schedulers.Schedulers
import kr.tooni.tooni.base.BaseViewModel
import kr.tooni.tooni.data.ApiProvider
import kr.tooni.tooni.data.api.ListApi
import timber.log.Timber

class DayWebtoonViewModel : BaseViewModel() {

init {
ApiProvider.create(ListApi::class.java).search("조석")
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({
// do something
}, Timber::e)
.addDisposable()
}
}

0 comments on commit b2cfd5e

Please sign in to comment.