1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
use anyhow::Result;
use mostro_core::message::{Action, Content, Message};
use nostr_sdk::prelude::*;
use uuid::Uuid;

use crate::util::send_order_id_cmd;

pub async fn execute_rate_user(
    order_id: &Uuid,
    rating: &u8,
    my_key: &Keys,
    mostro_key: PublicKey,
    client: &Client,
) -> Result<()> {
    // User rating
    let rating_content;

    // Check boundaries
    if let 1..=5 = *rating {
        rating_content = Content::RatingUser(*rating);
    } else {
        println!("Rating must be in the range 1 - 5");
        std::process::exit(0);
    }

    // Create rating message of counterpart
    let rate_message = Message::new_order(
        Some(*order_id),
        None,
        Action::RateUser,
        Some(rating_content),
    )
    .as_json()
    .unwrap();

    send_order_id_cmd(client, my_key, mostro_key, rate_message, true).await?;

    std::process::exit(0);
}