Skip to content

Commit dc2af0c

Browse files
committed
clean
1 parent 57ecf18 commit dc2af0c

34 files changed

+1540
-1128
lines changed

.github/workflows/deploy.yml

Lines changed: 32 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,23 +14,51 @@ jobs:
1414
include:
1515
- image_name: valeevilja/cppbot:v1
1616
dockerfile: Dockerfile
17+
1718
steps:
1819
- name: Set up Docker Buildx
19-
uses: docker/setup-buildx-action@v3.0.0
20-
20+
uses: docker/setup-buildx-action@v3
21+
2122
- name: Login to Docker Hub
22-
uses: docker/login-action@v3.0.0
23+
uses: docker/login-action@v3
2324
with:
2425
username: ${{ secrets.DOCKERHUB_USERNAME }}
2526
password: ${{ secrets.DOCKERHUB_PASSWORD }}
27+
28+
- name: Extract metadata (tags, labels) for Docker
29+
id: meta
30+
uses: docker/metadata-action@v5
31+
with:
32+
images: ${{ matrix.image_name }}
33+
34+
- name: Build and push
35+
uses: docker/build-push-action@v5
36+
with:
37+
platforms: linux/amd64
38+
file: ${{ matrix.dockerfile }}
39+
push: true
40+
tags: ${{ steps.meta.outputs.tags }}
41+
labels: ${{ steps.meta.outputs.labels }}
2642

2743
deploy:
2844
name: Deploy to server
2945
runs-on: ubuntu-latest
3046
needs: build_and_push
3147
steps:
3248
- name: Checkout code
33-
uses: actions/checkout@v4.1.1
49+
uses: actions/checkout@v4
50+
- name: Copy infra files to server
51+
uses: appleboy/scp-action@v0.1.7
52+
with:
53+
host: ${{ secrets.HOST }}
54+
username: ${{ secrets.SERVER }}
55+
key: ${{ secrets.SERVER_SSH_KEY }}
56+
passphrase: ${{ secrets.PASSPHRASE }}
57+
source: "cppinfra/docker-compose.yml,cppinfra/swag_nginx.conf"
58+
target: ${{ secrets.DEPLOY_PATH }}
59+
overwrite: true
60+
strip_components: 1
61+
3462

3563
- name: executing remote ssh commands to deploy
3664
uses: appleboy/ssh-action@master

.gitignore

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,6 @@
1313

1414
build/
1515
data/
16-
cppinfra/
1716
.env
18-
todo.txt
17+
todo.txt
18+
/db_setup/db_mock_data.sql

botstaff/CMakeLists.txt

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,15 @@
11
add_library(func
2-
src/handlers/handlers.cpp
3-
src/handlers/user_handlers/userHandlers.cpp
4-
src/handlers/teacher_handlers/teacherHandlers.cpp
5-
src/handlers/teacher_handlers/createLessonHandlers.cpp
6-
src/handlers/user_handlers/userRegistration.cpp
7-
src/commands.cpp
8-
src/database/psql.cpp
9-
src/keyboards/keyboards.cpp
10-
src/keyboards/teacher_keyboards/teacherKeyboards.cpp
11-
src/keyboards/user_keyboards/userKeyboards.cpp
12-
src/utils.cpp
2+
src/handlers/Handlers.cpp
3+
src/handlers/user_handlers/UserHandlers.cpp
4+
src/handlers/teacher_handlers/TeacherHandlers.cpp
5+
src/handlers/teacher_handlers/CreateLessonHandlers.cpp
6+
src/handlers/user_handlers/UserRegistration.cpp
7+
src/Commands.cpp
8+
src/database/PSQL.cpp
9+
src/keyboards/Keyboards.cpp
10+
src/keyboards/teacher_keyboards/TeacherKeyboards.cpp
11+
src/keyboards/user_keyboards/UserKeyboards.cpp
12+
src/Utils.cpp
1313
src/database/CRUD.cpp
1414
)
1515

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
#ifndef commands_hpp
2-
#define commands_hpp
1+
#ifndef Commands_hpp
2+
#define Commands_hpp
33

44
#include <tgbot/tgbot.h>
55
#include <vector>
@@ -8,4 +8,4 @@ using namespace TgBot;
88

99
std::vector<BotCommand::Ptr> create_commands();
1010

11-
#endif /* HasPtr_h */
11+
#endif

botstaff/include/botstaff/database/CRUD.hpp

Lines changed: 33 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -8,18 +8,32 @@
88
#include <chrono>
99
#include <memory>
1010

