news_flash/models/
mappings.rs1use super::{Category, CategoryID, Feed, FeedID};
2use crate::schema::{category_mapping, feed_mapping};
3use serde::{Deserialize, Serialize};
4
5#[derive(Identifiable, Insertable, Associations, Queryable, Eq, PartialEq, Debug, Hash, Clone, Serialize, Deserialize)]
6#[diesel(primary_key(feed_id, category_id))]
7#[diesel(table_name = feed_mapping)]
8#[diesel(belongs_to(Feed, foreign_key = feed_id))]
9#[diesel(check_for_backend(SQLite))]
10pub struct FeedMapping {
11 pub feed_id: FeedID,
12 pub category_id: CategoryID,
13 pub sort_index: Option<i32>,
14}
15
16#[derive(Identifiable, Clone, Insertable, Associations, Queryable, Eq, PartialEq, Debug)]
19#[diesel(primary_key(category_id))]
20#[diesel(table_name = category_mapping)]
21#[diesel(belongs_to(Category, foreign_key = category_id))]
22#[diesel(check_for_backend(SQLite))]
23pub struct CategoryMapping {
24 pub parent_id: CategoryID,
25 pub category_id: CategoryID,
26 pub sort_index: Option<i32>,
27}
28
29pub enum UnifiedMapping {
32 Feed(FeedMapping),
33 Category(CategoryMapping),
34}
35
36impl UnifiedMapping {
37 pub fn sort_index(&self) -> Option<i32> {
38 match self {
39 Self::Feed(f) => f.sort_index,
40 Self::Category(c) => c.sort_index,
41 }
42 }
43
44 pub fn set_sort_index(&mut self, index: i32) {
45 match self {
46 Self::Feed(f) => f.sort_index = Some(index),
47 Self::Category(c) => c.sort_index = Some(index),
48 }
49 }
50}