Skip to content

Commit 6128fc4

Browse files
Merge pull request #26 from intive-FDV/feature/Rate_a_Screening
Feature/rate a screening
2 parents a6f1b7e + 1622a5e commit 6128fc4

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

50 files changed

+784
-153
lines changed

.github/workflows/android.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,6 @@ jobs:
8080
# email body as text
8181
body: ${{ github.job }} job in worflow ${{ github.workflow }} of ${{ github.repository }} has ${{ job.status }}
8282
# comma-separated string, send email to
83-
to: francisco.beccuti@intive.com
83+
to: francisco.beccut@intive.com
8484
# from email name
8585
from: TMDB Team! GitHub Actions!

app/schemas/com.intive.tmdbandroid.datasource.local.LocalStorage/1.json

Lines changed: 65 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,11 @@
22
"formatVersion": 1,
33
"database": {
44
"version": 1,
5-
"identityHash": "016e4507f17862924f247000e7d4f1c4",
5+
"identityHash": "320b71eb2503e195a8d56c17386e39c7",
66
"entities": [
77
{
88
"tableName": "ScreeningORMEntity",
9-
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `backdrop_path` TEXT, `genres` TEXT, `name` TEXT NOT NULL, `number_of_episodes` INTEGER, `number_of_seasons` INTEGER, `overview` TEXT NOT NULL, `poster_path` TEXT, `status` TEXT, `vote_average` REAL NOT NULL, `vote_count` INTEGER NOT NULL, `popularity` REAL NOT NULL, `release_date` TEXT, `media_type` TEXT NOT NULL, `adult` INTEGER NOT NULL, `genre_ids` TEXT, `video` INTEGER NOT NULL, `networks` TEXT NOT NULL, PRIMARY KEY(`id`))",
9+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER NOT NULL, `backdrop_path` TEXT, `genres` TEXT, `name` TEXT NOT NULL, `number_of_episodes` INTEGER, `number_of_seasons` INTEGER, `overview` TEXT NOT NULL, `poster_path` TEXT, `status` TEXT, `vote_average` REAL NOT NULL, `vote_count` INTEGER NOT NULL, `popularity` REAL NOT NULL, `release_date` TEXT, `media_type` TEXT NOT NULL, `adult` INTEGER NOT NULL, `genre_ids` TEXT, `video` INTEGER NOT NULL, `networks` TEXT NOT NULL, `my_rate` REAL NOT NULL, `my_favorite` INTEGER NOT NULL, PRIMARY KEY(`id`))",
1010
"fields": [
1111
{
1212
"fieldPath": "id",
@@ -115,6 +115,18 @@
115115
"columnName": "networks",
116116
"affinity": "TEXT",
117117
"notNull": true
118+
},
119+
{
120+
"fieldPath": "my_rate",
121+
"columnName": "my_rate",
122+
"affinity": "REAL",
123+
"notNull": true
124+
},
125+
{
126+
"fieldPath": "my_favorite",
127+
"columnName": "my_favorite",
128+
"affinity": "INTEGER",
129+
"notNull": true
118130
}
119131
],
120132
"primaryKey": {
@@ -125,12 +137,62 @@
125137
},
126138
"indices": [],
127139
"foreignKeys": []
140+
},
141+
{
142+
"tableName": "SessionORMEntity",
143+
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`id` INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL, `success` INTEGER NOT NULL, `guest_session_id` TEXT NOT NULL, `expires_at` TEXT NOT NULL, `status_message` TEXT NOT NULL, `status_code` INTEGER NOT NULL)",
144+
"fields": [
145+
{
146+
"fieldPath": "id",
147+
"columnName": "id",
148+
"affinity": "INTEGER",
149+
"notNull": true
150+
},
151+
{
152+
"fieldPath": "success",
153+
"columnName": "success",
154+
"affinity": "INTEGER",
155+
"notNull": true
156+
},
157+
{
158+
"fieldPath": "guest_session_id",
159+
"columnName": "guest_session_id",
160+
"affinity": "TEXT",
161+
"notNull": true
162+
},
163+
{
164+
"fieldPath": "expires_at",
165+
"columnName": "expires_at",
166+
"affinity": "TEXT",
167+
"notNull": true
168+
},
169+
{
170+
"fieldPath": "status_message",
171+
"columnName": "status_message",
172+
"affinity": "TEXT",
173+
"notNull": true
174+
},
175+
{
176+
"fieldPath": "status_code",
177+
"columnName": "status_code",
178+
"affinity": "INTEGER",
179+
"notNull": true
180+
}
181+
],
182+
"primaryKey": {
183+
"columnNames": [
184+
"id"
185+
],
186+
"autoGenerate": true
187+
},
188+
"indices": [],
189+
"foreignKeys": []
128190
}
129191
],
130192
"views": [],
131193
"setupQueries": [
132194
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
133-
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '016e4507f17862924f247000e7d4f1c4')"
195+
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '320b71eb2503e195a8d56c17386e39c7')"
134196
]
135197
}
136198
}