11-
std::shared_ptr<BotUser> construct_user(const pqxx::row& res);
12-
std::shared_ptr<UserLesson> construct_user_lesson(const pqxx::row& res);
1311

1412
struct BotUser{
1513
BotUser(){}
1614
BotUser(long chat_id):chat_id(chat_id){}
15+
BotUser(const BotUser& other)
16+
{
17+
chat_id = other.chat_id;
18+
teacher = other.teacher;
19+
tgusername = other.tgusername;
20+
first_name = other.first_name;
21+
last_name = other.last_name;
22+
phone = other.phone;
23+
email = other.email;
24+
cls = other.cls;
25+
comment = other.comment;
26+
role = other.role;
27+
is_active = other.is_active;
28+
29+
}
1730
static std::shared_ptr<BotUser> get(long);
1831
static std::vector<std::shared_ptr<BotUser>> get_all(std::string&);
1932
static bool exists(long id);
2033
void update();
2134
void destroy();
2235
void create();
36+
2337
long chat_id{};
2438
long teacher{};
2539
std::string tgusername{};
@@ -47,12 +61,26 @@ struct UserLesson{
4761
std::chrono::floor<std::chrono::days>(now)
4862
};
4963
}
64+
UserLesson(const UserLesson& other)
65+
{
66+
id = other.id;
67+
date = other.date;
68+
time = other.time;
69+
teacher = other.teacher;
70+
pupil = other.pupil;
71+
objectives = other.objectives;
72+
comment_for_pupil = other.comment_for_pupil;
73+
comment_for_teacher = other.comment_for_teacher;
74+
is_paid = other.is_paid;
75+
}
76+
5077
static std::shared_ptr<UserLesson> get(int);
5178
static std::vector<std::shared_ptr<UserLesson>> get_all(std::string&);
5279
static bool exists(long id);
5380
void update();
5481
void destroy();
5582
int create();
83+
5684
int id{};
5785
std::chrono::year_month_day date{};
5886
std::string time{};
@@ -64,5 +92,7 @@ struct UserLesson{
6492
bool is_paid{};
6593
};
6694

95+
std::shared_ptr<BotUser> construct_user(const pqxx::row& res);
96+
std::shared_ptr<UserLesson> construct_user_lesson(const pqxx::row& res);
6797

68-
#endif /* HasPtr_h */
98+
#endif

botstaff/include/botstaff/database/psql.hpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
1-
#ifndef psql_h
2-
#define psql_h
1+
#ifndef PSQL_h
2+
#define PSQL_h
3+
34
#include <pqxx/pqxx>
45
#include <string>
56
#include <iostream>

botstaff/include/botstaff/handlers/handlers.hpp

Lines changed: 59 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -1,32 +1,77 @@
1-
#ifndef handlers_hpp
2-
#define handlers_hpp
1+
#ifndef Handlers_hpp
2+
#define Handlers_hpp
3+
34
#include <tgbot/tgbot.h>
45
#include <exception>
56
#include <functional>
6-
#include "botstaff/database/psql.hpp"
7-
#include "botstaff/utils.hpp"
8-
#include "botstaff/states.hpp"
9-
#include "botstaff/database/CRUD.hpp"
107
#include <unordered_map>
118

9+
#include "botstaff/database/PSQL.hpp"
10+
#include "botstaff/Utils.hpp"
11+
#include "botstaff/States.hpp"
12+
#include "botstaff/database/CRUD.hpp"
13+
1214
using namespace TgBot;
1315
using namespace std;
1416

1517

1618
namespace CommandHandlers
1719
{
18-
extern std::function<Message::Ptr (Message::Ptr)> startCommand(TgBot::Bot& bot);
19-
extern std::function<Message::Ptr (Message::Ptr)> cancelCommand(TgBot::Bot& bot);
20-
extern std::function<Message::Ptr (Message::Ptr)> helpCommand(TgBot::Bot& bot);
20+
class start_command{
21+
const TgBot::Bot& bot;
22+
public:
23+
start_command(const TgBot::Bot& _bot):bot(_bot){}
24+
Message::Ptr operator()(const Message::Ptr&);
25+
};
26+
27+
class cancel_command{
28+
const TgBot::Bot& bot;
29+
public:
30+
cancel_command(const TgBot::Bot& _bot):bot(_bot){}
31+
Message::Ptr operator()(const Message::Ptr&);
32+
};
33+
2134
};
2235

