Skip to content
Open
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .config/StartSch.run.xml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
<component name="ProjectRunConfigurationManager">
<configuration default="false" name="StartSch" type="LaunchSettings" factoryName=".NET Launch Settings Profile">
<configuration default="false" name="StartSch" type="LaunchSettings" factoryName=".NET Launch Settings Profile" activateToolWindowBeforeRun="false">
<option name="LAUNCH_PROFILE_PROJECT_FILE_PATH" value="$PROJECT_DIR$/StartSch/StartSch.csproj" />
<option name="LAUNCH_PROFILE_TFM" value="net10.0" />
<option name="LAUNCH_PROFILE_NAME" value="http" />
Expand Down
178 changes: 178 additions & 0 deletions StartSch/Components/Pages/CollaborationPage.razor
Original file line number Diff line number Diff line change
@@ -0,0 +1,178 @@
@attribute [Authorize]
@page "/collaborations/{PageId:int}"
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@page "/collaboration-requests/{CollaborationRequestId:int}"

instead of having a per-Page list for collaboration requests, show all of them under AdminDashboardPage with a link to this page, where the user can accept or deny the request


@using StartSch.Services

@rendermode InteractiveServerWithoutPrerendering
@layout MainLayout
@inherits ResourcePage<Page>

@inject IDbContextFactory<Db> DbFactory
@inject InterestService InterestService
@inject AuthorizationService AuthorizationService

@if (!IsResourceAvailable(_page, AuthorizationService.CanCreatePost, out var status))
{
<ResourceUnavailable Status="@status"/>
return;
}

<main>
<article class="post">
<p class="display">
<h1>Oldal együttműködési kérelmei</h1>
</p>

@if (_items.Count == 0)
{
<p>Nincsenek együttműködési kérelmek.</p>
}
else
{
<ul class="collaboration-request-list"
style="list-style: none; padding: 0; display: flex; flex-direction: column; gap: 16px;">
@foreach (var request in _items)
{
<li style="border: 1px solid #ccc; border-radius: 12px; padding: 16px;">
@if (request is EventCollaborationRequest eventRequest)
{
<div style="font-weight: bold; margin-bottom: 8px;">
Esemény együttműködés
</div>
<div>
<a href="/events/@eventRequest.Event.Id">@eventRequest.Event.Title</a>
</div>
<div class="small text" style="margin-top: 4px;">
Szervező: @(eventRequest.Event.Categories.FirstOrDefault()?.Page.Name ?? eventRequest.Event.Categories.FirstOrDefault()?.Page.PekName ?? "Ismeretlen")
</div>
}
else if (request is PostCollaborationRequest postRequest)
{
<div style="font-weight: bold; margin-bottom: 8px;">
Poszt együttműködés
</div>
<div>
<a href="/posts/@postRequest.Post.Id">@postRequest.Post.Title</a>
</div>
<div class="small text" style="margin-top: 4px;">
Szerző: @(postRequest.Post.Categories.FirstOrDefault()?.Page.Name ?? postRequest.Post.Categories.FirstOrDefault()?.Page.PekName ?? "Ismeretlen")
</div>
}

<div style="display: flex; gap: 8px; margin-top: 12px">
<button type="button" @onclick="() => Accept(request)" class="small filled round">
Elfogadás
</button>
<button type="button" @onclick="() => Deny(request)"
class="small text round error standard">Elutasítás
Copy link
Copy Markdown
Member

@albi005 albi005 Mar 19, 2026

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

</button>
</div>
</li>
}
</ul>
}
</article>
</main>

@code {
private Page? _page;
private readonly List<CollaborationRequest> _items = [];
[Parameter] public int PageId { get; set; }

protected override async Task OnInitializedAsync()
{
await InterestService.LoadIndex;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this does not work as InterestService.LoadIndex attaches the entities to the scoped DbContext. You already load Categories below, so you can just remove this line

await using var db = await DbFactory.CreateDbContextAsync();

_page = await db.Pages.FirstOrDefaultAsync(g => g.Id == PageId);
if (_page == null)
return;

_items.AddRange(await db.EventCollaborationRequests
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

these 2 queries can be replaced by a single db.CollaborationRequests query

.Include(r => r.Event)
.ThenInclude(e => e.Categories)
.ThenInclude(c => c.Page)
.Where(r => r.PageId == PageId)
.ToListAsync());

_items.AddRange(await db.PostCollaborationRequests
.Include(r => r.Post)
.ThenInclude(p => p.Categories)
.ThenInclude(c => c.Page)
.Where(r => r.PageId == PageId)
.ToListAsync());
}

private async Task Accept(CollaborationRequest request)
{
await using var db = await DbFactory.CreateDbContextAsync();

var page = await db.Pages
.Include(p => p.Categories)
.FirstOrDefaultAsync(p => p.Id == PageId);

if (page == null || page.Categories.Count == 0) return;
var category = page.Categories[0];

if (request is EventCollaborationRequest evInfo)
{
var ev = await db.Events
.Include(e => e.Categories)
.FirstOrDefaultAsync(e => e.Id == evInfo.EventId);

if (ev != null)
{
if (!ev.Categories.Any(c => c.Id == category.Id))
ev.Categories.Add(category);

var toRemove = await db.EventCollaborationRequests
.FirstOrDefaultAsync(r => r.Id == evInfo.Id);
if (toRemove != null)
db.EventCollaborationRequests.Remove(toRemove);
}
}
else if (request is PostCollaborationRequest postInfo)
{
var post = await db.Posts
.Include(p => p.Categories)
.FirstOrDefaultAsync(p => p.Id == postInfo.PostId);

if (post != null)
{
if (!post.Categories.Any(c => c.Id == category.Id))
post.Categories.Add(category);

var toRemove = await db.PostCollaborationRequests
.FirstOrDefaultAsync(r => r.Id == postInfo.Id);
if (toRemove != null)
db.PostCollaborationRequests.Remove(toRemove);
}
}

await db.SaveChangesAsync();
_items.Remove(request);
}

private async Task Deny(CollaborationRequest request)
{
await using var db = await DbFactory.CreateDbContextAsync();

if (request is EventCollaborationRequest evInfo)
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to type-check, just do the query on db.CollaborationRequests

i'd also add a check here for whether the user has permission to do this

{
var toRemove = await db.EventCollaborationRequests
.FirstOrDefaultAsync(r => r.Id == evInfo.Id);
if (toRemove != null)
db.EventCollaborationRequests.Remove(toRemove);
}
else if (request is PostCollaborationRequest postInfo)
{
var toRemove = await db.PostCollaborationRequests
.FirstOrDefaultAsync(r => r.Id == postInfo.Id);
if (toRemove != null)
db.PostCollaborationRequests.Remove(toRemove);
}

await db.SaveChangesAsync();
_items.Remove(request);
}
}
Loading