1
0
Fork 0
mirror of https://github.com/KingDuckZ/kamokan.git synced 2025-08-07 12:59:45 +00:00

Move some pastie fetching logic into Storage.

I'm implementing an "edit" page, so I also need to retrieve
a pastie from there and I want to minimize code duplication.
This commit is contained in:
King_DuckZ 2017-06-16 08:11:26 +01:00
parent 459f9682e0
commit c86df2de07
5 changed files with 64 additions and 37 deletions

View file

@ -62,7 +62,7 @@ namespace kamokan {
return submission_res;
}
Storage::RetrievedPastie FakeStorage::retrieve_pastie (const boost::string_view& parToken) const {
Storage::RetrievedPastie FakeStorage::retrieve_pastie (const boost::string_view& parToken, uint32_t parMaxTokenLen) const {
auto it_found = std::find_if(
m_submitted_pasties.begin(),
m_submitted_pasties.end(),
@ -70,10 +70,12 @@ namespace kamokan {
return pastie.token == parToken;
}
);
if (m_submitted_pasties.end() == it_found)
return RetrievedPastie {boost::optional<std::string>(), false};
if (parToken.size() > static_cast<std::size_t>(parMaxTokenLen))
return RetrievedPastie (boost::optional<std::string>(), false, false);
else if (m_submitted_pasties.end() == it_found)
return RetrievedPastie (boost::optional<std::string>(), false, true);
else
return RetrievedPastie {boost::make_optional(it_found->text), it_found->self_destruct};
return RetrievedPastie (boost::make_optional(it_found->text), it_found->self_destruct, true);
}
const std::vector<FakeStorage::SubmittedPastie>& FakeStorage::submitted_pasties() const {

View file

@ -52,7 +52,7 @@ namespace kamokan {
const std::string& parRemoteIP
) const override;
kamokan_virtual_testing Storage::RetrievedPastie retrieve_pastie (const boost::string_view& parToken) const override;
kamokan_virtual_testing Storage::RetrievedPastie retrieve_pastie (const boost::string_view& parToken, uint32_t parMaxTokenLen) const override;
const std::vector<SubmittedPastie>& submitted_pasties() const;