Skip to content

New tests #48

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 33 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
b138f64
Commented all lines of code
aqerd Nov 15, 2024
606ba5b
Commented all lines of code ... with database
aqerd Nov 15, 2024
16af220
Minor fixes
aqerd Nov 16, 2024
c9519ea
Workflow update
aqerd Nov 16, 2024
de7f8ad
Workflow update
aqerd Nov 16, 2024
c66701e
Updated commented code
aqerd Nov 16, 2024
d965ed0
New method for pretty json output
aqerd Nov 16, 2024
7052149
New testing directly in main, logging in output
aqerd Nov 16, 2024
2b468a3
New try catch code status (feign 404)
aqerd Nov 16, 2024
d38eb90
Updated service
aqerd Nov 16, 2024
f762026
Added api key param to response
aqerd Nov 16, 2024
77535a2
Minor changes
aqerd Nov 16, 2024
43b64da
Minor fix
aqerd Nov 16, 2024
adf84ec
Minor fix
aqerd Nov 16, 2024
1fac2ea
New requests
aqerd Nov 16, 2024
f4410c7
New requests
aqerd Nov 16, 2024
fd4d1c9
Updated deserializers
aqerd Nov 16, 2024
d6fdf35
Updated playground
aqerd Nov 16, 2024
f46089b
Places changed
aqerd Nov 16, 2024
b1dc673
New commands added
aqerd Nov 16, 2024
3d71625
Service now final
aqerd Nov 16, 2024
5b137ed
Minor fix
aqerd Nov 16, 2024
32885af
Minor fixes + new commands keyboard
aqerd Nov 16, 2024
1bce648
New replies
aqerd Nov 16, 2024
2d68eb0
Renamed method
aqerd Nov 16, 2024
1df2981
Renamed method + added new commands to switch case
aqerd Nov 16, 2024
55612d1
Minor fixes
aqerd Nov 16, 2024
ca3d108
New 2 commands
aqerd Nov 16, 2024
8c66f64
Added reminder
aqerd Nov 16, 2024
11c442e
Tests from main removed
aqerd Nov 17, 2024
d70f86d
Case fixed
aqerd Nov 17, 2024
13e6353
Added new tests
aqerd Nov 17, 2024
f041f4b
Minor fixes
aqerd Nov 17, 2024
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
12 changes: 8 additions & 4 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@ name: Java Maven CI
on:
push:
branches:
- main
- '**'
paths:
- 'src/**'
pull_request:
branches:
- main
- '**'
paths:
- 'src/**'

jobs:
build:
build-and-test:
runs-on: ubuntu-latest

steps:
Expand All @@ -33,5 +37,5 @@ jobs:
- name: Build with Maven
run: mvn -B package --file pom.xml

- name: Run Tests
- name: Run clean tests
run: mvn clean test
7 changes: 4 additions & 3 deletions src/main/java/org/oopproject/Database.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,15 @@
package org.oopproject;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.io.FileInputStream;
import java.io.IOException;
import java.sql.*;
import java.util.Properties;

