Entry -> HistoryEntry

This commit is contained in:
DieMyst 2021-01-14 20:12:43 +03:00
parent cc7ef8b24e
commit ec2409648f
7 changed files with 17 additions and 17 deletions

View File

@ -9,7 +9,7 @@ name = "history"
path = "src/main.rs"
[dependencies]
fluence = { version = "0.2.16", features = ["logger"] }
fluence = { version = "0.2.18", features = ["logger"] }
anyhow = "1.0.31"
boolinator = "2.4.0"

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
use crate::entry::Entry;
use crate::history_entry::HistoryEntry;
use crate::Result;
use crate::results::{AddServiceResult, EmptyResult, GetEntriesServiceResult};
@ -86,8 +86,8 @@ impl From<Result<()>> for EmptyResult {
}
}
impl From<Result<Vec<Entry>>> for GetEntriesServiceResult {
fn from(result: Result<Vec<Entry>>) -> Self {
impl From<Result<Vec<HistoryEntry>>> for GetEntriesServiceResult {
fn from(result: Result<Vec<HistoryEntry>>) -> Self {
match result {
Ok(entries) => Self {
ret_code: crate::service_api::SUCCESS_CODE,

View File

@ -18,7 +18,7 @@ use fluence::fce;
#[fce]
#[derive(Clone, Debug, Default, Eq, PartialEq, Hash)]
pub struct Entry {
pub struct HistoryEntry {
pub id: u64,
pub body: String,
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
mod entry;
mod history_entry;
mod errors;
mod results;
mod service_api;

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
use crate::entry::Entry;
use crate::history_entry::HistoryEntry;
use fluence::fce;
#[fce]
@ -28,7 +28,7 @@ pub struct AddServiceResult {
pub struct GetEntriesServiceResult {
pub ret_code: i32,
pub err_msg: String,
pub entries: Vec<Entry>,
pub entries: Vec<HistoryEntry>,
}
#[fce]

View File

@ -16,7 +16,7 @@
use crate::storage_api::*;
use crate::entry::Entry;
use crate::history_entry::HistoryEntry;
use crate::results::{AddServiceResult, EmptyResult, GetEntriesServiceResult};
use crate::utils::u64_to_usize;
use crate::Result;
@ -38,7 +38,7 @@ fn add(entry: String, auth: bool) -> AddServiceResult {
// get all entries
#[fce]
fn get_all(auth: bool) -> GetEntriesServiceResult {
fn get_all_impl(auth: bool) -> Result<Vec<Entry>> {
fn get_all_impl(auth: bool) -> Result<Vec<HistoryEntry>> {
is_authenticated(auth, 0)?;
get_all_entries()
}
@ -48,7 +48,7 @@ fn get_all(auth: bool) -> GetEntriesServiceResult {
// get last entry
#[fce]
fn get_last(last: u64, auth: bool) -> GetEntriesServiceResult {
fn get_last_impl(last: u64, auth: bool) -> Result<Vec<Entry>> {
fn get_last_impl(last: u64, auth: bool) -> Result<Vec<HistoryEntry>> {
is_authenticated(auth, 1)?;
get_entries_with_limit(last)
}

View File

@ -14,7 +14,7 @@
* limitations under the License.
*/
use crate::entry::Entry;
use crate::history_entry::HistoryEntry;
use crate::Result;
use crate::utils::{u64_to_usize, usize_to_u64};
@ -31,7 +31,7 @@ pub struct Tetraplet {
#[derive(Clone, Debug, Default, Eq, PartialEq)]
pub struct Data {
entries: Vec<Entry>,
entries: Vec<HistoryEntry>,
tetraplet: Option<Tetraplet>,
}
@ -46,16 +46,16 @@ pub fn add_entry(entry: String) -> Result<u64> {
let id = usize_to_u64(data.entries.len())?;
data.entries.push(Entry { id, body: entry });
data.entries.push(HistoryEntry { id, body: entry });
return Ok(id);
}
pub fn get_entries_with_limit(limit: u64) -> Result<Vec<Entry>> {
pub fn get_entries_with_limit(limit: u64) -> Result<Vec<HistoryEntry>> {
let data = get_data().lock();
let limit = u64_to_usize(limit)?;
let entries: Vec<Entry> = data
let entries: Vec<HistoryEntry> = data
.entries
.to_vec()
.iter()
@ -67,7 +67,7 @@ pub fn get_entries_with_limit(limit: u64) -> Result<Vec<Entry>> {
Ok(entries)
}
pub fn get_all_entries() -> Result<Vec<Entry>> {
pub fn get_all_entries() -> Result<Vec<HistoryEntry>> {
let data = get_data().lock();
Ok(data.entries.to_vec())