Skip to content

Commit

Permalink
Merge pull request #26 from intive-FDV/feature/Rate_a_Screening
Browse files Browse the repository at this point in the history
Feature/rate a screening
  • Loading branch information
FranciscoBeccutiIntive authored Oct 13, 2021
2 parents a6f1b7e + 1622a5e commit 6128fc4
Show file tree
Hide file tree
Showing 50 changed files with 784 additions and 153 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/android.yml
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,6 @@ jobs:
# email body as text
body: ${{ github.job }} job in worflow ${{ github.workflow }} of ${{ github.repository }} has ${{ job.status }}
# comma-separated string, send email to
to: francisco.beccuti@intive.com
to: francisco.beccut@intive.com
# from email name
from: TMDB Team! GitHub Actions!
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,11 @@
"formatVersion": 1,
"database": {
"version": 1,
"identityHash": "016e4507f17862924f247000e7d4f1c4",
"identityHash": "320b71eb2503e195a8d56c17386e39c7",
"entities": [
{
"tableName": "ScreeningORMEntity",
"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`))",
"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`))",
"fields": [
{
"fieldPath": "id",
Expand Down Expand Up @@ -115,6 +115,18 @@
"columnName": "networks",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "my_rate",
"columnName": "my_rate",
"affinity": "REAL",
"notNull": true
},
{
"fieldPath": "my_favorite",
"columnName": "my_favorite",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
Expand All @@ -125,12 +137,62 @@
},
"indices": [],
"foreignKeys": []
},
{
"tableName": "SessionORMEntity",
"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)",
"fields": [
{
"fieldPath": "id",
"columnName": "id",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "success",
"columnName": "success",
"affinity": "INTEGER",
"notNull": true
},
{
"fieldPath": "guest_session_id",
"columnName": "guest_session_id",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "expires_at",
"columnName": "expires_at",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "status_message",
"columnName": "status_message",
"affinity": "TEXT",
"notNull": true
},
{
"fieldPath": "status_code",
"columnName": "status_code",
"affinity": "INTEGER",
"notNull": true
}
],
"primaryKey": {
"columnNames": [
"id"
],
"autoGenerate": true
},
"indices": [],
"foreignKeys": []
}
],
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '016e4507f17862924f247000e7d4f1c4')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '320b71eb2503e195a8d56c17386e39c7')"
]
}
}
11 changes: 9 additions & 2 deletions app/src/main/java/com/intive/tmdbandroid/datasource/local/Dao.kt
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package com.intive.tmdbandroid.datasource.local
import androidx.room.*
import androidx.room.Dao
import com.intive.tmdbandroid.entity.ScreeningORMEntity
import com.intive.tmdbandroid.entity.SessionORMEntity