public class Database {
private Connection connection;
private static final Logger logger = LoggerFactory.getLogger(Database.class);

public Database() {
Properties properties = new Properties();
Expand All @@ -15,17 +18,15 @@ public Database() {
String username = properties.getProperty("db.username");
String password = properties.getProperty("db.password");
String connectionUrl = properties.getProperty("db.url");

connection = DriverManager.getConnection(connectionUrl, username, password);
System.out.println("Connected to database");
logger.info("Connected to database");
} catch (SQLException | IOException e) {
e.printStackTrace();
}
}

public void insertChatId(long chatId) {
String insertIdQuery = "INSERT INTO users (chatId) VALUES (?) ON DUPLICATE KEY UPDATE chatId=chatId";

try (PreparedStatement insertStatement = connection.prepareStatement(insertIdQuery)) {
insertStatement.setLong(1, chatId);
insertStatement.executeUpdate();
Expand Down
4 changes: 3 additions & 1 deletion src/main/java/org/oopproject/Main.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package org.oopproject;

import static org.oopproject.utils.Config.BOT_TOKEN;
import feign.FeignException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.telegram.telegrambots.meta.exceptions.TelegramApiException;
import org.telegram.telegrambots.longpolling.TelegramBotsLongPollingApplication;
import static org.oopproject.utils.Config.*;

public class Main {
private static final Logger logger = LoggerFactory.getLogger(Main.class);
Expand All @@ -21,6 +21,8 @@ public static void main(String[] args) {
} catch (FeignException e) {
if (e.status() == 401) {
logger.error("Invalid TMDB TOKEN");
} else if (e.status() == 404) {
logger.error("Could not find by user's parameters: {}", e.getMessage());
} else {
logger.error("Something wrong went with Feign: {}", e.getMessage());
}
Expand Down
138 changes: 83 additions & 55 deletions src/main/java/org/oopproject/SiteRequests.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import feign.Param;
import feign.RequestLine;
import org.oopproject.deserializers.FilmDeserializer;
import org.oopproject.deserializers.PersonDeserializer;
import org.oopproject.parameters.MovieParameters;
import org.oopproject.deserializers.AuthDeserializer;
import org.oopproject.deserializers.ListDeserializer;
Expand All @@ -12,65 +13,108 @@ public interface SiteRequests {
AuthDeserializer checkAuthStatus(@Param("api_key") String token);

@RequestLine("GET /movie/popular?api_key={api_key}")
ListDeserializer getPopularMovies(@Param("api_key") String token);
ListDeserializer<FilmDeserializer> getPopularMovies(@Param("api_key") String token);

@RequestLine("GET /movie/{id}?api_key={api_key}")
FilmDeserializer getMovieById(@Param("api_key") String token, @Param("id") String id);
FilmDeserializer getMovieById(@Param("api_key") String token, @Param("id") int id);

@RequestLine("GET /movie/{id}/similar?api_key={api_key}")
ListDeserializer<FilmDeserializer> getSimilarMovies(@Param("api_key") String token, @Param("id") int id);

@RequestLine("GET /movie/{id}/recommendations?api_key={api_key}")
ListDeserializer<FilmDeserializer> getRecommendationsForMovie(@Param("api_key") String token, @Param("id") int id);

@RequestLine("GET /search/movie" +
"?api_key={api_key}" +
"&query={query}" +
"&language={language}" +
"&page={page}" +
"&year={year}"
// +
// "&include_adult={adult}"
)
ListDeserializer<FilmDeserializer> searchMovie(@Param("api_key") String token,
@Param("query") String query,
@Param("language") String language,
@Param("page") int page,
@Param("year") String year
// ,
// @Param("adult") boolean adult
);

@RequestLine("GET /search/person?" +
"api_key={api_key}" +
"&query={query}" +
"&language={language}" +
"&page={page}"
// +
// "&include_adult={adult}"
)
ListDeserializer<PersonDeserializer> searchPerson(@Param("api_key") String token,
@Param("query") String query,
@Param("language") String language,
@Param("page") int page
// ,
// @Param("adult") boolean adult
);

@RequestLine("GET /discover/movie" +
"?api_key={api_key}" +
"&certification.lte={certification_lte}" +
"&certification_country={certification_country}" +
"&include_adult={include_adult}" +
// "&include_video={include_video}" +
"&language={language}" +
"&page={page}" +
// "&primary_release_year={primary_release_year}" +
// "&region={region}" +
"&release_date.gte={release_date_gte}" +
"&release_date.lte={release_date_lte}" +
"&sort_by={sort_by}" +
"&vote_average.gte={vote_average_gte}" +
"&vote_average.gte={vote_average_lte}" +
// "&watch_region={watch_region}" +
// "&with_cast={with_cast}" +
// "&with_companies={with_companies}" +
// "&with_crew={with_crew}" +
"&with_genres={with_genres}" +
"&with_origin_country={with_origin_country}" +
// "&with_original_language={with_original_language}" +
"&with_runtime.gte={with_runtime_gte}" +
// "&with_runtime.lte={with_runtime_lte}" +
// "&without_genres={without_genres}" +
"&year={year}")
ListDeserializer findMovie(@Param("api_key") String token,
@Param("certification_lte") String certificationLte,
@Param("certification_country") String certificationCountry,
@Param("include_adult") boolean includeAdult,
// @Param("include_video") boolean includeVideo,
@Param("language") String language,
@Param("page") int page,
// @Param("primary_release_year") int primaryReleaseYear,
// @Param("region") String region,
@Param("release_date_gte") String releaseDateGte,
@Param("release_date_lte") String releaseDateLte,
@Param("sort_by") String sortBy,
@Param("vote_average_gte") float voteAverageGte,
@Param("vote_average_lte") float voteAverageLte,
// @Param("watch_region") String watchRegion,
// @Param("with_cast") String withCast,
// @Param("with_companies") String withCompanies,
// @Param("with_crew") String withCrew,
@Param("with_genres") String withGenres,
@Param("with_origin_country") String withOriginCountry,
// @Param("with_original_language") String withOriginalLanguage,
@Param("with_runtime_gte") float withRuntimeGte,
// @Param("with_runtime_lte") float withRuntimeLte,
// @Param("without_genres") String withoutGenres,
@Param("year") int year
"&year={year}"
// +
// "&include_video={include_video}" +
// "&primary_release_year={primary_release_year}" +
// "&region={region}" +
// "&watch_region={watch_region}" +
// "&with_cast={with_cast}" +
// "&with_companies={with_companies}" +
// "&with_crew={with_crew}" +
// "&with_original_language={with_original_language}" +
// "&with_runtime.lte={with_runtime_lte}" +
// "&without_genres={without_genres}"
)
ListDeserializer<FilmDeserializer> findMovie(@Param("api_key") String token,
@Param("certification_lte") String certificationLte,
@Param("certification_country") String certificationCountry,
@Param("include_adult") boolean includeAdult,
@Param("language") String language,
@Param("page") int page,
@Param("release_date_gte") String releaseDateGte,
@Param("release_date_lte") String releaseDateLte,
@Param("sort_by") String sortBy,
@Param("vote_average_gte") float voteAverageGte,
@Param("vote_average_lte") float voteAverageLte,
@Param("with_genres") String withGenres,
@Param("with_origin_country") String withOriginCountry,
@Param("with_runtime_gte") float withRuntimeGte,
@Param("year") int year
// ,
// @Param("include_video") boolean includeVideo,
// @Param("primary_release_year") int primaryReleaseYear,
// @Param("region") String region,
// @Param("watch_region") String watchRegion,
// @Param("with_cast") String withCast,
// @Param("with_companies") String withCompanies,
// @Param("with_crew") String withCrew,
// @Param("with_original_language") String withOriginalLanguage,
// @Param("with_runtime_lte") float withRuntimeLte,
// @Param("without_genres") String withoutGenres,
);

default ListDeserializer findMovie(MovieParameters params) {
default ListDeserializer<FilmDeserializer> findMovie(MovieParameters params) {
return findMovie(
params.token(),
params.certificationLte(),
Expand All @@ -89,20 +133,4 @@ default ListDeserializer findMovie(MovieParameters params) {
params.year()
);
}

/*
@RequestLine("GET /movie/{id}/similar?api_key={api_key}")
ListDeserializer getSimilarMovies(@Param("api_key") String token, @Param("id") String id);

@RequestLine("GET /movie/{id}/recommendations?api_key={api_key}")
ListDeserializer getRecommendationsForMovie(@Param("api_key") String token, @Param("id") String id);

@RequestLine("GET /search/movie?query={query}&include_adult={adult}&language={language}&page={page}&year={year}")
ListDeserializer searchMovie(@Param("api_key") String token,
@Param("query") String query,
@Param("adult") boolean adult,
@Param("language") String language,
@Param("page") int page,
@Param("year") String year);
*/
}
Loading
Loading