forked from tukcomCD2024/ISP
-
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.
Feat : Connect a backend weather API tukcomCD2024#102 tukcomCD2024#85
fix a bug user can't change schedule date when its original date is later than a date that user want to change
- Loading branch information
Showing
26 changed files
with
545 additions
and
92 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
7 changes: 7 additions & 0 deletions
7
...outTrip/app/src/main/java/com/project/how/data_class/dto/country/GetCountryInfoRequest.kt
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 com.project.how.data_class.dto.country | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class GetCountryInfoRequest( | ||
@SerializedName("country") val country : String | ||
) |
15 changes: 15 additions & 0 deletions
15
...src/main/java/com/project/how/data_class/dto/country/weather/GetCurrentWeatherResponse.kt
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,15 @@ | ||
package com.project.how.data_class.dto.country.weather | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
data class GetCurrentWeatherResponse ( | ||
val main: String, | ||
val description: String, | ||
val temp: String, | ||
val localTime: String, | ||
val iconUrl: String, | ||
@SerializedName("temp_min") | ||
val tempMin: String, | ||
@SerializedName("temp_max") | ||
val tempMax: String | ||
) |
14 changes: 14 additions & 0 deletions
14
...src/main/java/com/project/how/data_class/dto/country/weather/GetWeeklyWeathersResponse.kt
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,14 @@ | ||
package com.project.how.data_class.dto.country.weather | ||
|
||
import com.google.gson.annotations.SerializedName | ||
|
||
typealias GetWeeklyWeathersResponse = ArrayList<GetWeeklyWeathersResponseElement> | ||
|
||
data class GetWeeklyWeathersResponseElement ( | ||
@SerializedName("date") | ||
val date: String, | ||
@SerializedName("temp") | ||
val temp: String, | ||
@SerializedName("iconUrl") | ||
val iconUrl: 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
24 changes: 24 additions & 0 deletions
24
android/HowAboutTrip/app/src/main/java/com/project/how/model/CountryRepository.kt
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,24 @@ | ||
package com.project.how.model | ||
|
||
import androidx.lifecycle.LiveData | ||
import androidx.lifecycle.MutableLiveData | ||
import com.project.how.data_class.dto.country.weather.GetCurrentWeatherResponse | ||
import com.project.how.data_class.dto.country.weather.GetWeeklyWeathersResponse | ||
|
||
class CountryRepository { | ||
private var _currentWeatherLiveData : MutableLiveData<GetCurrentWeatherResponse> = MutableLiveData() | ||
private var _weeklyWeathersLiveData : MutableLiveData<GetWeeklyWeathersResponse> = MutableLiveData() | ||
val currentWeatherLiveData : LiveData<GetCurrentWeatherResponse> | ||
get() = _currentWeatherLiveData | ||
val weeklyWeathersLiveData : LiveData<GetWeeklyWeathersResponse> | ||
get() = _weeklyWeathersLiveData | ||
|
||
fun getCurrentWeather(data : GetCurrentWeatherResponse){ | ||
_currentWeatherLiveData.postValue(data) | ||
} | ||
|
||
fun getWeeklyWeathers(data : GetWeeklyWeathersResponse){ | ||
_weeklyWeathersLiveData.postValue(data) | ||
} | ||
|
||
} |
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
26 changes: 26 additions & 0 deletions
26
...id/HowAboutTrip/app/src/main/java/com/project/how/network/api_interface/CountryService.kt
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,26 @@ | ||
package com.project.how.network.api_interface | ||
|
||
import com.project.how.data_class.dto.country.GetCountryInfoRequest | ||
import com.project.how.data_class.dto.country.GetCountryLocationResponse | ||
import com.project.how.data_class.dto.country.weather.GetCurrentWeatherResponse | ||
import com.project.how.data_class.dto.country.weather.GetWeeklyWeathersResponse | ||
import retrofit2.Call | ||
import retrofit2.http.Body | ||
import retrofit2.http.POST | ||
|
||
interface CountryService { | ||
@POST("countries/locations") | ||
fun getCountryLocation( | ||
@Body country : GetCountryInfoRequest | ||
) : Call<GetCountryLocationResponse> | ||
|
||
@POST("countries/weather/current") | ||
fun getCurrentWeather( | ||
@Body country: GetCountryInfoRequest | ||
) : Call<GetCurrentWeatherResponse> | ||
|
||
@POST("countries/weather/weekly") | ||
fun getWeeklyWeather( | ||
@Body country: GetCountryInfoRequest | ||
) : Call<GetWeeklyWeathersResponse> | ||
} |
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
41 changes: 41 additions & 0 deletions
41
android/HowAboutTrip/app/src/main/java/com/project/how/network/client/CountryRetrofit.kt
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,41 @@ | ||
package com.project.how.network.client | ||
|
||
import com.google.gson.GsonBuilder | ||
import com.project.how.BuildConfig | ||
import com.project.how.network.api_interface.CountryService | ||
import com.project.how.network.converter_factory.NullOnEmptyConverterFactory | ||
import okhttp3.OkHttpClient | ||
import okhttp3.logging.HttpLoggingInterceptor | ||
import retrofit2.Retrofit | ||
import retrofit2.converter.gson.GsonConverterFactory | ||
import retrofit2.converter.scalars.ScalarsConverterFactory | ||
import java.util.concurrent.TimeUnit | ||
|
||
object CountryRetrofit { | ||
private const val BASE_URL = BuildConfig.API_SERVER | ||
|
||
fun getApiService() : CountryService? = getInstance() | ||
?.create(CountryService::class.java) | ||
|
||
private fun getInstance() : Retrofit? { | ||
val gson = GsonBuilder().setLenient().create() | ||
|
||
val httpClient = OkHttpClient.Builder() | ||
.connectTimeout(3, TimeUnit.MINUTES) | ||
.readTimeout(2, TimeUnit.MINUTES) | ||
.writeTimeout(1, TimeUnit.MINUTES) | ||
|
||
val loggingInterceptor = HttpLoggingInterceptor().apply { | ||
level = HttpLoggingInterceptor.Level.BODY | ||
} | ||
httpClient.addInterceptor(loggingInterceptor) | ||
|
||
return Retrofit.Builder() | ||
.baseUrl(BASE_URL) | ||
.addConverterFactory(ScalarsConverterFactory.create()) | ||
.addConverterFactory(NullOnEmptyConverterFactory()) | ||
.addConverterFactory(GsonConverterFactory.create(gson)) | ||
.client(httpClient.build()) | ||
.build() | ||
} | ||
} |
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
Oops, something went wrong.