-
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.
Merge pull request #102 from Serveis-Neby/develop
Develop
- Loading branch information
Showing
68 changed files
with
3,712 additions
and
1,104 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,2 @@ | ||
.vscode/ | ||
.editorconfig |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,18 +1,25 @@ | ||
#pragma once | ||
|
||
#include <crow.h> | ||
#include <models/achievement_notification_model.h> | ||
#include <models/notification_model.h> | ||
#include <models/notification_service_model.h> | ||
#include <models/service_model.h> | ||
#include <models/user_achievement_model.h> | ||
#include <models/user_model.h> | ||
#include <utils/common.h> | ||
#include <utils/utils.h> | ||
#include <format> | ||
#include <map> | ||
#include <memory> | ||
#include <pqxx/pqxx> | ||
#include <string> | ||
|
||
class NotificationController { | ||
public: | ||
static void create_notification(pqxx::connection& db, const crow::request& req, crow::response& res, const std::string& service_id); | ||
static void handle_notification(pqxx::connection& db, const crow::request& req, crow::response& res, const std::string& notification_id); | ||
static void create_notification(pqxx::connection& db, const crow::request& req, crow::response& res); | ||
static void handle_notification(pqxx::connection& db, crow::request& req, crow::response& res, const std::string& notification_id); | ||
static void create_service_notification(pqxx::connection& db, const crow::request& req, crow::response& res); | ||
static void get_notification_service_by_id(pqxx::connection& db, const crow::request& req, crow::response& res, const std::string& service_id); | ||
static void get_notifications(pqxx::connection& db, const crow::request& req, crow::response& res); | ||
}; |
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,27 @@ | ||
#pragma once | ||
|
||
#include <crow.h> | ||
#include <format> | ||
#include <memory> | ||
#include <optional> | ||
#include <pqxx/pqxx> | ||
#include <string> | ||
#include <vector> | ||
|
||
// ** custom includes | ||
#include <models/rating_model.h> | ||
#include <models/service_model.h> | ||
#include <models/user_model.h> | ||
#include <utils/common.h> | ||
#include <utils/errors.h> | ||
#include <utils/utils.h> | ||
#include <utils/validations.h> | ||
// ** --------------------------------------------- | ||
|
||
class RatingController { | ||
public: | ||
static void create_rating(pqxx::connection& db, const crow::request& req, crow::response& res, const std::string& service_id); | ||
static void update_rating(pqxx::connection& db, const crow::request& req, crow::response& res, const std::string& rating_id); | ||
static void get_user_ratings(pqxx::connection& db, crow::response& res, const std::string& user_id); | ||
static void get_service_rating(pqxx::connection& db, crow::response& res, const std::string& service_id); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
#pragma once | ||
|
||
#include <crow.h> | ||
#include <models/user_achievement_model.h> | ||
#include <models/user_model.h> | ||
#include <utils/common.h> | ||
#include <utils/utils.h> | ||
#include <format> | ||
#include <memory> | ||
#include <pqxx/pqxx> | ||
#include <vector> | ||
#include <string> | ||
|
||
class UserAchievementController { | ||
public: | ||
static void get_user_achievements_self(pqxx::connection& db, crow::request& req, crow::response& res); | ||
static void claim_user_achievement(pqxx::connection& db, crow::request& req, crow::response& res, const std::string& arch_id); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
#pragma once | ||
|
||
#include <vector> | ||
#include <string> | ||
#include <sstream> | ||
|
||
std::string join_query_update(const std::vector<std::string>& elements, const std::string& delimiter); |
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,18 @@ | ||
|
||
#pragma once | ||
|
||
#include <crow.h> | ||
#include <db/connection_pool.h> | ||
#include <jwt-cpp/jwt.h> | ||
#include <utils/auth.h> | ||
#include <utils/common.h> | ||
#include <utils/utils.h> | ||
#include <memory> | ||
#include <utils/user_achievements_handler.h> | ||
|
||
struct HandleAchievements : crow::ILocalMiddleware { | ||
struct context {}; | ||
|
||
void before_handle(crow::request& req, crow::response& res, context& ctx); | ||
void after_handle(crow::request& req, crow::response& res, context& ctx); | ||
}; |
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,5 @@ | ||
#include <crow.h> | ||
#include <middlewares/handle_achievements.h> | ||
#include <middlewares/verify_jwt.h> | ||
|
||
using NebyApp = crow::App<VerifyJWT, HandleAchievements>; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
#pragma once | ||
|
||
#include <utils/errors.h> | ||
#include <ctime> | ||
#include <format> | ||
#include <memory> | ||
#include <pqxx/pqxx> | ||
#include <string> | ||
|
||
class AchievementModel { | ||
private: | ||
std::string _title; | ||
std::string _description; | ||
int _reward; | ||
|
||
public: | ||
std::string get_title() const; | ||
std::string get_description() const; | ||
int get_reward() const; | ||
|
||
AchievementModel(std::string title, std::string description, int reward); | ||
}; |
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,22 @@ | ||
#pragma once | ||
|
||
#include <utils/common.h> | ||
#include <utils/errors.h> | ||
#include <memory> | ||
#include <vector> | ||
|
||
class AchievementNotificationModel { | ||
private: | ||
std::string _id; | ||
std::string _achievement_user_id; | ||
std::string _notification_id; | ||
|
||
public: | ||
AchievementNotificationModel(std::string id, std::string achievement_user_id, std::string notification_id); | ||
|
||
std::string get_id() const; | ||
std::string get_achievement_user_id() const; | ||
std::string get_notification_id() const; | ||
|
||
static std::unique_ptr<AchievementNotificationModel> create_notification_service(pqxx::connection& db, const std::string& notification_id, const std::string& achievement_id, bool throw_when_null = false); | ||
}; |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,34 @@ | ||
#pragma once | ||
|
||
#include <models/achievement_notification_model.h> | ||
#include <models/notification_service_model.h> | ||
#include <utils/common.h> | ||
#include <utils/errors.h> | ||
#include <memory> | ||
#include <optional> | ||
#include <vector> | ||
|
||
class NotificationModel { | ||
private: | ||
std::string _id; | ||
std::string _sender_id; | ||
std::string _service_id; | ||
std::string _status; | ||
std::string _type; | ||
std::string _created_at; | ||
std::string _updated_at; | ||
std::optional<NotificationServiceModel> _notification_service; | ||
std::optional<AchievementNotificationModel> _achievement_notification; | ||
|
||
public: | ||
NotificationModel(std::string id, std::string sender_id, std::string service_id, std::string status, std::string created_at, std::string updated_at); | ||
NotificationModel(std::string id, std::string type, std::string created_at, std::string updated_at, std::optional<NotificationServiceModel> notification_service, std::optional<AchievementNotificationModel> achievement_notification); | ||
|
||
std::string get_id() const; | ||
std::string get_sender_id() const; | ||
std::string get_service_id() const; | ||
std::string get_status() const; | ||
std::string get_type() const; | ||
std::string get_created_at() const; | ||
std::string get_updated_at() const; | ||
std::optional<NotificationServiceModel> get_notification_service(); | ||
std::optional<AchievementNotificationModel> get_achievement_notification(); | ||
|
||
static std::unique_ptr<NotificationModel> create_notification(pqxx::connection& db, const std::string& sender_id, const std::string& service_id, const std::string& status = NotificationStatus::PENDING, bool throw_when_null = false); | ||
static std::unique_ptr<NotificationModel> create_notification(pqxx::connection& db, const std::string& type, bool throw_when_null = false); | ||
static std::unique_ptr<NotificationModel> get_notification_service_by_id(pqxx::connection& db, const std::string& sender_id, const std::string& service_id, bool throw_when_null = false); | ||
|
||
// * if the requester has already requested the service before, it returns true, otherwise false | ||
static bool is_requested(pqxx::connection& db, const std::string& sender_id); | ||
|
||
static std::unique_ptr<NotificationModel> handle_notification_status(pqxx::connection& db, const std::string& status, const std::string& notification_id, bool throw_when_null = false); | ||
|
||
static bool refused_notifications(pqxx::connection& db, const std::string& service_id, const std::string& notification_id); | ||
|
||
static std::unique_ptr<NotificationModel> get_notification_by_id(pqxx::connection& db, const std::string& id, bool throw_when_null = false); | ||
static std::vector<NotificationModel> get_notifications_self(pqxx::connection& db, const std::string& user_id, bool throw_when_null = false); | ||
}; |
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,36 @@ | ||
#pragma once | ||
|
||
#include <utils/common.h> | ||
#include <utils/errors.h> | ||
#include <memory> | ||
#include <vector> | ||
|
||
class NotificationServiceModel { | ||
private: | ||
std::string _id; | ||
std::string _sender_id; | ||
std::string _service_id; | ||
std::string _status; | ||
std::string _notification_id; | ||
|
||
public: | ||
NotificationServiceModel(std::string id, std::string sender_id, std::string service_id, std::string status, std::string notification_id); | ||
|
||
std::string get_id() const; | ||
std::string get_sender_id() const; | ||
std::string get_service_id() const; | ||
std::string get_status() const; | ||
std::string get_notification_id() const; | ||
|
||
static std::unique_ptr<NotificationServiceModel> create_notification_service(pqxx::connection& db, const std::string& notification_id, const std::string& sender_id, const std::string& service_id, const std::string& status = NotificationServicesStatus::PENDING, bool throw_when_null = false); | ||
|
||
static bool is_requested(pqxx::connection& db, const std::string& sender_id, const std::string& service_id, bool throw_when_null = false); | ||
|
||
static std::unique_ptr<NotificationServiceModel> handle_notification_status(pqxx::connection& db, const std::string& status, const std::string& notification_id, bool throw_when_null = false); | ||
|
||
static bool refused_notifications(pqxx::connection& db, const std::string& service_id, const std::string& notification_id, bool throw_when_null = false); | ||
|
||
static std::unique_ptr<NotificationServiceModel> get_notification_by_id(pqxx::connection& db, const std::string& id, bool throw_when_null = false); | ||
|
||
static std::vector<NotificationServiceModel> get_notifications_accepted_self(pqxx::connection& db, const std::string& sender_id, bool throw_when_null = false); | ||
}; |
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,37 @@ | ||
#pragma once | ||
|
||
#include <utils/common.h> | ||
#include <utils/errors.h> | ||
#include <format> | ||
#include <iostream> | ||
#include <memory> | ||
#include <optional> | ||
#include <pqxx/pqxx> | ||
#include <string> | ||
#include <vector> | ||
|
||
class RatingModel { | ||
private: | ||
std::string _id; | ||
std::string _service_id; | ||
int _rating; | ||
std::string _description; | ||
std::optional<std::string> _sender_id; | ||
|
||
public: | ||
RatingModel(std::string id, std::string service_id, int rating, std::string description); | ||
|
||
RatingModel(std::string id, std::string service_id, int rating, std::string description, std::optional<std::string> sender_id); | ||
|
||
std::string get_id() const; | ||
std::string get_service_id() const; | ||
int get_rating() const; | ||
std::string get_description() const; | ||
std::optional<std::string> get_sender_id() const; | ||
|
||
static std::unique_ptr<RatingModel> create_rating(pqxx::connection& db, const std::string& service_id, const int& rating, const std::string& description, bool throw_when_null = false); | ||
static bool update_rating(pqxx::connection& db, const std::string& rating_id, const int& rating, const std::string& description, bool throw_when_null = false); | ||
static std::vector<std::unique_ptr<RatingModel>> get_rating_by_user_id(pqxx::connection& db, const std::string& user_id, bool throw_when_null = false); | ||
static std::unique_ptr<RatingModel> get_rating_by_service_id(pqxx::connection& db, const std::string& service_id, bool throw_when_null = false); | ||
static std::unique_ptr<RatingModel> get_rating_by_id(pqxx::connection& db, const std::string& rating_id, bool throw_when_null = false); | ||
}; |
Oops, something went wrong.