Add database rating input

This commit is contained in:
2024-03-25 11:55:18 +01:00
parent 206e340012
commit 3a1fbd48d9
4 changed files with 14 additions and 10 deletions

View File

@@ -32,7 +32,7 @@ impl Database {
id INTEGER PRIMARY KEY,
title TEXT NOT NULL,
interpret_id INTEGER NOT NULL,
FOREIGN KEY("interpret_id") REFERENCES interpret (id),
FOREIGN KEY("interpret_id") REFERENCES interprets (id),
UNIQUE(title, interpret_id)
);
CREATE TABLE IF NOT EXISTS ratings (

View File

@@ -11,14 +11,15 @@ async fn main() {
let db = database::Database::new()
.await
.expect("Could not create database");
db.create_tables().await.unwrap();
let (usernumber, userrating) = userinterface::get_user_rating(&db).await.expect("Lala");
let track = player
let (interpret, song) = player
.get_interpret_and_track()
.expect("Could not read track");
println!("User: {usernumber} with rating: {userrating}: {track}");
db.create_tables().await.unwrap();
//db.add_user(1, "Janek").await.unwrap();
db.user_add_rating(usernumber, &interpret, &song, userrating)
.await
.expect("Can not add rating");
}

View File

@@ -11,13 +11,13 @@ impl MprisPlayer {
Ok(MprisPlayer { player_finder })
}
pub fn get_interpret_and_track(&self) -> Result<String> {
pub fn get_interpret_and_track(&self) -> Result<(String, String)> {
let player = self.player_finder.find_active()?;
let metadata = player.get_metadata()?;
if let (Some(title), Some(artists)) = (metadata.title(), metadata.artists()) {
let artist = artists.join(", ");
return Ok(format!("{artist} - {title}"));
return Ok((artist, title.to_owned()));
}
Err(anyhow!("Could not create interpret and title string"))
}

View File

@@ -7,7 +7,7 @@ use ratatui::layout::{Constraint, Layout};
use ratatui::style::{Color, Style};
use ratatui::widgets::{Block, Borders};
use ratatui::Terminal;
use std::io;
use std::{i64, io};
use tui_textarea::{Input, Key, TextArea};
use anyhow::Result;
@@ -72,7 +72,7 @@ fn validate_rating(textarea: &mut TextArea) -> bool {
}
}
pub async fn get_user_rating(db: &Database) -> Result<(String, String)> {
pub async fn get_user_rating(db: &Database) -> Result<(i64, i64)> {
let stdout = io::stdout();
let mut stdout = stdout.lock();
@@ -165,5 +165,8 @@ pub async fn get_user_rating(db: &Database) -> Result<(String, String)> {
)?;
term.show_cursor()?;
Ok((user_number, user_rating))
let user_id = user_number.parse::<i64>()?;
let rating_int = user_rating.parse::<i64>()?;
Ok((user_id, rating_int))
}