app/src/main/java/com/intive/tmdbandroid/datasource/local/Dao.kt

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.intive.tmdbandroid.datasource.local
33
import androidx.room.*
44
import androidx.room.Dao
55
import com.intive.tmdbandroid.entity.ScreeningORMEntity
6+
import com.intive.tmdbandroid.entity.SessionORMEntity
67

78
@Dao
89
interface Dao{
@@ -18,6 +19,12 @@ interface Dao{
1819
@Delete
1920
suspend fun deleteFavorite(screeningORMEntity: ScreeningORMEntity)
2021

21-
@Query("SELECT EXISTS(SELECT * FROM ScreeningORMEntity WHERE id = :id)")
22-
suspend fun existAsFavorite(id: Int): Boolean
22+
@Query("SELECT * FROM ScreeningORMEntity WHERE id = :id")
23+
suspend fun existAsFavorite(id: Int): ScreeningORMEntity
24+
25+
@Query("SELECT * FROM SessionORMEntity WHERE id = 1")
26+
suspend fun existSession(): List<SessionORMEntity>
27+
28+
@Insert(onConflict = OnConflictStrategy.REPLACE)
29+
suspend fun insertSession(sessionORMEntity: SessionORMEntity)
2330
}

app/src/main/java/com/intive/tmdbandroid/datasource/local/LocalStorage.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,12 +4,13 @@ import androidx.room.Database
44
import androidx.room.RoomDatabase
55
import androidx.room.TypeConverters
66
import com.intive.tmdbandroid.entity.ScreeningORMEntity
7+
import com.intive.tmdbandroid.entity.SessionORMEntity
78
import com.intive.tmdbandroid.model.converter.GenreConverter
89
import com.intive.tmdbandroid.model.converter.IntConverter
910
import com.intive.tmdbandroid.model.converter.NetworkConverter
1011

1112
@Database(
12-
entities = [(ScreeningORMEntity::class)],
13+
entities = [ScreeningORMEntity::class,SessionORMEntity::class],
1314
version = 1,
1415
exportSchema = true,
1516
)

app/src/main/java/com/intive/tmdbandroid/datasource/network/ApiClient.kt

Lines changed: 67 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -2,38 +2,62 @@ package com.intive.tmdbandroid.datasource.network
22

33
import com.intive.tmdbandroid.entity.*
44
import com.intive.tmdbandroid.model.Movie
5+
import com.intive.tmdbandroid.model.Session
56
import com.intive.tmdbandroid.model.TVShow
6-
import retrofit2.http.GET
7-
import retrofit2.http.Path
8-
import retrofit2.http.Query
7+
import okhttp3.RequestBody
8+
import okhttp3.ResponseBody
9+
import retrofit2.Response
10+
import retrofit2.http.*
911

1012
interface ApiClient {
1113
// HOME
1214
@GET("tv/popular")
13-
suspend fun getPaginatedPopularTVShows(@Query("api_key") apiKey: String,
14-
@Query("page") page: Int) : ResultTVShowsEntity
15+
suspend fun getPaginatedPopularTVShows(
16+
@Query("api_key") apiKey: String,
17+
@Query("page") page: Int
18+
): ResultTVShowsEntity
1519

1620
@GET("movie/popular")
17-
suspend fun getPaginatedPopularMovies(@Query("api_key") apiKey: String,
18-
@Query("page") page: Int) : ResultMoviesEntity
21+
suspend fun getPaginatedPopularMovies(
22+
@Query("api_key") apiKey: String,
23+
@Query("page") page: Int
24+
): ResultMoviesEntity
1925

2026
// DETAIL
2127

2228
@GET("tv/{tv_id}")
23-
suspend fun getTVShowByID(@Path("tv_id") tvShowID: Int,
24-
@Query("api_key") apiKey: String) : TVShow
29+
suspend fun getTVShowByID(
30+
@Path("tv_id") tvShowID: Int,
31+
@Query("api_key") apiKey: String
32+
): TVShow
2533

2634
@GET("movie/{movie_id}")
27-
suspend fun getMovieByID(@Path("movie_id") movieID: Int,
28-
@Query("api_key") apiKey: String) : Movie
35+
suspend fun getMovieByID(
36+
@Path("movie_id") movieID: Int,
37+
@Query("api_key") apiKey: String
38+
): Movie
2939

3040
@GET("tv/{tv_id}/videos")
31-
suspend fun getTVShowVideos(@Path("tv_id") tvShowID: Int,
32-
@Query("api_key") apiKey: String) : VideoEntity
41+
suspend fun getTVShowVideos(
42+
@Path("tv_id") tvShowID: Int,
43+
@Query("api_key") apiKey: String
44+
): VideoEntity
3345

3446
@GET("movie/{movie_id}/videos")
35-
suspend fun getMovieVideos(@Path("movie_id") movieID: Int,
36-
@Query("api_key") apiKey: String) : VideoEntity
47+
suspend fun getMovieVideos(
48+
@Path("movie_id") movieID: Int,
49+
@Query("api_key") apiKey: String
50+
): VideoEntity
51+
52+
@POST("movie/{movie_id}/rating")
53+
suspend fun postMovieRanking(@Path("movie_id") query: Int, @Query("api_key") apiKey: String, @Query("guest_session_id") sessionId: String, @Body requestBody: RequestBody): Response<ResponseBody>
54+
55+
@POST("tv/{tv_id}/rating")
56+
suspend fun postTVRanking(@Path("tv_id") query: Int, @Query("api_key") apiKey: String, @Query("guest_session_id") sessionId: String, @Body requestBody: RequestBody): Response<ResponseBody>
57+
58+
@GET("authentication/guest_session/new")
59+
suspend fun getNewGuestSession(@Query("api_key") apiKey: String): Session
60+
3761

3862
@GET("person/{person_id}/combined_credits")
3963
suspend fun getCombinedCreditsByID(@Path("person_id") personID: Int,
@@ -44,32 +68,44 @@ interface ApiClient {
4468
@Query("api_key") apiKey: String) : ResultPerson
4569

4670
@GET("tv/{tv_id}/similar")
47-
suspend fun getTVShowSimilar(@Path("tv_id") tvShowID: Int,
48-
@Query("api_key") apiKey: String) : ResultTVShowsEntity
71+
suspend fun getTVShowSimilar(
72+
@Path("tv_id") tvShowID: Int,
73+
@Query("api_key") apiKey: String
74+
): ResultTVShowsEntity
4975

5076
@GET("movie/{movie_id}/similar")
51-
suspend fun getMovieSimilar(@Path("movie_id") movieID: Int,
52-
@Query("api_key") apiKey: String) : ResultMoviesEntity
77+
suspend fun getMovieSimilar(
78+
@Path("movie_id") movieID: Int,
79+
@Query("api_key") apiKey: String
80+
): ResultMoviesEntity
5381

5482
// SEARCH
5583

5684
@GET("search/multi")
57-
suspend fun getTVShowAndMoviesByName(@Query("api_key") apiKey: String,
58-
@Query("query") query: String,
59-
@Query("page") page: Int) : ResultListTVShowOrMovies
85+
suspend fun getTVShowAndMoviesByName(
86+
@Query("api_key") apiKey: String,
87+
@Query("query") query: String,
88+
@Query("page") page: Int
89+
): ResultListTVShowOrMovies
6090

6191
@GET("search/movie")
62-
suspend fun getMoviesByName(@Query("api_key") apiKey: String,
63-
@Query("query") query: String,
64-
@Query("page") page: Int) : ResultMoviesEntity
92+
suspend fun getMoviesByName(
93+
@Query("api_key") apiKey: String,
94+
@Query("query") query: String,
95+
@Query("page") page: Int
96+
): ResultMoviesEntity
6597

6698
@GET("search/tv")
67-
suspend fun getTVByName(@Query("api_key") apiKey: String,
68-
@Query("query") query: String,
69-
@Query("page") page: Int) : ResultTVShowsEntity
99+
suspend fun getTVByName(
100+
@Query("api_key") apiKey: String,
101+
@Query("query") query: String,
102+
@Query("page") page: Int
103+
): ResultTVShowsEntity
70104

71105
@GET("search/person")
72-
suspend fun getPersonByName(@Query("api_key") apiKey: String,
73-
@Query("query") query: String,
74-
@Query("page") page: Int) : ResultPeopleEntity
106+
suspend fun getPersonByName(
107+
@Query("api_key") apiKey: String,
108+
@Query("query") query: String,
109+
@Query("page") page: Int
110+
): ResultPeopleEntity
75111
}

app/src/main/java/com/intive/tmdbandroid/datasource/network/Service.kt

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,13 @@ import com.intive.tmdbandroid.model.Screening
88
import com.intive.tmdbandroid.model.TVShow
99
import kotlinx.coroutines.flow.Flow
1010
import kotlinx.coroutines.flow.flow
11+
import okhttp3.MediaType.Companion.toMediaTypeOrNull
12+
import okhttp3.RequestBody.Companion.toRequestBody
13+
import org.json.JSONObject
14+
import com.intive.tmdbandroid.model.Session
15+
import kotlinx.coroutines.flow.collect
16+
17+
import timber.log.Timber
1118

1219
class Service {
1320
private val retrofit = RetrofitHelper.getRetrofit()
@@ -70,6 +77,56 @@ class Service {
7077
}
7178
}
7279

80+
suspend fun setMovieRating(movieID: Int, rating: Double,session:Session): Boolean {
81+
var retorno:Boolean = true
82+
if(rating < 0.5 || rating > 10){
83+
retorno=false
84+
}
85+
else{
86+
// Create JSON using JSONObject
87+
val jsonObject = JSONObject()
88+
jsonObject.put("value", rating)
89+
90+
// Convert JSONObject to String
91+
val jsonObjectString = jsonObject.toString()
92+
93+
// Create RequestBody ( We're not using any converter, like GsonConverter, MoshiConverter e.t.c, that's why we use RequestBody )
94+
val requestBody = jsonObjectString.toRequestBody("application/json".toMediaTypeOrNull())
95+
96+
retrofit.create(ApiClient::class.java).postMovieRanking(movieID,BuildConfig.API_KEY,session.guest_session_id,requestBody)
97+
}
98+
99+
return retorno
100+
}
101+
102+
suspend fun setTVShowRating(tvShowID: Int, rating: Double,session:Session): Boolean {
103+
var retorno:Boolean = true
104+
if(rating < 0.5 || rating > 10){
105+
retorno=false
106+
}
107+
else{
108+
// Create JSON using JSONObject
109+
val jsonObject = JSONObject()
110+
jsonObject.put("value", rating)
111+
112+
// Convert JSONObject to String
113+
val jsonObjectString = jsonObject.toString()
114+
115+
// Create RequestBody ( We're not using any converter, like GsonConverter, MoshiConverter e.t.c, that's why we use RequestBody )
116+
val requestBody = jsonObjectString.toRequestBody("application/json".toMediaTypeOrNull())
117+
118+
retrofit.create(ApiClient::class.java).postTVRanking(tvShowID,BuildConfig.API_KEY,session.guest_session_id,requestBody)
119+
}
120+
121+
return retorno
122+
}
123+
124+
fun getGuestSession():Flow<Session>{
125+
return flow {
126+
emit(retrofit.create(ApiClient::class.java).getNewGuestSession(BuildConfig.API_KEY))
127+
}
128+
}
129+
73130
fun getCombinedCredits(personID: Int): Flow<List<Screening>> {
74131
return flow {
75132
val result = retrofit.create(ApiClient::class.java).getCombinedCreditsByID(personID, BuildConfig.API_KEY)

0 commit comments

Comments
 (0)