Skip to content

Commit 25231f5

Browse files
committed
work
1 parent ec174e8 commit 25231f5

File tree

4 files changed

+13
-9
lines changed

4 files changed

+13
-9
lines changed

src/latest.cpp

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,9 @@ std::string LatestHandler::HandleRequestThrow(
2020
const userver::server::http::HttpRequest&,
2121
userver::server::request::RequestContext&) const {
2222
auto result = pg_->Execute(
23-
userver::storages::postgres::ClusterHostType::kSlave,
24-
"SELECT author, substring(text for $1::INTEGER) AS text_tr, ip_source "
23+
// userver::storages::postgres::ClusterHostType::kSlave,
24+
userver::storages::postgres::ClusterHostType::kMaster,
25+
"SELECT uuid, author, substring(text for $1::INTEGER) AS text_tr, ip_source "
2526
"FROM "
2627
"upastebin.texts ORDER BY created_at DESC LIMIT $2::INTEGER;",
2728
1000, 10);
@@ -31,6 +32,7 @@ std::string LatestHandler::HandleRequestThrow(
3132
for (const auto& item : result) {
3233
userver::formats::json::ValueBuilder response_item;
3334

35+
response_item["id"] = item["uuid"].As<std::string>();
3436
response_item["author"] = item["author"].As<std::string>();
3537
response_item["ip"] = item["ip_source"].As<std::string>();
3638
response_item["text"] = item["text_tr"].As<std::string>();

src/redirect.hpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ class RedirectHandler final : public userver::server::handlers::HttpHandlerBase
2222
userver::server::request::RequestContext&) const override {
2323
auto& response = request.GetHttpResponse();
2424
response.SetStatus(userver::server::http::HttpStatus::kTemporaryRedirect);
25-
response.SetHeader(userver::http::headers::kLocation, "/index.html");
25+
response.SetHeader(userver::http::headers::kLocation, "/r/index.html");
2626
return {};
2727
}
2828
};

www-data/index.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,8 +4,9 @@ fetch("../api/v1/latest")
44
})
55
.then(function (json) {
66
latest_html = "";
7-
for (const item in json.items) {
8-
latest_html += "<p>author: " + item["author"] + "</p>";
7+
for (const i in json.items) {
8+
const item = json.items[i];
9+
latest_html += "<p><a href=\"/" + item.id + "\">author: " + item.author + "</a></p>";
910
}
1011
document.getElementById("latest").innerHTML = latest_html;
1112
})

www-data/text.html

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,14 @@
11
<!DOCTYPE html>
22
<html>
33
<head>
4-
<meta charset="UTF8">
4+
<meta charset="UTF8">
55
<title>Pastebin (userver)</title>
6-
</head>
7-
<body>
6+
</head>
7+
<body>
88
<span id="text"></span>
99
<script type="text/javascript" src="r/text.js"></script>
1010
<span id="latest">unchanged</span>
1111
<script type="text/javascript" src="r/index.js"></script>
12-
</body>
12+
<a href="/">Создать новую заметку</a>
13+
</body>
1314
</html>

0 commit comments

Comments
 (0)