Working on saving the api information to the database and then saving the token. After that work on fetching the songs from icarus and viewing them.
This commit is contained in:
@@ -0,0 +1,95 @@
|
||||
//
|
||||
// Created by brahmix on 10/12/19.
|
||||
//
|
||||
|
||||
#include "APIRepository.h"
|
||||
|
||||
#include <SQLiteCpp/Database.h>
|
||||
|
||||
namespace repository { namespace local {
|
||||
APIRepository::APIRepository()
|
||||
{
|
||||
m_tableName = apiInfoTable();
|
||||
}
|
||||
|
||||
|
||||
model::APIInfo APIRepository::retrieveAPIInfo(const std::string& path)
|
||||
{
|
||||
model::APIInfo apiInfo;
|
||||
try {
|
||||
const auto dbPath = pathOfDatabase(path);
|
||||
SQLite::Database db(dbPath, SQLite::OPEN_READONLY);
|
||||
|
||||
std::string queryString("SELECT * FROM ");
|
||||
queryString.append(m_tableName);
|
||||
queryString.append(" LIMIT 1");
|
||||
|
||||
SQLite::Statement query(db, queryString);
|
||||
|
||||
auto result = query.executeStep();
|
||||
apiInfo.uri = query.getColumn(1).getString();
|
||||
apiInfo.endpoint = query.getColumn(2).getString();
|
||||
apiInfo.version = query.getColumn(3).getInt();
|
||||
|
||||
return apiInfo;
|
||||
} catch (std::exception ex) {
|
||||
auto msg = ex.what();
|
||||
}
|
||||
|
||||
return apiInfo;
|
||||
}
|
||||
|
||||
|
||||
void APIRepository::createAPiInfoTable(const std::string& path)
|
||||
{
|
||||
try {
|
||||
const auto dbPath = pathOfDatabase(path);
|
||||
SQLite::Database db(dbPath, SQLite::OPEN_READWRITE);
|
||||
|
||||
std::string queryString("CREATE TABLE ");
|
||||
queryString.append(m_tableName);
|
||||
queryString.append(" (Id INTEGER PRIMARY KEY, Uri TEXT, Endpoint TEXT, Version INT");
|
||||
db.exec(queryString);
|
||||
} catch (std::exception& ex) {
|
||||
auto msg = ex.what();
|
||||
}
|
||||
}
|
||||
|
||||
void APIRepository::deleteAPIInfo(const model::APIInfo& apiInfo, const std::string& path)
|
||||
{
|
||||
try {
|
||||
const auto dbPath = pathOfDatabase(path);
|
||||
SQLite::Database db(dbPath, SQLite::OPEN_READWRITE);
|
||||
|
||||
std::string queryString("DELETE FROM ");
|
||||
queryString.append(m_tableName);
|
||||
|
||||
db.exec(queryString);
|
||||
} catch (std::exception& ex) {
|
||||
auto msg = ex.what();
|
||||
}
|
||||
}
|
||||
|
||||
void APIRepository::saveAPIInfo(const model::APIInfo& apiInfo, const std::string& path)
|
||||
{
|
||||
try {
|
||||
const auto dbPath = pathOfDatabase(path);
|
||||
SQLite::Database db(dbPath, SQLite::OPEN_READWRITE);
|
||||
std::string queryString("INSERT INTO ");
|
||||
queryString.append(m_tableName);
|
||||
queryString.append(" (Uri, Endpoint, Version) VALUES (?, ?, ?)");
|
||||
|
||||
SQLite::Statement query(db, queryString);
|
||||
query.bind(1, apiInfo.uri);
|
||||
query.bind(2, apiInfo.endpoint);
|
||||
query.bind(3, apiInfo.version);
|
||||
|
||||
query.exec();
|
||||
} catch (std::exception& ex) {
|
||||
auto msg = ex.what();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
std::string APIRepository::apiInfoTable() noexcept { return "APIInfo"; }
|
||||
}}
|
||||
@@ -0,0 +1,30 @@
|
||||
//
|
||||
// Created by brahmix on 10/12/19.
|
||||
//
|
||||
|
||||
#ifndef MEAR_APIREPOSITORY_H
|
||||
#define MEAR_APIREPOSITORY_H
|
||||
|
||||
#include <string>
|
||||
|
||||
#include "BaseRepository.h"
|
||||
#include "model/APIInfo.h"
|
||||
|
||||
namespace repository { namespace local {
|
||||
class APIRepository: public BaseRepository {
|
||||
public:
|
||||
APIRepository();
|
||||
|
||||
model::APIInfo retrieveAPIInfo(const std::string&);
|
||||
|
||||
void createAPiInfoTable(const std::string&);
|
||||
void deleteAPIInfo(const model::APIInfo&, const std::string&);
|
||||
void saveAPIInfo(const model::APIInfo&, const std::string&);
|
||||
private:
|
||||
//std::string apiInfoTable();
|
||||
std::string apiInfoTable() noexcept;
|
||||
};
|
||||
}}
|
||||
|
||||
|
||||
#endif //MEAR_APIREPOSITORY_H
|
||||
@@ -19,6 +19,7 @@ set(CMAKE_CXX_FLAGS_DEBUG "${CMAKE_CXX_FLAGS} -g -O0 -std=c++17")
|
||||
set(CMAKE_CXX_FLAGS_RELEASE "${CMAKE_CXX_FLAGS} -O3 -std=c++17 -DNDEBUG")
|
||||
|
||||
set (SOURCES
|
||||
APIRepository.cpp
|
||||
BaseRepository.cpp
|
||||
Demo.cpp
|
||||
SongRepository.cpp
|
||||
@@ -28,7 +29,9 @@ set (SOURCES
|
||||
)
|
||||
|
||||
set (HEADERS
|
||||
APIRepository.h
|
||||
BaseRepository.h
|
||||
model/APIInfo.h
|
||||
model/Song.h
|
||||
model/Token.h
|
||||
model/User.h
|
||||
|
||||
@@ -23,9 +23,11 @@
|
||||
#include <curl/curl.h>
|
||||
#include <sqlite3.h>
|
||||
|
||||
#include "model/APIInfo.h"
|
||||
#include "model/Song.h"
|
||||
#include "model/Token.h"
|
||||
#include "model/User.h"
|
||||
#include "APIRepository.h"
|
||||
#include "SongRepository.h"
|
||||
#include "Tok.h"
|
||||
#include "UserRepository.h"
|
||||
@@ -44,6 +46,7 @@ model::User retrieveCredentials(const std::string&);
|
||||
std::string fetchToken(const std::string&, const std::string&, const std::string&);
|
||||
|
||||
bool doesDatabaseExist(const std::string&);
|
||||
bool apiInformationExist(const std::string&);
|
||||
bool userCredentialExist(const std::string&);
|
||||
|
||||
void saveCredentials(const model::User&, const std::string&);
|
||||
@@ -150,6 +153,13 @@ bool doesDatabaseExist(const std::string& dataPath)
|
||||
return result;
|
||||
}
|
||||
|
||||
bool apiInformationExist(const std::string& dataPath)
|
||||
{
|
||||
repository::local::APIRepository apiRepo;
|
||||
|
||||
return apiRepo.isTableEmpty(dataPath);
|
||||
}
|
||||
|
||||
bool userCredentialExist(const std::string& dataPath)
|
||||
{
|
||||
repository::local::UserRepository userRepo;
|
||||
@@ -381,6 +391,19 @@ Java_com_example_mear_activities_LoginActivity_logUser(
|
||||
}
|
||||
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean
|
||||
JNICALL
|
||||
Java_com_example_mear_repositories_APIRepository_isAPIInfoTableEmpty(
|
||||
JNIEnv *env,
|
||||
jobject thisObj,
|
||||
jstring pathStr
|
||||
) {
|
||||
const std::string datapath = env->GetStringUTFChars(pathStr, nullptr);
|
||||
|
||||
return apiInformationExist(datapath);
|
||||
}
|
||||
|
||||
extern "C"
|
||||
JNIEXPORT jboolean
|
||||
JNICALL
|
||||
|
||||
@@ -19,7 +19,6 @@ namespace repository { namespace local {
|
||||
|
||||
model::User retrieveUserCredentials(const std::string&);
|
||||
|
||||
bool isEmpty(const std::string&);
|
||||
bool doesUserTableExist(const std::string&);
|
||||
|
||||
void createUserTable(const std::string&);
|
||||
|
||||
@@ -0,0 +1,20 @@
|
||||
//
|
||||
// Created by brahmix on 10/12/19.
|
||||
//
|
||||
|
||||
#ifndef MEAR_APIINFO_H
|
||||
#define MEAR_APIINFO_H
|
||||
|
||||
#include <string>
|
||||
|
||||
namespace model {
|
||||
class APIInfo
|
||||
{
|
||||
public:
|
||||
std::string uri;
|
||||
std::string endpoint;
|
||||
int version;
|
||||
};
|
||||
}
|
||||
|
||||
#endif //MEAR_APIINFO_H
|
||||
Reference in New Issue
Block a user