Skip to content

Commit

Permalink
fixed yaml
Browse files Browse the repository at this point in the history
  • Loading branch information
Alexey-Sagaydak committed Nov 11, 2024
1 parent 262527e commit 79b4a19
Show file tree
Hide file tree
Showing 4 changed files with 62 additions and 51 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ jobs:
- name: Test 1. Install client
run: sudo dpkg -i ./client/http-client.deb
- name: Test 2. Test client
run: echo "6" | libhv-client
run: echo "7" | libhv-client

- name: Start server and database with Docker Compose
run: docker-compose up -d
Expand Down
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,12 @@
- Тело ответа: Пустое
- Описание: Редактирует данные пользователя по его идентификатору.

6. **Получение данных о погоде**
- Метод: GET
- Путь: /weather
- Тело ответа: JSON
- Описание: Возвращает информацию о погоде.

## Сборка и запуск

1. Склонируйте репозиторий:
Expand Down Expand Up @@ -87,6 +93,8 @@

```5. Edit user by ID``` - редактироване данных пользователя по его идентификатору; \*

```6. Exit``` - выход из программы.
```6. Get weather``` - редактироване данных пользователя по его идентификатору;

```7. Exit``` - выход из программы.

> \* - необходима авторизация (администратор может редактировать любое дело, а обычный пользователь только свое).
51 changes: 51 additions & 0 deletions client/src/client.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
#ifndef CLIENT_H
#define CLIENT_H

#include "HttpClient.h"
#include <iostream>
#include <string>

using json = nlohmann::json;

enum class TextColor {
BLACK,
RED,
GREEN,
YELLOW,
BLUE,
MAGENTA,
CYAN,
WHITE,
GRAY,
LIGHT_RED,
LIGHT_GREEN,
LIGHT_YELLOW,
LIGHT_BLUE,
LIGHT_MAGENTA,
LIGHT_CYAN,
LIGHT_GRAY,
DARK_RED,
DARK_GREEN,
DARK_YELLOW,
DARK_BLUE,
DARK_MAGENTA,
DARK_CYAN,
DARK_GRAY,
RESET
};

void printMenu();
void addUser(hv::HttpClient& httpClient);
void printUser(const std::string& jsonStr);
void printUser(json jsonData);
void printWeather(json jsonData);
void setTextColor(TextColor color);
void getAllUsersInfo(hv::HttpClient& httpClient);
void getUserById(hv::HttpClient& httpClient);
void deleteUserById(hv::HttpClient& httpClient);
void editUserById(hv::HttpClient& httpClient);
void getWeather(hv::HttpClient& httpClient);
std::string getBasicAuthHeader();
std::string base64_encode(const std::string &input);

#endif
50 changes: 1 addition & 49 deletions client/src/main.cpp
Original file line number Diff line number Diff line change
@@ -1,55 +1,10 @@
#include "HttpClient.h"
#include <iostream>
#include <string>

using json = nlohmann::json;

enum class TextColor {
BLACK,
RED,
GREEN,
YELLOW,
BLUE,
MAGENTA,
CYAN,
WHITE,
GRAY,
LIGHT_RED,
LIGHT_GREEN,
LIGHT_YELLOW,
LIGHT_BLUE,
LIGHT_MAGENTA,
LIGHT_CYAN,
LIGHT_GRAY,
DARK_RED,
DARK_GREEN,
DARK_YELLOW,
DARK_BLUE,
DARK_MAGENTA,
DARK_CYAN,
DARK_GRAY,
RESET
};
#include "client.h"

const std::string base64_chars =
"ABCDEFGHIJKLMNOPQRSTUVWXYZ"
"abcdefghijklmnopqrstuvwxyz"
"0123456789+/";

void printMenu();
void addUser(hv::HttpClient& httpClient);
void printUser(const std::string& jsonStr);
void printUser(json jsonData);
void printWeather(json jsonData);
void setTextColor(TextColor color);
void getAllUsersInfo(hv::HttpClient& httpClient);
void getUserById(hv::HttpClient& httpClient);
void deleteUserById(hv::HttpClient& httpClient);
void editUserById(hv::HttpClient& httpClient);
void getWeather(hv::HttpClient& httpClient);
std::string getBasicAuthHeader();
std::string base64_encode(const std::string &input);

int main() {
std::string serverAddress = "0.0.0.0:8080";

Expand Down Expand Up @@ -290,20 +245,17 @@ void addUser(hv::HttpClient& httpClient) {
std::cout << "Is admin? (1 for yes, 0 for no): ";
std::cin >> isAdmin;

// Создаем JSON для отправки на сервер
nlohmann::json requestData;
requestData["username"] = username;
requestData["password"] = password;
requestData["isAdmin"] = isAdmin;

// Создаем объект HttpRequest и добавляем заголовок Content-Type
HttpRequest req;
req.method = HTTP_POST;
req.url = "/user";
req.content_type = APPLICATION_JSON;
req.body = requestData.dump();

// Отправляем запрос на сервер
HttpResponse resp;
int ret = httpClient.send(&req, &resp);

Expand Down

0 comments on commit 79b4a19

Please sign in to comment.