-
Notifications
You must be signed in to change notification settings - Fork 2
Add collaboration requests #183
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 5 commits
2c50a22
876e1f9
8b6efa4
c6d055f
4cd61ff
2a1f8d8
be3ad75
2718db9
08a1846
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,178 @@ | ||
| @attribute [Authorize] | ||
| @page "/collaborations/{PageId:int}" | ||
|
|
||
| @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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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; | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this does not work as |
||
| 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 | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these 2 queries can be replaced by a single |
||
| .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) | ||
|
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. no need to type-check, just do the query on 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); | ||
| } | ||
| } | ||
There was a problem hiding this comment.
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
AdminDashboardPagewith a link to this page, where the user can accept or deny the request