Compare commits
10 Commits
675f953866
...
969bb0a0f7
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
969bb0a0f7 | ||
|
|
a07485cc9e | ||
|
|
bb97b81756 | ||
|
|
ed29fafb89 | ||
|
|
54c513b144 | ||
|
|
1d2a9290bb | ||
|
|
c778552b1a | ||
|
|
d048630941 | ||
|
|
4ee19174e5 | ||
|
|
bcb2223587 |
32
Cargo.lock
generated
@@ -110,6 +110,18 @@ version = "1.70.2"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a6cb138bb79a146c1bd460005623e142ef0181e3d0219cb493e02f7d08a35695"
|
||||
|
||||
[[package]]
|
||||
name = "itoa"
|
||||
version = "1.0.17"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "92ecc6618181def0457392ccd0ee51198e065e016d1d527a7ac1b6dc7c1f09d2"
|
||||
|
||||
[[package]]
|
||||
name = "memchr"
|
||||
version = "2.7.6"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "f52b00d39961fc5b2736ea853c9cc86238e165017a493d1d5c8eac6bdc4cc273"
|
||||
|
||||
[[package]]
|
||||
name = "once_cell_polyfill"
|
||||
version = "1.70.2"
|
||||
@@ -122,6 +134,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"clap",
|
||||
"serde",
|
||||
"serde_json",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
@@ -172,6 +185,19 @@ dependencies = [
|
||||
"syn",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "serde_json"
|
||||
version = "1.0.149"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "83fc039473c5595ace860d8c4fafa220ff474b3fc6bfdb4293327f1a37e94d86"
|
||||
dependencies = [
|
||||
"itoa",
|
||||
"memchr",
|
||||
"serde",
|
||||
"serde_core",
|
||||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "strsim"
|
||||
version = "0.11.1"
|
||||
@@ -215,3 +241,9 @@ checksum = "ae137229bcbd6cdf0f7b80a31df61766145077ddf49416a728b02cb3921ff3fc"
|
||||
dependencies = [
|
||||
"windows-link",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "zmij"
|
||||
version = "1.0.18"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1966f8ac2c1f76987d69a74d0e0f929241c10e78136434e3be70ff7f58f64214"
|
||||
|
||||
@@ -6,3 +6,4 @@ edition = "2024"
|
||||
[dependencies]
|
||||
clap = { version = "4.5.54", features = ["derive"] }
|
||||
serde = { version = "1.0.228", features = ["derive"] }
|
||||
serde_json = "1.0.149"
|
||||
|
||||
191
src/lib.rs
@@ -1,4 +1,191 @@
|
||||
// src/lib.rs
|
||||
|
||||
pub mod logic;
|
||||
pub use logic::*;
|
||||
use serde::{Serialize, Deserialize};
|
||||
use serde_json;
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, PartialEq)]
|
||||
enum Semester {
|
||||
#[default]
|
||||
Zimny,
|
||||
Letny
|
||||
}
|
||||
|
||||
impl fmt::Display for Semester {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Semester::Zimny => write!(f, "Zimny"),
|
||||
Semester::Letny => write!(f, "Letny"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, PartialEq, Eq, Hash, Copy, Clone)]
|
||||
enum TypPovinnosti {
|
||||
Povinny,
|
||||
PovinneVoliteny,
|
||||
#[default]
|
||||
Vyberovy,
|
||||
}
|
||||
|
||||
impl fmt::Display for TypPovinnosti {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
TypPovinnosti::Povinny => write!(f, "Povinny"),
|
||||
TypPovinnosti::PovinneVoliteny => write!(f, "PovinneVoliteny"),
|
||||
TypPovinnosti::Vyberovy => write!(f, "Vyberovy"),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize)]
|
||||
struct Predmet {
|
||||
kod: String,
|
||||
nazov: String,
|
||||
vyucujuci: Vec<String>,
|
||||
popis: String,
|
||||
semester: Semester,
|
||||
rocnik: u8,
|
||||
pocet_kreditov: u8,
|
||||
znamka: char,
|
||||
typ_povinnosti: TypPovinnosti
|
||||
}
|
||||
|
||||
impl fmt::Display for Predmet {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "({}, {}, {}, {}, {}, {}, {}, {}, {})",
|
||||
self.kod,
|
||||
self.nazov,
|
||||
self.vyucujuci.join(", "),
|
||||
self.popis,
|
||||
self.semester,
|
||||
self.rocnik,
|
||||
self.pocet_kreditov,
|
||||
self.znamka,
|
||||
self.typ_povinnosti
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize)]
|
||||
struct Index {
|
||||
predmety: Vec<Predmet>
|
||||
}
|
||||
|
||||
impl Index{
|
||||
pub fn nacitaj_zo_suboru(&self, cesta: &std::path::PathBuf) -> Option<Self> {
|
||||
let data = match std::fs::read_to_string(cesta) {
|
||||
Ok(x) => x,
|
||||
Err(_) => return None,
|
||||
};
|
||||
let vysledok = match serde_json::from_str(data.as_str()) {
|
||||
Ok(k) => k,
|
||||
Err(_) => return None,
|
||||
};
|
||||
Some(vysledok)
|
||||
}
|
||||
|
||||
pub fn uloz_do_suboru(&self, cesta_uloz: &std::path::PathBuf) -> bool {
|
||||
let str_data = match serde_json::to_string(&self) {
|
||||
Ok(x) => x,
|
||||
Err(_) => return false,
|
||||
};
|
||||
match std::fs::write(cesta_uloz, str_data) {
|
||||
Ok(_) => true,
|
||||
Err(_) => false,
|
||||
}
|
||||
}
|
||||
|
||||
pub fn pridaj_predmet2(&mut self, predmet: Predmet) -> Result<(), ()> {
|
||||
let mut je: bool;
|
||||
let var_name = self.predmety.iter().any(|x| x.kod == predmet.kod);
|
||||
|
||||
if var_name {
|
||||
return Err(());
|
||||
}
|
||||
self.predmety.push(predmet);
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn pridaj_predmet(&mut self, predmet: Predmet) -> Result<(), ()> {
|
||||
let mut je: bool;
|
||||
let var_name = self.predmety.iter().filter(|x| x.kod == predmet.kod).count();
|
||||
|
||||
if var_name > 0 {
|
||||
return Err(());
|
||||
} else {
|
||||
self.predmety.push(predmet);
|
||||
}
|
||||
Ok(())
|
||||
}
|
||||
|
||||
pub fn odstran_predmet(&mut self, kod: &str) -> Result<Predmet, ()> {
|
||||
if let Some(index) = self.predmety.iter().position(|x| x.kod == kod) {
|
||||
let odstranenie = self.predmety.remove(index);
|
||||
return Ok(odstranenie);
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn daj_predmet_podla_kodu(&self, kod: &str) -> Result<Option<&Predmet>, ()> {
|
||||
if let Some(vrat) = self.predmety.iter().find(|x| x.kod == kod) {
|
||||
return Ok(Some(vrat));
|
||||
} else {
|
||||
Err(())
|
||||
}
|
||||
}
|
||||
|
||||
pub fn daj_predmety_vyucujuceho(&self, menov: &str) -> Vec<&Predmet> {
|
||||
let vec: Vec<_> = self.predmety.iter().filter(|x| x.vyucujuci.contains(&menov.to_string())).collect();
|
||||
vec
|
||||
}
|
||||
|
||||
pub fn daj_predmety_podla_povinnosti(&self, tp: TypPovinnosti) -> Vec<&Predmet> {
|
||||
let vec: Vec<_> = self.predmety.iter().filter(|x| x.typ_povinnosti == tp).collect();
|
||||
vec
|
||||
}
|
||||
|
||||
pub fn formatuj_predmety_podla_znamky(&self, znamka: char) -> Vec<String> {
|
||||
self.predmety
|
||||
.iter()
|
||||
.filter(|p| p.znamka == znamka)
|
||||
.map(|p| format!("{}", p))
|
||||
.collect()
|
||||
}
|
||||
}
|
||||
|
||||
impl Predmet {
|
||||
pub fn new(
|
||||
kod: String,
|
||||
nazov: String,
|
||||
vyucujuci: Vec<String>,
|
||||
popis: String,
|
||||
semester: Semester,
|
||||
rocnik: u8,
|
||||
pocet_kreditov: u8,
|
||||
znamka: char,
|
||||
typ_povinnosti: TypPovinnosti
|
||||
) -> Self{
|
||||
return Self {
|
||||
kod: kod.to_string(),
|
||||
nazov: nazov.to_string(),
|
||||
vyucujuci,
|
||||
popis: popis.to_string(),
|
||||
semester,
|
||||
rocnik,
|
||||
pocet_kreditov,
|
||||
znamka,
|
||||
typ_povinnosti,
|
||||
}
|
||||
}
|
||||
}
|
||||
// kod: &str,
|
||||
// nazov: &str,
|
||||
// vyucujuci: Vec<String>,
|
||||
// popis: &str,
|
||||
// semester: Semester,
|
||||
// rocnik: u8,
|
||||
// pocet_kreditov: u8,
|
||||
// znamka: char,
|
||||
// typ_povinnosti: TypPovinnosti
|
||||
|
||||
72
src/logic.rs
@@ -1,72 +0,0 @@
|
||||
// src/logic.rs
|
||||
|
||||
use serde::{Deserialize, Serialize};
|
||||
use std::fmt;
|
||||
|
||||
#[derive(Default, Serialize, Deserialize, PartialEq)]
|
||||
enum Stav {
|
||||
#[default] Nova = 0,
|
||||
Pouzivana = 1,
|
||||
Poskodena = 2,
|
||||
Vyradena = 3,
|
||||
}
|
||||
|
||||
impl fmt::Display for Stav {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
match self {
|
||||
Stav::Nova => write!(f, "Nova"),
|
||||
Stav::Pouzivana => write!(f, "Pouzivana"),
|
||||
Stav::Poskodena => write!(f, "Poskodena"),
|
||||
Stav::Vyradena => write!(f, "Vyradena")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[derive(Default, Serialize, Deserialize)]
|
||||
struct Kniha {
|
||||
autori: Vec<String>,
|
||||
nazov: String,
|
||||
vydavatelstvo: String,
|
||||
zaner: String,
|
||||
pocet_stran: usize,
|
||||
isbn: String,
|
||||
rok_vydania: usize,
|
||||
je_pozicana: bool,
|
||||
stav_knihy: Stav,
|
||||
}
|
||||
|
||||
impl fmt::Display for Kniha {
|
||||
fn fmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {
|
||||
write!(f, "(Autori: {},
|
||||
Nazov: {},
|
||||
Vydavatelstvo: {},
|
||||
Zaner: {},
|
||||
Pocet stran: {},
|
||||
ISBN: {},
|
||||
Rok vydania: {},
|
||||
Je pozicana {},
|
||||
Stav knihy: {})",
|
||||
self.autori.join(", "),
|
||||
self.nazov,
|
||||
self.vydavatelstvo,
|
||||
self.zaner,
|
||||
self.pocet_stran,
|
||||
self.isbn,
|
||||
self.rok_vydania,
|
||||
self.je_pozicana,
|
||||
self.stav_knihy,
|
||||
)
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#[derive(Default, Serialize, Deserialize)]
|
||||
struct Kniznica {
|
||||
knihy: Vec<Kniha>
|
||||
}
|
||||
|
||||
impl Kniznica {
|
||||
// fn pridaj_knihu
|
||||
// fn odstran_knihu
|
||||
// fn daj_knihu_podla_isbn
|
||||
}
|
||||
BIN
zadanie/1.jpg
|
Before Width: | Height: | Size: 66 KiB After Width: | Height: | Size: 792 KiB |
BIN
zadanie/2.jpg
|
Before Width: | Height: | Size: 64 KiB After Width: | Height: | Size: 905 KiB |
BIN
zadanie/3.jpg
|
Before Width: | Height: | Size: 98 KiB After Width: | Height: | Size: 982 KiB |
BIN
zadanie/4.jpg
Normal file
|
After Width: | Height: | Size: 956 KiB |