@Dao
interface Dao{
Expand All @@ -18,6 +19,12 @@ interface Dao{
@Delete
suspend fun deleteFavorite(screeningORMEntity: ScreeningORMEntity)

@Query("SELECT EXISTS(SELECT * FROM ScreeningORMEntity WHERE id = :id)")
suspend fun existAsFavorite(id: Int): Boolean
@Query("SELECT * FROM ScreeningORMEntity WHERE id = :id")
suspend fun existAsFavorite(id: Int): ScreeningORMEntity

@Query("SELECT * FROM SessionORMEntity WHERE id = 1")
suspend fun existSession(): List<SessionORMEntity>

@Insert(onConflict = OnConflictStrategy.REPLACE)
suspend fun insertSession(sessionORMEntity: SessionORMEntity)
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,13 @@ import androidx.room.Database
import androidx.room.RoomDatabase
import androidx.room.TypeConverters
import com.intive.tmdbandroid.entity.ScreeningORMEntity
import com.intive.tmdbandroid.entity.SessionORMEntity
import com.intive.tmdbandroid.model.converter.GenreConverter
import com.intive.tmdbandroid.model.converter.IntConverter
import com.intive.tmdbandroid.model.converter.NetworkConverter

@Database(
entities = [(ScreeningORMEntity::class)],
entities = [ScreeningORMEntity::class,SessionORMEntity::class],
version = 1,
exportSchema = true,
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,38 +2,62 @@ package com.intive.tmdbandroid.datasource.network

import com.intive.tmdbandroid.entity.*
import com.intive.tmdbandroid.model.Movie
import com.intive.tmdbandroid.model.Session
import com.intive.tmdbandroid.model.TVShow
import retrofit2.http.GET
import retrofit2.http.Path
import retrofit2.http.Query
import okhttp3.RequestBody
import okhttp3.ResponseBody
import retrofit2.Response
import retrofit2.http.*

interface ApiClient {
// HOME
@GET("tv/popular")
suspend fun getPaginatedPopularTVShows(@Query("api_key") apiKey: String,
@Query("page") page: Int) : ResultTVShowsEntity
suspend fun getPaginatedPopularTVShows(
@Query("api_key") apiKey: String,
@Query("page") page: Int
): ResultTVShowsEntity

@GET("movie/popular")
suspend fun getPaginatedPopularMovies(@Query("api_key") apiKey: String,
@Query("page") page: Int) : ResultMoviesEntity
suspend fun getPaginatedPopularMovies(
@Query("api_key") apiKey: String,
@Query("page") page: Int
): ResultMoviesEntity

// DETAIL

@GET("tv/{tv_id}")
suspend fun getTVShowByID(@Path("tv_id") tvShowID: Int,
@Query("api_key") apiKey: String) : TVShow
suspend fun getTVShowByID(
@Path("tv_id") tvShowID: Int,
@Query("api_key") apiKey: String
): TVShow

@GET("movie/{movie_id}")
suspend fun getMovieByID(@Path("movie_id") movieID: Int,
@Query("api_key") apiKey: String) : Movie
suspend fun getMovieByID(
@Path("movie_id") movieID: Int,
@Query("api_key") apiKey: String
): Movie

@GET("tv/{tv_id}/videos")
suspend fun getTVShowVideos(@Path("tv_id") tvShowID: Int,
@Query("api_key") apiKey: String) : VideoEntity
suspend fun getTVShowVideos(
@Path("tv_id") tvShowID: Int,
@Query("api_key") apiKey: String
): VideoEntity

@GET("movie/{movie_id}/videos")
suspend fun getMovieVideos(@Path("movie_id") movieID: Int,
@Query("api_key") apiKey: String) : VideoEntity
suspend fun getMovieVideos(
@Path("movie_id") movieID: Int,
@Query("api_key") apiKey: String
): VideoEntity

@POST("movie/{movie_id}/rating")
suspend fun postMovieRanking(@Path("movie_id") query: Int, @Query("api_key") apiKey: String, @Query("guest_session_id") sessionId: String, @Body requestBody: RequestBody): Response<ResponseBody>

@POST("tv/{tv_id}/rating")
suspend fun postTVRanking(@Path("tv_id") query: Int, @Query("api_key") apiKey: String, @Query("guest_session_id") sessionId: String, @Body requestBody: RequestBody): Response<ResponseBody>

@GET("authentication/guest_session/new")
suspend fun getNewGuestSession(@Query("api_key") apiKey: String): Session


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

@GET("tv/{tv_id}/similar")
suspend fun getTVShowSimilar(@Path("tv_id") tvShowID: Int,
@Query("api_key") apiKey: String) : ResultTVShowsEntity
suspend fun getTVShowSimilar(
@Path("tv_id") tvShowID: Int,
@Query("api_key") apiKey: String
): ResultTVShowsEntity

@GET("movie/{movie_id}/similar")
suspend fun getMovieSimilar(@Path("movie_id") movieID: Int,
@Query("api_key") apiKey: String) : ResultMoviesEntity
suspend fun getMovieSimilar(
@Path("movie_id") movieID: Int,
@Query("api_key") apiKey: String
): ResultMoviesEntity

// SEARCH

@GET("search/multi")
suspend fun getTVShowAndMoviesByName(@Query("api_key") apiKey: String,
@Query("query") query: String,
@Query("page") page: Int) : ResultListTVShowOrMovies
suspend fun getTVShowAndMoviesByName(
@Query("api_key") apiKey: String,
@Query("query") query: String,
@Query("page") page: Int
): ResultListTVShowOrMovies

@GET("search/movie")
suspend fun getMoviesByName(@Query("api_key") apiKey: String,
@Query("query") query: String,
@Query("page") page: Int) : ResultMoviesEntity
suspend fun getMoviesByName(
@Query("api_key") apiKey: String,
@Query("query") query: String,
@Query("page") page: Int
): ResultMoviesEntity

@GET("search/tv")
suspend fun getTVByName(@Query("api_key") apiKey: String,
@Query("query") query: String,
@Query("page") page: Int) : ResultTVShowsEntity
suspend fun getTVByName(
@Query("api_key") apiKey: String,
@Query("query") query: String,
@Query("page") page: Int
): ResultTVShowsEntity

@GET("search/person")
suspend fun getPersonByName(@Query("api_key") apiKey: String,
@Query("query") query: String,
@Query("page") page: Int) : ResultPeopleEntity
suspend fun getPersonByName(
@Query("api_key") apiKey: String,
@Query("query") query: String,
@Query("page") page: Int
): ResultPeopleEntity
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,13 @@ import com.intive.tmdbandroid.model.Screening
import com.intive.tmdbandroid.model.TVShow
import kotlinx.coroutines.flow.Flow
import kotlinx.coroutines.flow.flow
import okhttp3.MediaType.Companion.toMediaTypeOrNull
import okhttp3.RequestBody.Companion.toRequestBody
import org.json.JSONObject
import com.intive.tmdbandroid.model.Session
import kotlinx.coroutines.flow.collect

import timber.log.Timber

class Service {
private val retrofit = RetrofitHelper.getRetrofit()
Expand Down Expand Up @@ -70,6 +77,56 @@ class Service {
}
}

suspend fun setMovieRating(movieID: Int, rating: Double,session:Session): Boolean {
var retorno:Boolean = true
if(rating < 0.5 || rating > 10){
retorno=false
}
else{
// Create JSON using JSONObject
val jsonObject = JSONObject()
jsonObject.put("value", rating)

// Convert JSONObject to String
val jsonObjectString = jsonObject.toString()

// Create RequestBody ( We're not using any converter, like GsonConverter, MoshiConverter e.t.c, that's why we use RequestBody )
val requestBody = jsonObjectString.toRequestBody("application/json".toMediaTypeOrNull())

retrofit.create(ApiClient::class.java).postMovieRanking(movieID,BuildConfig.API_KEY,session.guest_session_id,requestBody)
}

return retorno
}

suspend fun setTVShowRating(tvShowID: Int, rating: Double,session:Session): Boolean {
var retorno:Boolean = true
if(rating < 0.5 || rating > 10){
retorno=false
}
else{
// Create JSON using JSONObject
val jsonObject = JSONObject()
jsonObject.put("value", rating)

// Convert JSONObject to String
val jsonObjectString = jsonObject.toString()

// Create RequestBody ( We're not using any converter, like GsonConverter, MoshiConverter e.t.c, that's why we use RequestBody )
val requestBody = jsonObjectString.toRequestBody("application/json".toMediaTypeOrNull())

retrofit.create(ApiClient::class.java).postTVRanking(tvShowID,BuildConfig.API_KEY,session.guest_session_id,requestBody)
}

return retorno
}

fun getGuestSession():Flow<Session>{
return flow {
emit(retrofit.create(ApiClient::class.java).getNewGuestSession(BuildConfig.API_KEY))
}
}

fun getCombinedCredits(personID: Int): Flow<List<Screening>> {
return flow {
val result = retrofit.create(ApiClient::class.java).getCombinedCreditsByID(personID, BuildConfig.API_KEY)
Expand Down
Loading

0 comments on commit 6128fc4

Please sign in to comment.