2336
namespace Handlers
2437
{
25-
extern std::function<Message::Ptr (Message::Ptr)> any_message_handler(TgBot::Bot& bot);
26-
extern std::function<Message::Ptr (CallbackQuery::Ptr)> calendar_handler(TgBot::Bot& bot);
27-
extern std::function<Message::Ptr (CallbackQuery::Ptr)> next_month_handler(TgBot::Bot& bot);
28-
extern std::function<Message::Ptr (CallbackQuery::Ptr)> calendar_day_handler(TgBot::Bot& bot);
29-
extern std::function<Message::Ptr (CallbackQuery::Ptr)> day_info_handler(TgBot::Bot& bot);
38+
39+
class any_message_handler{
40+
const TgBot::Bot& bot;
41+
public:
42+
any_message_handler(const TgBot::Bot& _bot):bot(_bot){}
43+
Message::Ptr operator()(const Message::Ptr&);
44+
};
45+
46+
class calendar_handler{
47+
const TgBot::Bot& bot;
48+
public:
49+
calendar_handler(const TgBot::Bot& _bot):bot(_bot){}
50+
Message::Ptr operator()(const CallbackQuery::Ptr&);
51+
};
52+
53+
class next_month_handler{
54+
const TgBot::Bot& bot;
55+
public:
56+
next_month_handler(const TgBot::Bot& _bot):bot(_bot){}
57+
Message::Ptr operator()(const CallbackQuery::Ptr&);
58+
};
59+
60+
61+
class calendar_day_handler{
62+
const TgBot::Bot& bot;
63+
public:
64+
calendar_day_handler(const TgBot::Bot& _bot):bot(_bot){}
65+
Message::Ptr operator()(const CallbackQuery::Ptr&);
66+
};
67+
68+
class day_info_handler{
69+
const TgBot::Bot& bot;
70+
public:
71+
day_info_handler(const TgBot::Bot& _bot):bot(_bot){}
72+
Message::Ptr operator()(const CallbackQuery::Ptr&);
73+
};
74+
3075
};
3176

3277
void startWebhook(TgBot::Bot& bot, std::string& webhookUrl);

botstaff/include/botstaff/handlers/teacher_handlers/createLessonHandlers.hpp

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,61 @@
1-
#ifndef createLessonHandlers_hpp
2-
#define createLessonHandlers_hpp
1+
#ifndef CreateLessonHandlers_hpp
2+
#define CreateLessonHandlers_hpp
33

44
#include <tgbot/tgbot.h>
5-
#include "botstaff/states.hpp"
65
#include <unordered_map>
76

7+
#include "botstaff/States.hpp"
8+
89
using namespace TgBot;
910
using std::unordered_map;
1011

1112
static unordered_map<long, DayForLesson> lessonState;
13+
1214
void clear_lesson_state(long chat_id);
15+
1316
Message::Ptr check_lesson_state(
14-
TgBot::Bot& bot,
17+
const TgBot::Bot& bot,
1518
const Message::Ptr message
1619
);
1720

1821
Message::Ptr lesson_time_handler(
19-
TgBot::Bot& bot,
22+
const TgBot::Bot& bot,
2023
const Message::Ptr message,
2124
bool update = false
2225
);
2326

2427
Message::Ptr lesson_objectives_handler(
25-
TgBot::Bot& bot,
28+
const TgBot::Bot& bot,
2629
const Message::Ptr message,
2730
bool update = false
2831
);
2932

3033
Message::Ptr lesson_comment_for_pupil_handler(
31-
TgBot::Bot& bot,
34+
const TgBot::Bot& bot,
3235
const Message::Ptr message,
3336
bool update = false
3437
);
3538

3639
Message::Ptr lesson_comment_for_teacher_handler(
37-
TgBot::Bot& bot,
40+
const TgBot::Bot& bot,
3841
const Message::Ptr message,
3942
bool update = false
4043
);
44+
4145
// Message::Ptr lesson_paid_handler(
4246
// TgBot::Bot& bot,
4347
// const Message::Ptr message,
4448
// bool update
4549
// );
4650

4751
Message::Ptr send_lesson_info_to_pupil(
48-
TgBot::Bot& bot,
52+
const TgBot::Bot& bot,
4953
std::string& message,
5054
long pupil_id
5155
);
5256

5357
Message::Ptr send_lesson_update_kb(
54-
TgBot::Bot& bot,
58+
const TgBot::Bot& bot,
5559
const Message::Ptr& message
5660
);
5761

0 commit comments

Comments
 (0)