mirror of
https://github.com/hmaxnl/SharpRSS.git
synced 2025-01-18 21:04:21 +01:00
Working on read page & database service
This commit is contained in:
parent
bd4d465089
commit
d638e763d4
|
@ -31,4 +31,7 @@ Global
|
|||
GlobalSection(SolutionProperties) = preSolution
|
||||
HideSolutionNode = FALSE
|
||||
EndGlobalSection
|
||||
GlobalSection(ExtensibilityGlobals) = postSolution
|
||||
SolutionGuid = {A31B46E9-37D1-4263-8681-617029BDBE66}
|
||||
EndGlobalSection
|
||||
EndGlobal
|
||||
|
|
|
@ -15,7 +15,7 @@ namespace SharpRss.Services
|
|||
internal DatabaseService()
|
||||
{
|
||||
_sqlConn = new SqliteConnection(_connectionString);
|
||||
//InitializeDb();
|
||||
InitializeDb();
|
||||
}
|
||||
private readonly SqliteConnection _sqlConn;
|
||||
private readonly string _connectionString = $"Data Source={Path.Combine(Environment.CurrentDirectory, "sharp_rss.sqlite")};";
|
||||
|
@ -24,14 +24,14 @@ namespace SharpRss.Services
|
|||
private readonly string _feedItemTable = "feed_item_data";
|
||||
|
||||
// Groups
|
||||
public async Task<HashSet<GroupModel>> GetGroupsAsync(string? groupName = null)
|
||||
public async Task<HashSet<GroupModel>> GetGroupsAsync(string? groupId = null)
|
||||
{
|
||||
_sqlConn.Open();
|
||||
using SqliteCommand cmd = new SqliteCommand(groupName != null ? $"SELECT * FROM {_groupTable} WHERE name=@name;" : $"SELECT * FROM {_groupTable}", _sqlConn)
|
||||
using SqliteCommand cmd = new SqliteCommand(groupId != null ? $"SELECT * FROM {_groupTable} WHERE id=@gId;" : $"SELECT * FROM {_groupTable}", _sqlConn)
|
||||
{
|
||||
Parameters =
|
||||
{
|
||||
new SqliteParameter("name", groupName)
|
||||
new SqliteParameter("gId", groupId)
|
||||
}
|
||||
};
|
||||
await using SqliteDataReader reader = await cmd.ExecuteReaderAsync();
|
||||
|
@ -255,6 +255,26 @@ namespace SharpRss.Services
|
|||
_sqlConn.Close();
|
||||
return result;
|
||||
}
|
||||
public async Task<GroupModel?> GetGroupFromFeeditemAsync(FeedItemModel feedItem)
|
||||
{
|
||||
GroupModel? result = null;
|
||||
_sqlConn.Open();
|
||||
using SqliteCommand cmd = new SqliteCommand($"SELECT * FROM {_groupTable} WHERE id=(SELECT group_id FROM {_feedTable} WHERE id=@fId)", _sqlConn)
|
||||
{
|
||||
Parameters =
|
||||
{
|
||||
new SqliteParameter ("fId", feedItem.Id)
|
||||
}
|
||||
};
|
||||
using SqliteDataReader reader = await cmd.ExecuteReaderAsync();
|
||||
HashSet<GroupModel>? groups = null;
|
||||
if (reader.Read())
|
||||
groups = await GetGroupsAsync(reader["group_id"].ToString());
|
||||
if (groups != null && groups.Any())
|
||||
result = groups.FirstOrDefault();
|
||||
_sqlConn.Close();
|
||||
return result;
|
||||
}
|
||||
|
||||
private async void InitializeDb()
|
||||
{
|
||||
|
|
|
@ -5,7 +5,12 @@ namespace WebSharpRSS.Models
|
|||
{
|
||||
public class FeedItemData : FeedItemModel
|
||||
{
|
||||
public FeedItemData()
|
||||
{
|
||||
FaviconUrl = string.Format(Caretaker.Settings["Paths"].GetString("FaviconResolveUrl"), Link.Remove(Link.IndexOf("http", StringComparison.Ordinal), Link.IndexOf("://", StringComparison.Ordinal) + 3));
|
||||
}
|
||||
public static FeedItemData? FromModel(FeedItemModel model) => Utilities.ConvertFrom<FeedItemData, FeedItemModel>(model);
|
||||
public string HexColor { get; set; }
|
||||
public string FaviconUrl { get; set; }
|
||||
}
|
||||
}
|
||||
|
|
|
@ -20,7 +20,7 @@ namespace WebSharpRSS.Models
|
|||
{
|
||||
FeedModel = feedModel;
|
||||
Title = feedModel.Title;
|
||||
FaviconUrl = string.Format(Caretaker.Settings["Paths"].GetString("FaviconResolveUrl"), feedModel.Url.Remove(feedModel.Url.IndexOf("http", StringComparison.Ordinal), feedModel.Url.IndexOf("://", StringComparison.Ordinal) + 3)); ;
|
||||
FaviconUrl = string.Format(Caretaker.Settings["Paths"].GetString("FaviconResolveUrl"), feedModel.Url.Remove(feedModel.Url.IndexOf("http", StringComparison.Ordinal), feedModel.Url.IndexOf("://", StringComparison.Ordinal) + 3));
|
||||
}
|
||||
public readonly GroupModel? GroupModel;
|
||||
public readonly FeedModel? FeedModel;
|
||||
|
|
54
WebSharpRSS/Pages/Read.razor
Normal file
54
WebSharpRSS/Pages/Read.razor
Normal file
|
@ -0,0 +1,54 @@
|
|||
@page "/read/{Id}"
|
||||
@using WebSharpRSS.Models;
|
||||
|
||||
<MudStack Spacing="2" Class="ml-2 mr-2">
|
||||
@if (isLoading)
|
||||
{
|
||||
<div class="justify-self: center">
|
||||
<MudProgressCircular Color="Color.Primary" Indeterminate="true" />
|
||||
<MudText>Loading...</MudText>
|
||||
</div>
|
||||
}
|
||||
else if (failed)
|
||||
{
|
||||
<MudAlert Severity="Severity.Error" Variant="Variant.Filled">Loading failed!</MudAlert>
|
||||
}
|
||||
else
|
||||
{
|
||||
foreach (var feedItemData in items)
|
||||
{
|
||||
<MudItem>
|
||||
<MudCard>
|
||||
<MudCardContent>
|
||||
<div style="justify-self: start;" class="d-flex align-center">
|
||||
@*@if (feedItemData.Icon != null)
|
||||
{
|
||||
<MudIcon Icon="@feedItemData.Icon" Style="@($"color:{feedItemData.CategoryColorHex}")" />
|
||||
}
|
||||
@if (feedItemData.FaviconUrl != null)
|
||||
{
|
||||
<MudImage Src="@feedItemData" ObjectFit="ObjectFit.Contain" />
|
||||
}*@
|
||||
<MudText Class="d-inline pa-2 align-center">@feedItemData.Title</MudText>
|
||||
</div>
|
||||
<MudText Typo="Typo.body2">@feedItemData.Description</MudText>
|
||||
<MudText Typo="Typo.overline">@feedItemData.PublishingDate.ToString()</MudText>
|
||||
</MudCardContent>
|
||||
</MudCard>
|
||||
</MudItem>
|
||||
}
|
||||
}
|
||||
</MudStack>
|
||||
|
||||
@code {
|
||||
[Parameter]
|
||||
public string Id { get; set; }
|
||||
HashSet<FeedItemData> items = new HashSet<FeedItemData>();
|
||||
bool isLoading = true;
|
||||
bool failed = false;
|
||||
|
||||
protected override void OnInitialized()
|
||||
{
|
||||
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user