mirror of
https://github.com/GCMatters/hermes.git
synced 2026-02-04 21:50:12 +01:00
Compare commits
26 Commits
endpoints_
...
426288d728
| Author | SHA1 | Date | |
|---|---|---|---|
| 426288d728 | |||
| 72fbfe982f | |||
| 4be57c27d9 | |||
| b9a7ca08f5 | |||
| a83d8e963a | |||
|
|
9306c90ad6 | ||
| 239b588175 | |||
| 32027f7384 | |||
|
|
e47fd77333 | ||
|
|
2a8fff39c9 | ||
|
|
b194819b6e | ||
|
|
5da58ee030 | ||
|
|
42e468f28f | ||
|
|
740f8a955d | ||
| 89543558b0 | |||
| 39f483fdaa | |||
| 07702b93b1 | |||
| ace54fb4ef | |||
| 82936633f1 | |||
| ef7ec0fc33 | |||
| 4da3729edb | |||
| 5536a9ad7f | |||
| e0e6fa0573 | |||
| d4db4e2493 | |||
| 8ffb7f4eff | |||
|
|
69c508ef84 |
5
.editorconfig
Normal file
5
.editorconfig
Normal file
@@ -0,0 +1,5 @@
|
|||||||
|
[*]
|
||||||
|
end_of_line = crlf
|
||||||
|
charset = utf-8
|
||||||
|
trim_trailing_whitespace = true
|
||||||
|
insert_final_newline = true
|
||||||
@@ -6,7 +6,6 @@ namespace WebApp.DTOs;
|
|||||||
// Input values in JSON file to create event
|
// Input values in JSON file to create event
|
||||||
public record class EventCreateDto
|
public record class EventCreateDto
|
||||||
(
|
(
|
||||||
[Required] int? OrganisationId,
|
|
||||||
[Required][StringLength(50)] string Title,
|
[Required][StringLength(50)] string Title,
|
||||||
[StringLength(500)] string Description,
|
[StringLength(500)] string Description,
|
||||||
[Required][StringLength(100)] string Location,
|
[Required][StringLength(100)] string Location,
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ public record class EventDetailsDto
|
|||||||
(
|
(
|
||||||
int EventId,
|
int EventId,
|
||||||
[Required] int? OrganisationId,
|
[Required] int? OrganisationId,
|
||||||
|
[Required] string? OrganisationName,
|
||||||
[Required][StringLength(50)] string Title,
|
[Required][StringLength(50)] string Title,
|
||||||
[StringLength(500)] string Description,
|
[StringLength(500)] string Description,
|
||||||
[Required][StringLength(100)] string Location,
|
[Required][StringLength(100)] string Location,
|
||||||
|
|||||||
@@ -7,10 +7,11 @@ namespace WebApp.DTOs;
|
|||||||
public record class EventSearchDto
|
public record class EventSearchDto
|
||||||
(
|
(
|
||||||
int? OrganisationId,
|
int? OrganisationId,
|
||||||
string? Title,
|
string? TitleOrDescription,
|
||||||
string? Description,
|
|
||||||
string? Location,
|
string? Location,
|
||||||
DateTime? EventDate,
|
DateTime? EventDateFrom, // zakres daty od
|
||||||
|
DateTime? EventDateTo, // zakres daty do
|
||||||
ICollection<EventSkill>? EventSkills, // obecnie nie dotyczy
|
ICollection<EventSkill>? EventSkills, // obecnie nie dotyczy
|
||||||
ICollection<EventRegistration>? EventRegistrations // obecnie nie dotyczy
|
ICollection<EventRegistration>? EventRegistrations // obecnie nie dotyczy
|
||||||
|
|
||||||
);
|
);
|
||||||
|
|||||||
@@ -6,7 +6,6 @@ namespace WebApp.DTOs;
|
|||||||
// Input values in JSON file to update event
|
// Input values in JSON file to update event
|
||||||
public record class EventUpdateDto
|
public record class EventUpdateDto
|
||||||
(
|
(
|
||||||
[Required] int? OrganisationId,
|
|
||||||
[Required][StringLength(50)] string Title,
|
[Required][StringLength(50)] string Title,
|
||||||
[StringLength(500)] string Description,
|
[StringLength(500)] string Description,
|
||||||
[Required][StringLength(100)] string Location,
|
[Required][StringLength(100)] string Location,
|
||||||
|
|||||||
8
WebApp/DTOs/SingleSkillDto.cs
Normal file
8
WebApp/DTOs/SingleSkillDto.cs
Normal file
@@ -0,0 +1,8 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace WebApp.DTOs;
|
||||||
|
|
||||||
|
public record class SingleSkillDto
|
||||||
|
(
|
||||||
|
[Required] int Skill
|
||||||
|
);
|
||||||
9
WebApp/DTOs/SkillSummaryDto.cs
Normal file
9
WebApp/DTOs/SkillSummaryDto.cs
Normal file
@@ -0,0 +1,9 @@
|
|||||||
|
using System.ComponentModel.DataAnnotations;
|
||||||
|
|
||||||
|
namespace WebApp.DTOs;
|
||||||
|
|
||||||
|
public record class SkillSummaryDto
|
||||||
|
(
|
||||||
|
[Required] int SkillId,
|
||||||
|
[Required] string SkillName
|
||||||
|
);
|
||||||
@@ -11,4 +11,15 @@ namespace WebApp.DTOs
|
|||||||
[Required] DateTime CreatedAt,
|
[Required] DateTime CreatedAt,
|
||||||
[Required] bool isOrganisation
|
[Required] bool isOrganisation
|
||||||
);
|
);
|
||||||
|
|
||||||
|
public record class UserSummaryWithOrgIdDto
|
||||||
|
(
|
||||||
|
[Required] int UserId,
|
||||||
|
[Required] string Email,
|
||||||
|
[Required] string FirstName,
|
||||||
|
[Required] string LastName,
|
||||||
|
[Required] DateTime CreatedAt,
|
||||||
|
[Required] bool isOrganisation,
|
||||||
|
int? OrganisationId
|
||||||
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -35,7 +35,7 @@ namespace WebApp.Data
|
|||||||
.HasKey(es => new { es.EventId, es.SkillId });
|
.HasKey(es => new { es.EventId, es.SkillId });
|
||||||
|
|
||||||
builder.Entity<EventRegistration>()
|
builder.Entity<EventRegistration>()
|
||||||
.HasKey(er => new { er.VolunteerId, er.EventId });
|
.HasKey(er => new { er.UserId, er.EventId });
|
||||||
|
|
||||||
builder.Entity<MessageActivity>()
|
builder.Entity<MessageActivity>()
|
||||||
.HasKey(ma => new { ma.Sender, ma.Recipient });
|
.HasKey(ma => new { ma.Sender, ma.Recipient });
|
||||||
|
|||||||
@@ -1,7 +1,6 @@
|
|||||||
using Microsoft.AspNetCore.Http.HttpResults;
|
|
||||||
using Microsoft.EntityFrameworkCore;
|
|
||||||
using System.Security.Cryptography;
|
using System.Security.Cryptography;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
using WebApp.Data;
|
using WebApp.Data;
|
||||||
using WebApp.DTOs;
|
using WebApp.DTOs;
|
||||||
using WebApp.Entities;
|
using WebApp.Entities;
|
||||||
@@ -19,6 +18,7 @@ namespace WebApp.Endpoints
|
|||||||
var group = app.MapGroup("api/auth")
|
var group = app.MapGroup("api/auth")
|
||||||
.WithParameterValidation();
|
.WithParameterValidation();
|
||||||
|
|
||||||
|
// POST /api/auth/login
|
||||||
group.MapPost("/login", async (LoginDto dto, ApplicationDbContext context, GeneralUseHelpers guh) =>
|
group.MapPost("/login", async (LoginDto dto, ApplicationDbContext context, GeneralUseHelpers guh) =>
|
||||||
{
|
{
|
||||||
var user = await context.WebUsers.FirstOrDefaultAsync(u => u.Email == dto.Email);
|
var user = await context.WebUsers.FirstOrDefaultAsync(u => u.Email == dto.Email);
|
||||||
@@ -39,6 +39,7 @@ namespace WebApp.Endpoints
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// POST /api/auth/logout
|
||||||
group.MapPost("/logout", async (HttpContext httpContext, GeneralUseHelpers guh) =>
|
group.MapPost("/logout", async (HttpContext httpContext, GeneralUseHelpers guh) =>
|
||||||
{
|
{
|
||||||
var token = await guh.GetTokenFromHTTPContext(httpContext);
|
var token = await guh.GetTokenFromHTTPContext(httpContext);
|
||||||
@@ -55,6 +56,7 @@ namespace WebApp.Endpoints
|
|||||||
return Results.Ok(new { success = true });
|
return Results.Ok(new { success = true });
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// GET /api/auth/my_account
|
||||||
group.MapGet("/my_account", async (HttpContext httpContext, GeneralUseHelpers guh) =>
|
group.MapGet("/my_account", async (HttpContext httpContext, GeneralUseHelpers guh) =>
|
||||||
{
|
{
|
||||||
var token = await guh.GetTokenFromHTTPContext(httpContext);
|
var token = await guh.GetTokenFromHTTPContext(httpContext);
|
||||||
@@ -71,10 +73,14 @@ namespace WebApp.Endpoints
|
|||||||
return Results.Json(new {message = "No user found."}, statusCode: 404);
|
return Results.Json(new {message = "No user found."}, statusCode: 404);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Organisation? org = await guh.GetOrganisationFromUserId(user.UserId);
|
||||||
|
if (org is not null) return Results.Ok(user.ToUserSummaryWithOrgIdDto(org.OrganisationId));
|
||||||
return Results.Ok(user.ToUserSummaryDto());
|
return Results.Ok(user.ToUserSummaryDto());
|
||||||
|
|
||||||
})
|
})
|
||||||
.WithName(GetUserEndpointName);
|
.WithName(GetUserEndpointName);
|
||||||
|
|
||||||
|
// GET /api/auth/my_events
|
||||||
group.MapGet("/my_events", async (HttpContext httpContext, GeneralUseHelpers guh, ApplicationDbContext context) =>
|
group.MapGet("/my_events", async (HttpContext httpContext, GeneralUseHelpers guh, ApplicationDbContext context) =>
|
||||||
{
|
{
|
||||||
var token = await guh.GetTokenFromHTTPContext(httpContext);
|
var token = await guh.GetTokenFromHTTPContext(httpContext);
|
||||||
@@ -94,7 +100,7 @@ namespace WebApp.Endpoints
|
|||||||
if(!user.IsOrganisation)
|
if(!user.IsOrganisation)
|
||||||
{
|
{
|
||||||
var events = await context.EventRegistrations
|
var events = await context.EventRegistrations
|
||||||
.Where(er => er.VolunteerId == user.UserId)
|
.Where(er => er.UserId == user.UserId)
|
||||||
.Select(er => er.Event.ToEventSummaryNoErDto())
|
.Select(er => er.Event.ToEventSummaryNoErDto())
|
||||||
.ToListAsync();
|
.ToListAsync();
|
||||||
|
|
||||||
@@ -120,6 +126,110 @@ namespace WebApp.Endpoints
|
|||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// POST /api/auth/add_skill
|
||||||
|
group.MapPost("/add_skill", async (SingleSkillDto dto, HttpContext httpContext, ApplicationDbContext context, GeneralUseHelpers guh) =>
|
||||||
|
{
|
||||||
|
// Uzyskaj użytkownika z tokenu
|
||||||
|
Token? token = await guh.GetTokenFromHTTPContext(httpContext);
|
||||||
|
User? user = await guh.GetUserFromToken(token);
|
||||||
|
|
||||||
|
// Tylko wolontariusze powinni móc dodawać swoje skille
|
||||||
|
if (user == null || user.IsOrganisation) {
|
||||||
|
return Results.Json(new { message = "Unauthorized" }, statusCode: 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Szukamy skilla w bazie o ID takim, jak w otrzymanym DTO
|
||||||
|
Skill? skill = await context.Skills.FindAsync(dto.Skill);
|
||||||
|
if (skill is null)
|
||||||
|
{
|
||||||
|
return Results.Json(new { message = "Skill not found" }, statusCode: 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sprawdzamy, czy ten użytkownik nie ma już takiego skilla. Jeżeli ma, nie ma sensu dodawać go kilkukrotnie.
|
||||||
|
VolunteerSkill? vs = await context.VolunteerSkills.FirstOrDefaultAsync(v => v.UserId == user.UserId && v.SkillId == dto.Skill);
|
||||||
|
if (vs is null)
|
||||||
|
{
|
||||||
|
// Nie ma - zatem musimy dodać nowy VolunteerSkill do bazy
|
||||||
|
VolunteerSkill newVs = dto.ToVolunteerSkillEntity(user.UserId);
|
||||||
|
context.VolunteerSkills.Add(newVs);
|
||||||
|
await context.SaveChangesAsync();
|
||||||
|
|
||||||
|
} else
|
||||||
|
{
|
||||||
|
// Ma - (ta para UserId <-> SkillId już istnieje w bazie) użytkownik już ma ten skill
|
||||||
|
return Results.Json(new { message = "You already have this skill!" }, statusCode: 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Results.Json(new { message = "Skill added successfully!" }, statusCode: 201);
|
||||||
|
});
|
||||||
|
|
||||||
|
// POST /api/auth/remove_skill
|
||||||
|
group.MapPost("/remove_skill", async (SingleSkillDto dto, HttpContext httpContext, ApplicationDbContext context, GeneralUseHelpers guh) =>
|
||||||
|
{
|
||||||
|
// Uzyskaj użytkownika z tokenu
|
||||||
|
Token? token = await guh.GetTokenFromHTTPContext(httpContext);
|
||||||
|
User? user = await guh.GetUserFromToken(token);
|
||||||
|
|
||||||
|
// Tylko wolontariusze powinni móc usuwać swoje skille
|
||||||
|
if (user == null || user.IsOrganisation)
|
||||||
|
{
|
||||||
|
return Results.Json(new { message = "Unauthorized" }, statusCode: 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Szukamy skilla w bazie o ID takim, jak w otrzymanym DTO
|
||||||
|
Skill? skill = await context.Skills.FindAsync(dto.Skill);
|
||||||
|
if (skill is null)
|
||||||
|
{
|
||||||
|
return Results.Json(new { message = "Skill not found" }, statusCode: 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sprawdzamy, czy ten użytkownik ma już taki skill. Jeżeli nie ma, to nie ma sensu usuwać czegoś, czego nie ma.
|
||||||
|
VolunteerSkill? vs = await context.VolunteerSkills.FirstOrDefaultAsync(v => v.UserId == user.UserId && v.SkillId == dto.Skill);
|
||||||
|
if (vs is not null)
|
||||||
|
{
|
||||||
|
// Ma - zatem musimy usunąć otrzymany VolunteerSkill z bazy
|
||||||
|
VolunteerSkill newVs = dto.ToVolunteerSkillEntity(user.UserId);
|
||||||
|
|
||||||
|
await context.VolunteerSkills.Where(v => v.SkillId == dto.Skill)
|
||||||
|
.ExecuteDeleteAsync();
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Nie ma - (ta para UserId <-> SkillId nie istnieje w bazie). Zwracamy błąd.
|
||||||
|
return Results.Json(new { message = "You don't have this skill" }, statusCode: 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Results.Json(new { message = "Skill deleted successfully!" }, statusCode: 201);
|
||||||
|
});
|
||||||
|
|
||||||
|
// GET /api/auth/skills
|
||||||
|
group.MapGet("/skills", async (HttpContext httpContext, ApplicationDbContext context, GeneralUseHelpers guh) =>
|
||||||
|
{
|
||||||
|
// Uzyskaj użytkownika z tokenu
|
||||||
|
Token? token = await guh.GetTokenFromHTTPContext(httpContext);
|
||||||
|
User? user = await guh.GetUserFromToken(token);
|
||||||
|
|
||||||
|
// Sprawdź, czy użytkownik istnieje i nie jest organizacją
|
||||||
|
if (user == null || user.IsOrganisation)
|
||||||
|
{
|
||||||
|
return Results.Json(new { message = "Unauthorized" }, statusCode: 401);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Pobierz skille wolontariusza
|
||||||
|
var skills = await context.VolunteerSkills
|
||||||
|
.Where(vs => vs.UserId == user.UserId)
|
||||||
|
.Include(vs => vs.Skill)
|
||||||
|
.Select(vs => new
|
||||||
|
{
|
||||||
|
skillId = vs.Skill.SkillId,
|
||||||
|
skillName = vs.Skill.Name
|
||||||
|
})
|
||||||
|
.ToListAsync();
|
||||||
|
|
||||||
|
return Results.Json(skills);
|
||||||
|
});
|
||||||
|
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
using Microsoft.AspNetCore.Http;
|
using Microsoft.AspNetCore.Http;
|
||||||
using Microsoft.EntityFrameworkCore;
|
using Microsoft.EntityFrameworkCore;
|
||||||
using WebApp.Data;
|
using WebApp.Data;
|
||||||
using WebApp.DTOs;
|
using WebApp.DTOs;
|
||||||
@@ -19,12 +19,28 @@ namespace WebApp.Endpoints
|
|||||||
// GET /events
|
// GET /events
|
||||||
group.MapGet("/",
|
group.MapGet("/",
|
||||||
async (ApplicationDbContext dbContext, HttpContext httpContext) =>
|
async (ApplicationDbContext dbContext, HttpContext httpContext) =>
|
||||||
await dbContext.Events
|
{
|
||||||
.Include(Eve => Eve.Organisation)
|
|
||||||
.OrderByDescending(Eve => Eve.EventId)
|
var sort = httpContext.Request.Query["sort"].ToString();
|
||||||
.Select(Eve => Eve.ToEventSummaryDto()) //EventSummaryDto
|
IOrderedQueryable<Event> res;
|
||||||
.AsNoTracking()
|
var r = dbContext.Events
|
||||||
.ToListAsync());
|
.Include(Eve => Eve.Organisation);
|
||||||
|
|
||||||
|
if (sort is not null && sort.ToUpper() == "ASC")
|
||||||
|
{
|
||||||
|
res = r.OrderBy(Eve => Eve.EventId);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
res = r.OrderByDescending(Eve => Eve.EventId);
|
||||||
|
}
|
||||||
|
|
||||||
|
return await res
|
||||||
|
.Select(Eve => Eve.ToEventSummaryDto()) //EventSummaryDto
|
||||||
|
.AsNoTracking()
|
||||||
|
.ToListAsync();
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
// GET /events/1
|
// GET /events/1
|
||||||
group.MapGet("/{id}",
|
group.MapGet("/{id}",
|
||||||
@@ -42,6 +58,10 @@ namespace WebApp.Endpoints
|
|||||||
// to zwróć także EventRegistrations. W przeciwnym razie usuń to pole
|
// to zwróć także EventRegistrations. W przeciwnym razie usuń to pole
|
||||||
// przed jego wysłaniem!
|
// przed jego wysłaniem!
|
||||||
if (org is null || org.OrganisationId != Eve.OrganisationId) Eve.EventRegistrations = [];
|
if (org is null || org.OrganisationId != Eve.OrganisationId) Eve.EventRegistrations = [];
|
||||||
|
|
||||||
|
// DLACZEGO?
|
||||||
|
Eve.Organisation = await guhf.GetOrganisationFromId(Eve.OrganisationId);
|
||||||
|
|
||||||
EventDetailsDto EveDto = Eve.ToEventDetailsDto();
|
EventDetailsDto EveDto = Eve.ToEventDetailsDto();
|
||||||
|
|
||||||
return Results.Ok(EveDto); //EventDetailsDto
|
return Results.Ok(EveDto); //EventDetailsDto
|
||||||
@@ -58,16 +78,10 @@ namespace WebApp.Endpoints
|
|||||||
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||||
if (org is null) return Results.Unauthorized();
|
if (org is null) return Results.Unauthorized();
|
||||||
|
|
||||||
|
// dodajemy id organizacji z tokenu
|
||||||
Event Eve = newEvent.ToEntity();
|
Event Eve = newEvent.ToEntity();
|
||||||
|
|
||||||
// Wyzeruj EventRegistrations, ponieważ nie są to dane,
|
|
||||||
// które powinniśmy przyjmować bez zgody wolontariuszy!
|
|
||||||
Eve.EventRegistrations = [];
|
|
||||||
Eve.OrganisationId = org.OrganisationId;
|
Eve.OrganisationId = org.OrganisationId;
|
||||||
|
|
||||||
// Na wszelki wypadek, gdyby użytkownik wciskał nam kit :D
|
|
||||||
if (newEvent.OrganisationId is not null && newEvent.OrganisationId != org.OrganisationId) return Results.StatusCode(418);
|
|
||||||
|
|
||||||
dbContext.Events.Add(Eve);
|
dbContext.Events.Add(Eve);
|
||||||
await dbContext.SaveChangesAsync();
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
@@ -81,12 +95,12 @@ namespace WebApp.Endpoints
|
|||||||
group.MapPut("/{id}",
|
group.MapPut("/{id}",
|
||||||
async (int id, EventUpdateDto updatedEvent, ApplicationDbContext dbContext, GeneralUseHelpers guhf, HttpContext httpContext) =>
|
async (int id, EventUpdateDto updatedEvent, ApplicationDbContext dbContext, GeneralUseHelpers guhf, HttpContext httpContext) =>
|
||||||
{
|
{
|
||||||
|
|
||||||
// Uzyskaj organizację z tokenu
|
// Uzyskaj organizację z tokenu
|
||||||
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||||
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||||
if (org is null) return Results.Unauthorized();
|
if (org is null) return Results.Unauthorized();
|
||||||
|
|
||||||
|
Console.Write(org.OrganisationId);
|
||||||
var existingEvent = await dbContext.Events.FindAsync(id);
|
var existingEvent = await dbContext.Events.FindAsync(id);
|
||||||
if (existingEvent is null)
|
if (existingEvent is null)
|
||||||
{
|
{
|
||||||
@@ -97,15 +111,11 @@ namespace WebApp.Endpoints
|
|||||||
// do zmodyfikowania tego (EventId = id) eventu.
|
// do zmodyfikowania tego (EventId = id) eventu.
|
||||||
if (org.OrganisationId != existingEvent.OrganisationId) return Results.StatusCode(403);
|
if (org.OrganisationId != existingEvent.OrganisationId) return Results.StatusCode(403);
|
||||||
|
|
||||||
// Nadpisz organisationId (obecne w updatedEvent,
|
var originalOrgId = existingEvent.OrganisationId;
|
||||||
// lecz nie sprawdzane poniżej) na to, co odczytaliśmy
|
|
||||||
// do existingEvent.
|
|
||||||
// ... trzeba by było tworzyć obiekt od nowa, zamiast tego po prostu zwróćmy błąd.
|
|
||||||
if (existingEvent.OrganisationId != updatedEvent.OrganisationId) return Results.StatusCode(403);
|
|
||||||
|
|
||||||
dbContext.Entry(existingEvent)
|
dbContext.Entry(existingEvent)
|
||||||
.CurrentValues
|
.CurrentValues
|
||||||
.SetValues(updatedEvent.ToEntity(id));
|
.SetValues(updatedEvent.ToEntity(id));
|
||||||
|
existingEvent.OrganisationId = originalOrgId;
|
||||||
|
|
||||||
dbContext.Entry(existingEvent)
|
dbContext.Entry(existingEvent)
|
||||||
.Collection(Eve => Eve.EventRegistrations)
|
.Collection(Eve => Eve.EventRegistrations)
|
||||||
@@ -124,7 +134,7 @@ namespace WebApp.Endpoints
|
|||||||
// Uzyskaj organizację z tokenu
|
// Uzyskaj organizację z tokenu
|
||||||
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||||
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||||
if (org is null) return Results.StatusCode(403);
|
if (org is null) return Results.Unauthorized();
|
||||||
|
|
||||||
// Sprawdź, czy organizacja ma prawo
|
// Sprawdź, czy organizacja ma prawo
|
||||||
// do usunięcia tego (EventId = id) eventu.
|
// do usunięcia tego (EventId = id) eventu.
|
||||||
@@ -145,21 +155,50 @@ namespace WebApp.Endpoints
|
|||||||
{
|
{
|
||||||
|
|
||||||
// Uzyskaj organizację z tokenu
|
// Uzyskaj organizację z tokenu
|
||||||
|
var sort = httpContext.Request.Query["sort"].ToString();
|
||||||
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||||
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||||
List<EventSummaryDto> SearchResults = [];
|
List<EventSummaryDto> SearchResults = [];
|
||||||
|
|
||||||
|
|
||||||
List<Event> AllEvents = await dbContext.Events.ToListAsync();
|
List<Event> AllEvents = await dbContext.Events.ToListAsync();
|
||||||
|
if (sort is null || sort.ToUpper() != "ASC")
|
||||||
|
{
|
||||||
|
AllEvents.Reverse(); // aby wyświetlało od najnowszych wydarzeń
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
foreach(Event e in AllEvents)
|
foreach(Event e in AllEvents)
|
||||||
{
|
{
|
||||||
|
bool matchFound = true;
|
||||||
// Logika wyszukiwania
|
// Logika wyszukiwania
|
||||||
// Sprawdź wszystkie pola z EventSearchDto, np.
|
// Sprawdź wszystkie pola z EventSearchDto, np.
|
||||||
if (query.OrganisationId is not null)
|
if (query.OrganisationId is not null)
|
||||||
{
|
{
|
||||||
// Sprawdź, czy Event należy do query.OrganisationId.
|
// Sprawdź, czy Event należy do query.OrganisationId.
|
||||||
|
if (e.OrganisationId != query.OrganisationId) matchFound = false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (query.TitleOrDescription is not null)
|
||||||
|
{
|
||||||
|
var TitleMatch = guhf.SearchString(e.Title, query.TitleOrDescription);
|
||||||
|
var DescMatch = guhf.SearchString(e.Description, query.TitleOrDescription);
|
||||||
|
if (!TitleMatch && !DescMatch) matchFound = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//Zakres dat do wyszukiwania
|
||||||
|
if(query.EventDateFrom is not null)
|
||||||
|
{
|
||||||
|
if (e.EventDate < query.EventDateFrom) matchFound = false;
|
||||||
|
|
||||||
|
}
|
||||||
|
if(query.EventDateTo is not null)
|
||||||
|
{
|
||||||
|
if (e.EventDate > query.EventDateTo) matchFound = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
// ...
|
// ...
|
||||||
|
|
||||||
// Jeśli Event jest tym, czego szuka użytkownik,
|
// Jeśli Event jest tym, czego szuka użytkownik,
|
||||||
@@ -173,12 +212,101 @@ namespace WebApp.Endpoints
|
|||||||
e.EventRegistrations.Clear();
|
e.EventRegistrations.Clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
SearchResults.Add(e.ToEventSummaryDto());
|
// UWAGA! TO NIE POWINNO TAK DZIAŁAĆ!
|
||||||
|
// KTOKOLWIEK WIDZIAŁ, KTOKOLWIEK WIE CZEMU Organisation JEST null?
|
||||||
|
e.Organisation = await guhf.GetOrganisationFromId(e.OrganisationId);
|
||||||
|
|
||||||
|
if (matchFound) SearchResults.Add(e.ToEventSummaryDto());
|
||||||
}
|
}
|
||||||
|
|
||||||
return Results.Ok(SearchResults);
|
return Results.Ok(SearchResults);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
// POST /events/1/add_skill
|
||||||
|
group.MapPost("/{id}/add_skill/",
|
||||||
|
async (int id, SingleSkillDto dto, ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
|
||||||
|
{
|
||||||
|
Event? Eve = await dbContext.Events.FindAsync(id);
|
||||||
|
|
||||||
|
if (Eve is null) return Results.Json(new { message = "Event not found" }, statusCode: 404);
|
||||||
|
|
||||||
|
// Sprawdź, czy token należy do organizacji, a jeżeli tak, to do której.
|
||||||
|
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||||
|
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||||
|
|
||||||
|
// Jeśli token należy do organizacji, która utworzyła to wydarzenie,
|
||||||
|
// to zwróć także EventRegistrations. W przeciwnym razie usuń to pole
|
||||||
|
// przed jego wysłaniem!
|
||||||
|
if (org is null || org.OrganisationId != Eve.OrganisationId) return Results.Unauthorized();
|
||||||
|
|
||||||
|
// Szukamy skilla w bazie o ID takim, jak w otrzymanym DTO
|
||||||
|
Skill? skill = await dbContext.Skills.FindAsync(dto.Skill);
|
||||||
|
if (skill is null)
|
||||||
|
{
|
||||||
|
return Results.Json(new { message = "Skill not found" }, statusCode: 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sprawdzamy, czy to wydarzenie nie ma już takiego skilla. Jeżeli ma, nie ma sensu dodawać go kilkukrotnie.
|
||||||
|
EventSkill? es = await dbContext.EventSkills.FirstOrDefaultAsync(e => e.EventId == id && e.SkillId == dto.Skill);
|
||||||
|
if (es is null)
|
||||||
|
{
|
||||||
|
// Nie ma - zatem musimy dodać nowy EventSkill do bazy
|
||||||
|
EventSkill newEs = dto.ToEventSkillEntity(Eve.EventId);
|
||||||
|
dbContext.EventSkills.Add(newEs);
|
||||||
|
await dbContext.SaveChangesAsync();
|
||||||
|
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Ma - (ta para EventId <-> SkillId już istnieje w bazie); ten Event posiada już ten skill
|
||||||
|
return Results.Json(new { message = "Skill already assinged to this event!" }, statusCode: 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Results.Json(new { message = "Skill added to event successfully!" }, statusCode: 201);
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
// POST /events/1/renive_skill
|
||||||
|
group.MapPost("/{id}/remove_skill/",
|
||||||
|
async (int id, SingleSkillDto dto, ApplicationDbContext dbContext, HttpContext httpContext, GeneralUseHelpers guhf) =>
|
||||||
|
{
|
||||||
|
Event? Eve = await dbContext.Events.FindAsync(id);
|
||||||
|
|
||||||
|
if (Eve is null) return Results.Json(new { message = "Event not found" }, statusCode: 404);
|
||||||
|
|
||||||
|
// Sprawdź, czy token należy do organizacji, a jeżeli tak, to do której.
|
||||||
|
Token? token = await guhf.GetTokenFromHTTPContext(httpContext);
|
||||||
|
Organisation? org = await guhf.GetOrganisationFromToken(token);
|
||||||
|
|
||||||
|
// Jeśli token należy do organizacji, która utworzyła to wydarzenie,
|
||||||
|
// to zwróć także EventRegistrations. W przeciwnym razie usuń to pole
|
||||||
|
// przed jego wysłaniem!
|
||||||
|
if (org is null || org.OrganisationId != Eve.OrganisationId) return Results.Unauthorized();
|
||||||
|
|
||||||
|
// Szukamy skilla w bazie o ID takim, jak w otrzymanym DTO
|
||||||
|
Skill? skill = await dbContext.Skills.FindAsync(dto.Skill);
|
||||||
|
if (skill is null)
|
||||||
|
{
|
||||||
|
return Results.Json(new { message = "Skill not found" }, statusCode: 404);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Sprawdzamy, czy to wydarzenie nie ma już takiego skilla. Jeżeli nie ma, to nie ma sensu kasować czegoś, czego nie ma.
|
||||||
|
EventSkill? es = await dbContext.EventSkills.FirstOrDefaultAsync(e => e.EventId == id && e.SkillId == dto.Skill);
|
||||||
|
if (es is not null)
|
||||||
|
{
|
||||||
|
// Ma - zatem musimy usunąć ten EventSkill z bazy
|
||||||
|
await dbContext.EventSkills.Where(e => e.SkillId == dto.Skill)
|
||||||
|
.ExecuteDeleteAsync();
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
// Nie ma - (ta para EventId <-> SkillId nie istnieje w bazie); ten Event nie posiada tego skill'a
|
||||||
|
return Results.Json(new { message = "This skill isn't assinged to this event!" }, statusCode: 400);
|
||||||
|
}
|
||||||
|
|
||||||
|
return Results.Json(new { message = "Skill removed from event successfully!" }, statusCode: 201);
|
||||||
|
});
|
||||||
|
|
||||||
return group;
|
return group;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -48,6 +48,18 @@ public class GeneralUseHelpers
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async public Task<Organisation?> GetOrganisationFromId(int id)
|
||||||
|
{
|
||||||
|
Organisation? org = await _context.Organisations.FirstOrDefaultAsync(o => o.OrganisationId == id);
|
||||||
|
return org;
|
||||||
|
}
|
||||||
|
|
||||||
|
async public Task<Organisation?> GetOrganisationFromUserId(int userId)
|
||||||
|
{
|
||||||
|
Organisation? org = await _context.Organisations.FirstOrDefaultAsync(o => o.UserId == userId);
|
||||||
|
return org;
|
||||||
|
}
|
||||||
|
|
||||||
public string? GetTokenStrFromHTTPContext(HttpContext httpContext)
|
public string? GetTokenStrFromHTTPContext(HttpContext httpContext)
|
||||||
{
|
{
|
||||||
var cookies = httpContext.Request.Cookies;
|
var cookies = httpContext.Request.Cookies;
|
||||||
@@ -87,4 +99,17 @@ public class GeneralUseHelpers
|
|||||||
_context.Tokens.Remove(token);
|
_context.Tokens.Remove(token);
|
||||||
await _context.SaveChangesAsync();
|
await _context.SaveChangesAsync();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public bool SearchString(string? text, string searchTerm)
|
||||||
|
{
|
||||||
|
// Zwraca fałsz jeśli tekst jest pusty.
|
||||||
|
// (Brak tekstu nie wpływa na wynik wyszukiwania).
|
||||||
|
if (text is null) return false;
|
||||||
|
|
||||||
|
// Zamienia tekst na słowa
|
||||||
|
var words = text.Split(' ', StringSplitOptions.RemoveEmptyEntries);
|
||||||
|
|
||||||
|
// Sprawdza, czy któreś ze słów pasuje (nawet częściowo) do searchTerm
|
||||||
|
return words.Any(word => word.Contains(searchTerm, StringComparison.OrdinalIgnoreCase));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
26
WebApp/Endpoints/SkillsEndpoints.cs
Normal file
26
WebApp/Endpoints/SkillsEndpoints.cs
Normal file
@@ -0,0 +1,26 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using WebApp.Data;
|
||||||
|
using WebApp.Mapping;
|
||||||
|
|
||||||
|
namespace WebApp.Endpoints;
|
||||||
|
|
||||||
|
public static class SkillsEndpoints
|
||||||
|
{
|
||||||
|
const string GetSkillEndpointName = "GetSkill";
|
||||||
|
|
||||||
|
public static RouteGroupBuilder MapSkillsEndpoints(this WebApplication app)
|
||||||
|
{
|
||||||
|
var group = app.MapGroup("api/skills").WithParameterValidation();
|
||||||
|
|
||||||
|
// GET /skills
|
||||||
|
group.MapGet("/",
|
||||||
|
async (ApplicationDbContext dbContext) =>
|
||||||
|
await dbContext.Skills
|
||||||
|
.OrderBy(Sk => Sk.SkillId)
|
||||||
|
.Select(Sk => Sk.ToSkillSummaryDto()) // SkillSummaryDto
|
||||||
|
.AsNoTracking()
|
||||||
|
.ToListAsync());
|
||||||
|
|
||||||
|
return group;
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -3,7 +3,7 @@
|
|||||||
public class EventRegistration
|
public class EventRegistration
|
||||||
{
|
{
|
||||||
public int EventId { get; set; }
|
public int EventId { get; set; }
|
||||||
public required int VolunteerId { get; set; }
|
public required int UserId { get; set; }
|
||||||
public DateTime RegisteredAt { get; set; } = DateTime.UtcNow;
|
public DateTime RegisteredAt { get; set; } = DateTime.UtcNow;
|
||||||
public Event? Event { get; set; }
|
public Event? Event { get; set; }
|
||||||
public User? User { get; set; }
|
public User? User { get; set; }
|
||||||
|
|||||||
@@ -10,7 +10,6 @@ public static class EventMapping
|
|||||||
{
|
{
|
||||||
return new Event()
|
return new Event()
|
||||||
{
|
{
|
||||||
OrganisationId = ECDto.OrganisationId!.Value,
|
|
||||||
Title = ECDto.Title,
|
Title = ECDto.Title,
|
||||||
Description = ECDto.Description,
|
Description = ECDto.Description,
|
||||||
Location = ECDto.Location,
|
Location = ECDto.Location,
|
||||||
@@ -25,7 +24,6 @@ public static class EventMapping
|
|||||||
return new Event()
|
return new Event()
|
||||||
{
|
{
|
||||||
EventId = id,
|
EventId = id,
|
||||||
OrganisationId = EUDto.OrganisationId!.Value,
|
|
||||||
Title = EUDto.Title,
|
Title = EUDto.Title,
|
||||||
Description = EUDto.Description,
|
Description = EUDto.Description,
|
||||||
Location = EUDto.Location,
|
Location = EUDto.Location,
|
||||||
@@ -67,6 +65,7 @@ public static class EventMapping
|
|||||||
return new EventDetailsDto(
|
return new EventDetailsDto(
|
||||||
myEvent.EventId,
|
myEvent.EventId,
|
||||||
myEvent.OrganisationId,
|
myEvent.OrganisationId,
|
||||||
|
myEvent.Organisation.Name,
|
||||||
myEvent.Title,
|
myEvent.Title,
|
||||||
myEvent.Description,
|
myEvent.Description,
|
||||||
myEvent.Location,
|
myEvent.Location,
|
||||||
|
|||||||
16
WebApp/Mapping/EventSkillMapping.cs
Normal file
16
WebApp/Mapping/EventSkillMapping.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using WebApp.DTOs;
|
||||||
|
using WebApp.Entities;
|
||||||
|
|
||||||
|
namespace WebApp.Mapping;
|
||||||
|
|
||||||
|
public static class EventSkillMapping
|
||||||
|
{
|
||||||
|
public static EventSkill ToEventSkillEntity(this SingleSkillDto SSDto, int eid)
|
||||||
|
{
|
||||||
|
return new EventSkill()
|
||||||
|
{
|
||||||
|
EventId = eid,
|
||||||
|
SkillId = SSDto.Skill,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
25
WebApp/Mapping/SkillMapping.cs
Normal file
25
WebApp/Mapping/SkillMapping.cs
Normal file
@@ -0,0 +1,25 @@
|
|||||||
|
using WebApp.DTOs;
|
||||||
|
using WebApp.Entities;
|
||||||
|
|
||||||
|
namespace WebApp.Mapping
|
||||||
|
{
|
||||||
|
public static class SkillMapping
|
||||||
|
{
|
||||||
|
public static Skill ToSkillEntity(this SingleSkillDto SSDto, string name)
|
||||||
|
{
|
||||||
|
return new Skill()
|
||||||
|
{
|
||||||
|
SkillId = SSDto.Skill,
|
||||||
|
Name = name
|
||||||
|
};
|
||||||
|
}
|
||||||
|
|
||||||
|
public static SkillSummaryDto ToSkillSummaryDto(this Skill s)
|
||||||
|
{
|
||||||
|
return new SkillSummaryDto(
|
||||||
|
s.SkillId,
|
||||||
|
s.Name
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -16,5 +16,18 @@ namespace WebApp.Mapping
|
|||||||
user.IsOrganisation
|
user.IsOrganisation
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static UserSummaryWithOrgIdDto ToUserSummaryWithOrgIdDto(this User user, int OrganisationId)
|
||||||
|
{
|
||||||
|
return new UserSummaryWithOrgIdDto(
|
||||||
|
user.UserId,
|
||||||
|
user.Email,
|
||||||
|
user.FirstName,
|
||||||
|
user.LastName,
|
||||||
|
user.CreatedAt,
|
||||||
|
user.IsOrganisation,
|
||||||
|
OrganisationId
|
||||||
|
);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
16
WebApp/Mapping/VolunteerSkillMapping.cs
Normal file
16
WebApp/Mapping/VolunteerSkillMapping.cs
Normal file
@@ -0,0 +1,16 @@
|
|||||||
|
using WebApp.DTOs;
|
||||||
|
using WebApp.Entities;
|
||||||
|
|
||||||
|
namespace WebApp.Mapping;
|
||||||
|
|
||||||
|
public static class VolunteerSkillMapping
|
||||||
|
{
|
||||||
|
public static VolunteerSkill ToVolunteerSkillEntity(this SingleSkillDto SSDto, int uid)
|
||||||
|
{
|
||||||
|
return new VolunteerSkill()
|
||||||
|
{
|
||||||
|
UserId = uid,
|
||||||
|
SkillId = SSDto.Skill,
|
||||||
|
};
|
||||||
|
}
|
||||||
|
}
|
||||||
622
WebApp/Migrations/20250530235051_RenameEventRegistration.Designer.cs
generated
Normal file
622
WebApp/Migrations/20250530235051_RenameEventRegistration.Designer.cs
generated
Normal file
@@ -0,0 +1,622 @@
|
|||||||
|
// <auto-generated />
|
||||||
|
using System;
|
||||||
|
using Microsoft.EntityFrameworkCore;
|
||||||
|
using Microsoft.EntityFrameworkCore.Infrastructure;
|
||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
using Microsoft.EntityFrameworkCore.Storage.ValueConversion;
|
||||||
|
using Npgsql.EntityFrameworkCore.PostgreSQL.Metadata;
|
||||||
|
using WebApp.Data;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace WebApp.Migrations
|
||||||
|
{
|
||||||
|
[DbContext(typeof(ApplicationDbContext))]
|
||||||
|
[Migration("20250530235051_RenameEventRegistration")]
|
||||||
|
partial class RenameEventRegistration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void BuildTargetModel(ModelBuilder modelBuilder)
|
||||||
|
{
|
||||||
|
#pragma warning disable 612, 618
|
||||||
|
modelBuilder
|
||||||
|
.HasAnnotation("ProductVersion", "9.0.3")
|
||||||
|
.HasAnnotation("Relational:MaxIdentifierLength", 63);
|
||||||
|
|
||||||
|
NpgsqlModelBuilderExtensions.UseIdentityByDefaultColumns(modelBuilder);
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRole", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("ConcurrencyStamp")
|
||||||
|
.IsConcurrencyToken()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("NormalizedName")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("NormalizedName")
|
||||||
|
.IsUnique()
|
||||||
|
.HasDatabaseName("RoleNameIndex");
|
||||||
|
|
||||||
|
b.ToTable("AspNetRoles", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ClaimType")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("ClaimValue")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("RoleId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("RoleId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetRoleClaims", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUser", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("Id")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("AccessFailedCount")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("ConcurrencyStamp")
|
||||||
|
.IsConcurrencyToken()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<bool>("EmailConfirmed")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<bool>("LockoutEnabled")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<DateTimeOffset?>("LockoutEnd")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("NormalizedEmail")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("NormalizedUserName")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.Property<string>("PasswordHash")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("PhoneNumber")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<bool>("PhoneNumberConfirmed")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("SecurityStamp")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<bool>("TwoFactorEnabled")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("UserName")
|
||||||
|
.HasMaxLength(256)
|
||||||
|
.HasColumnType("character varying(256)");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("NormalizedEmail")
|
||||||
|
.HasDatabaseName("EmailIndex");
|
||||||
|
|
||||||
|
b.HasIndex("NormalizedUserName")
|
||||||
|
.IsUnique()
|
||||||
|
.HasDatabaseName("UserNameIndex");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUsers", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Id")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("Id"));
|
||||||
|
|
||||||
|
b.Property<string>("ClaimType")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("ClaimValue")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("Id");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserClaims", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("LoginProvider")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("ProviderKey")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("ProviderDisplayName")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("LoginProvider", "ProviderKey");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserLogins", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("RoleId")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("UserId", "RoleId");
|
||||||
|
|
||||||
|
b.HasIndex("RoleId");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserRoles", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||||
|
{
|
||||||
|
b.Property<string>("UserId")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("LoginProvider")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("UserId", "LoginProvider", "Name");
|
||||||
|
|
||||||
|
b.ToTable("AspNetUserTokens", (string)null);
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.Event", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("EventId")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("EventId"));
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<DateTime>("EventDate")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Location")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("OrganisationId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("Title")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("EventId");
|
||||||
|
|
||||||
|
b.HasIndex("OrganisationId");
|
||||||
|
|
||||||
|
b.ToTable("Events");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.EventRegistration", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("UserId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("EventId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime>("RegisteredAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("UserId", "EventId");
|
||||||
|
|
||||||
|
b.HasIndex("EventId");
|
||||||
|
|
||||||
|
b.ToTable("EventRegistrations");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.EventSkill", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("EventId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("SkillId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("EventId", "SkillId");
|
||||||
|
|
||||||
|
b.HasIndex("SkillId");
|
||||||
|
|
||||||
|
b.ToTable("EventSkills");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.Message", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("MessageId")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("MessageId"));
|
||||||
|
|
||||||
|
b.Property<string>("Content")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("EventType")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<bool>("IsMsgFromVolunteer")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<DateTime>("IsoDate")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<int>("OrganizationId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("VolunteerId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("MessageId");
|
||||||
|
|
||||||
|
b.ToTable("Messages");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.MessageActivity", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("Sender")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("Recipient")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime>("RecipientLastActive")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.HasKey("Sender", "Recipient");
|
||||||
|
|
||||||
|
b.ToTable("MessagesActivities");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.Organisation", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("OrganisationId")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("OrganisationId"));
|
||||||
|
|
||||||
|
b.Property<string>("Description")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<int>("UserId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<string>("Website")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("OrganisationId");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("Organisations");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.Skill", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("SkillId")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("SkillId"));
|
||||||
|
|
||||||
|
b.Property<string>("Name")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("SkillId");
|
||||||
|
|
||||||
|
b.ToTable("Skills");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.Token", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("TokenId")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("TokenId"));
|
||||||
|
|
||||||
|
b.Property<int>("UserId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<DateTime>("ValidUntil")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Value")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("TokenId");
|
||||||
|
|
||||||
|
b.HasIndex("UserId");
|
||||||
|
|
||||||
|
b.ToTable("Tokens");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("UserId")
|
||||||
|
.ValueGeneratedOnAdd()
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
NpgsqlPropertyBuilderExtensions.UseIdentityByDefaultColumn(b.Property<int>("UserId"));
|
||||||
|
|
||||||
|
b.Property<DateTime>("CreatedAt")
|
||||||
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
|
b.Property<string>("Email")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("FirstName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<bool>("IsOrganisation")
|
||||||
|
.HasColumnType("boolean");
|
||||||
|
|
||||||
|
b.Property<string>("LastName")
|
||||||
|
.IsRequired()
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.Property<string>("Password")
|
||||||
|
.HasColumnType("text");
|
||||||
|
|
||||||
|
b.HasKey("UserId");
|
||||||
|
|
||||||
|
b.ToTable("WebUsers");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.VolunteerSkill", b =>
|
||||||
|
{
|
||||||
|
b.Property<int>("UserId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.Property<int>("SkillId")
|
||||||
|
.HasColumnType("integer");
|
||||||
|
|
||||||
|
b.HasKey("UserId", "SkillId");
|
||||||
|
|
||||||
|
b.HasIndex("SkillId");
|
||||||
|
|
||||||
|
b.ToTable("VolunteerSkills");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityRoleClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("RoleId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserClaim<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserLogin<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserRole<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityRole", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("RoleId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("Microsoft.AspNetCore.Identity.IdentityUserToken<string>", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("Microsoft.AspNetCore.Identity.IdentityUser", null)
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.Event", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("WebApp.Entities.Organisation", "Organisation")
|
||||||
|
.WithMany("Events")
|
||||||
|
.HasForeignKey("OrganisationId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Organisation");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.EventRegistration", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("WebApp.Entities.Event", "Event")
|
||||||
|
.WithMany("EventRegistrations")
|
||||||
|
.HasForeignKey("EventId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("WebApp.Entities.User", "User")
|
||||||
|
.WithMany("EventRegistrations")
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Event");
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.EventSkill", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("WebApp.Entities.Event", "Event")
|
||||||
|
.WithMany("EventSkills")
|
||||||
|
.HasForeignKey("EventId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("WebApp.Entities.Skill", "Skill")
|
||||||
|
.WithMany("EventSkills")
|
||||||
|
.HasForeignKey("SkillId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Event");
|
||||||
|
|
||||||
|
b.Navigation("Skill");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.Organisation", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("WebApp.Entities.User", "User")
|
||||||
|
.WithMany()
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.Token", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("WebApp.Entities.User", null)
|
||||||
|
.WithMany("Tokens")
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.VolunteerSkill", b =>
|
||||||
|
{
|
||||||
|
b.HasOne("WebApp.Entities.Skill", "Skill")
|
||||||
|
.WithMany("VolunteerSkills")
|
||||||
|
.HasForeignKey("SkillId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.HasOne("WebApp.Entities.User", "User")
|
||||||
|
.WithMany("VolunteerSkills")
|
||||||
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
|
b.Navigation("Skill");
|
||||||
|
|
||||||
|
b.Navigation("User");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.Event", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("EventRegistrations");
|
||||||
|
|
||||||
|
b.Navigation("EventSkills");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.Organisation", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("Events");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.Skill", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("EventSkills");
|
||||||
|
|
||||||
|
b.Navigation("VolunteerSkills");
|
||||||
|
});
|
||||||
|
|
||||||
|
modelBuilder.Entity("WebApp.Entities.User", b =>
|
||||||
|
{
|
||||||
|
b.Navigation("EventRegistrations");
|
||||||
|
|
||||||
|
b.Navigation("Tokens");
|
||||||
|
|
||||||
|
b.Navigation("VolunteerSkills");
|
||||||
|
});
|
||||||
|
#pragma warning restore 612, 618
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
97
WebApp/Migrations/20250530235051_RenameEventRegistration.cs
Normal file
97
WebApp/Migrations/20250530235051_RenameEventRegistration.cs
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
using Microsoft.EntityFrameworkCore.Migrations;
|
||||||
|
|
||||||
|
#nullable disable
|
||||||
|
|
||||||
|
namespace WebApp.Migrations
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
public partial class RenameEventRegistration : Migration
|
||||||
|
{
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Up(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_EventRegistrations_WebUsers_UserId",
|
||||||
|
table: "EventRegistrations");
|
||||||
|
|
||||||
|
migrationBuilder.DropPrimaryKey(
|
||||||
|
name: "PK_EventRegistrations",
|
||||||
|
table: "EventRegistrations");
|
||||||
|
|
||||||
|
migrationBuilder.DropIndex(
|
||||||
|
name: "IX_EventRegistrations_UserId",
|
||||||
|
table: "EventRegistrations");
|
||||||
|
|
||||||
|
migrationBuilder.DropColumn(
|
||||||
|
name: "VolunteerId",
|
||||||
|
table: "EventRegistrations");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<int>(
|
||||||
|
name: "UserId",
|
||||||
|
table: "EventRegistrations",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0,
|
||||||
|
oldClrType: typeof(int),
|
||||||
|
oldType: "integer",
|
||||||
|
oldNullable: true);
|
||||||
|
|
||||||
|
migrationBuilder.AddPrimaryKey(
|
||||||
|
name: "PK_EventRegistrations",
|
||||||
|
table: "EventRegistrations",
|
||||||
|
columns: new[] { "UserId", "EventId" });
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_EventRegistrations_WebUsers_UserId",
|
||||||
|
table: "EventRegistrations",
|
||||||
|
column: "UserId",
|
||||||
|
principalTable: "WebUsers",
|
||||||
|
principalColumn: "UserId",
|
||||||
|
onDelete: ReferentialAction.Cascade);
|
||||||
|
}
|
||||||
|
|
||||||
|
/// <inheritdoc />
|
||||||
|
protected override void Down(MigrationBuilder migrationBuilder)
|
||||||
|
{
|
||||||
|
migrationBuilder.DropForeignKey(
|
||||||
|
name: "FK_EventRegistrations_WebUsers_UserId",
|
||||||
|
table: "EventRegistrations");
|
||||||
|
|
||||||
|
migrationBuilder.DropPrimaryKey(
|
||||||
|
name: "PK_EventRegistrations",
|
||||||
|
table: "EventRegistrations");
|
||||||
|
|
||||||
|
migrationBuilder.AlterColumn<int>(
|
||||||
|
name: "UserId",
|
||||||
|
table: "EventRegistrations",
|
||||||
|
type: "integer",
|
||||||
|
nullable: true,
|
||||||
|
oldClrType: typeof(int),
|
||||||
|
oldType: "integer");
|
||||||
|
|
||||||
|
migrationBuilder.AddColumn<int>(
|
||||||
|
name: "VolunteerId",
|
||||||
|
table: "EventRegistrations",
|
||||||
|
type: "integer",
|
||||||
|
nullable: false,
|
||||||
|
defaultValue: 0);
|
||||||
|
|
||||||
|
migrationBuilder.AddPrimaryKey(
|
||||||
|
name: "PK_EventRegistrations",
|
||||||
|
table: "EventRegistrations",
|
||||||
|
columns: new[] { "VolunteerId", "EventId" });
|
||||||
|
|
||||||
|
migrationBuilder.CreateIndex(
|
||||||
|
name: "IX_EventRegistrations_UserId",
|
||||||
|
table: "EventRegistrations",
|
||||||
|
column: "UserId");
|
||||||
|
|
||||||
|
migrationBuilder.AddForeignKey(
|
||||||
|
name: "FK_EventRegistrations_WebUsers_UserId",
|
||||||
|
table: "EventRegistrations",
|
||||||
|
column: "UserId",
|
||||||
|
principalTable: "WebUsers",
|
||||||
|
principalColumn: "UserId");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
@@ -252,7 +252,7 @@ namespace WebApp.Migrations
|
|||||||
|
|
||||||
modelBuilder.Entity("WebApp.Entities.EventRegistration", b =>
|
modelBuilder.Entity("WebApp.Entities.EventRegistration", b =>
|
||||||
{
|
{
|
||||||
b.Property<int>("VolunteerId")
|
b.Property<int>("UserId")
|
||||||
.HasColumnType("integer");
|
.HasColumnType("integer");
|
||||||
|
|
||||||
b.Property<int>("EventId")
|
b.Property<int>("EventId")
|
||||||
@@ -261,15 +261,10 @@ namespace WebApp.Migrations
|
|||||||
b.Property<DateTime>("RegisteredAt")
|
b.Property<DateTime>("RegisteredAt")
|
||||||
.HasColumnType("timestamp with time zone");
|
.HasColumnType("timestamp with time zone");
|
||||||
|
|
||||||
b.Property<int?>("UserId")
|
b.HasKey("UserId", "EventId");
|
||||||
.HasColumnType("integer");
|
|
||||||
|
|
||||||
b.HasKey("VolunteerId", "EventId");
|
|
||||||
|
|
||||||
b.HasIndex("EventId");
|
b.HasIndex("EventId");
|
||||||
|
|
||||||
b.HasIndex("UserId");
|
|
||||||
|
|
||||||
b.ToTable("EventRegistrations");
|
b.ToTable("EventRegistrations");
|
||||||
});
|
});
|
||||||
|
|
||||||
@@ -524,7 +519,9 @@ namespace WebApp.Migrations
|
|||||||
|
|
||||||
b.HasOne("WebApp.Entities.User", "User")
|
b.HasOne("WebApp.Entities.User", "User")
|
||||||
.WithMany("EventRegistrations")
|
.WithMany("EventRegistrations")
|
||||||
.HasForeignKey("UserId");
|
.HasForeignKey("UserId")
|
||||||
|
.OnDelete(DeleteBehavior.Cascade)
|
||||||
|
.IsRequired();
|
||||||
|
|
||||||
b.Navigation("Event");
|
b.Navigation("Event");
|
||||||
|
|
||||||
|
|||||||
@@ -53,5 +53,6 @@ app.UseRouting(); // Enables routing to match incoming request to endpoints
|
|||||||
app.MapEventsEndpoints();
|
app.MapEventsEndpoints();
|
||||||
app.MapOrganizationsEndpoints();
|
app.MapOrganizationsEndpoints();
|
||||||
app.MapAuthEndpoints();
|
app.MapAuthEndpoints();
|
||||||
|
app.MapSkillsEndpoints();
|
||||||
|
|
||||||
app.Run();
|
app.Run();
|
||||||
|
|||||||
57
WebApp/ts/auth.ts
Normal file
57
WebApp/ts/auth.ts
Normal file
@@ -0,0 +1,57 @@
|
|||||||
|
// /js/auth.ts
|
||||||
|
|
||||||
|
function deleteCookie(name: string): void {
|
||||||
|
document.cookie = `${name}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function logoutUser(): Promise<void> {
|
||||||
|
await fetch("/api/auth/logout", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
|
||||||
|
deleteCookie('token');
|
||||||
|
|
||||||
|
window.location.href = "/index.html";
|
||||||
|
}
|
||||||
|
|
||||||
|
function redirectToLogin(): void {
|
||||||
|
window.location.href = 'login.html';
|
||||||
|
}
|
||||||
|
|
||||||
|
function checkAuth(): boolean {
|
||||||
|
// Basic auth check via presence of token cookie
|
||||||
|
return document.cookie.includes('token=');
|
||||||
|
}
|
||||||
|
|
||||||
|
function setupAuthUI(): void {
|
||||||
|
const joinNowBtn = document.getElementById('joinnow-btn');
|
||||||
|
const signInBtn = document.getElementById('signin-btn');
|
||||||
|
const logoutBtn = document.getElementById('logout-btn');
|
||||||
|
|
||||||
|
const isAuthenticated = checkAuth();
|
||||||
|
|
||||||
|
if (joinNowBtn) {
|
||||||
|
joinNowBtn.classList.toggle('d-none', isAuthenticated);
|
||||||
|
joinNowBtn.addEventListener('click', redirectToLogin);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (signInBtn) {
|
||||||
|
signInBtn.classList.toggle('d-none', isAuthenticated);
|
||||||
|
signInBtn.addEventListener('click', redirectToLogin);
|
||||||
|
}
|
||||||
|
|
||||||
|
if (logoutBtn) {
|
||||||
|
logoutBtn.classList.toggle('d-none', !isAuthenticated);
|
||||||
|
logoutBtn.addEventListener('click', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
logoutUser();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// Initialize on load
|
||||||
|
document.addEventListener('DOMContentLoaded', setupAuthUI);
|
||||||
@@ -1,4 +1,4 @@
|
|||||||
console.log("TypeScript działa!");
|
import { getEvent, getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||||
|
|
||||||
async function createEvent() {
|
async function createEvent() {
|
||||||
// Pobieranie danych z formularza
|
// Pobieranie danych z formularza
|
||||||
@@ -9,7 +9,7 @@ async function createEvent() {
|
|||||||
|
|
||||||
// Walidacja prostych pól
|
// Walidacja prostych pól
|
||||||
if (!title || !location || !eventDateRaw) {
|
if (!title || !location || !eventDateRaw) {
|
||||||
alert("Uzupełnij wszystkie wymagane pola!");
|
alert("Please fill out all of the required fields!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -34,16 +34,28 @@ async function createEvent() {
|
|||||||
throw new Error(errorText);
|
throw new Error(errorText);
|
||||||
}
|
}
|
||||||
|
|
||||||
alert("Wydarzenie zostało utworzone!");
|
alert("Event created successfully!");
|
||||||
window.location.href = "/"; // Przekierowanie do strony głównej
|
window.location.href = "/"; // Przekierowanie do strony głównej
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
console.error("Błąd podczas tworzenia:", error);
|
console.error("Couldn't create event:", error);
|
||||||
alert("Nie udało się utworzyć wydarzenia: " + error);
|
alert("Couldn't create new event: " + error);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
const saveBtn = document.getElementById("saveBtn");
|
const saveBtn = document.getElementById("saveBtn");
|
||||||
|
|
||||||
|
var user = await getMyAccount();
|
||||||
|
if (user) {
|
||||||
|
if (user.isOrganisation) {
|
||||||
|
unhideElementById(document, "mainContainer");
|
||||||
|
}
|
||||||
|
unhideElementById(document, "logout-btn");
|
||||||
|
} else {
|
||||||
|
unhideElementById(document, "joinnow-btn");
|
||||||
|
unhideElementById(document, "signin-btn");
|
||||||
|
}
|
||||||
|
|
||||||
if (saveBtn) {
|
if (saveBtn) {
|
||||||
saveBtn.addEventListener("click", (e) => {
|
saveBtn.addEventListener("click", (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
|
|||||||
@@ -3,30 +3,38 @@
|
|||||||
document.body.addEventListener("click", async (e) => {
|
document.body.addEventListener("click", async (e) => {
|
||||||
const target = e.target as HTMLElement;
|
const target = e.target as HTMLElement;
|
||||||
|
|
||||||
if (!target.matches(".delete-btn")) return; // Sprawdza, czy kliknięto przycisk "Usuń"
|
if (!target.matches(".mod-btn")) return; // Sprawdza, czy kliknięto przycisk "Usuń" lub "Edytuj"
|
||||||
|
|
||||||
const id = target.getAttribute("data-id"); // Pobiera ID wydarzenia
|
const id = target.getAttribute("data-id"); // Pobiera ID wydarzenia
|
||||||
if (!id) return;
|
if (!id) return;
|
||||||
|
|
||||||
const confirmed = confirm("Na pewno chcesz usunąć to wydarzenie?"); // Potwierdzenie usunięcia
|
switch (target.id) {
|
||||||
if (!confirmed) return;
|
case "edit-btn":
|
||||||
|
window.location.href = "/modify.html?event=" + id;
|
||||||
|
break;
|
||||||
|
case "remove-btn":
|
||||||
|
const confirmed = confirm("Na pewno chcesz usunąć to wydarzenie?"); // Potwierdzenie usunięcia
|
||||||
|
if (!confirmed) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// Wysyła żądanie DELETE do API
|
// Wysyła żądanie DELETE do API
|
||||||
const response = await fetch(`/api/events/${id}`, {
|
const response = await fetch(`/api/events/${id}`, {
|
||||||
method: "DELETE"
|
method: "DELETE"
|
||||||
});
|
});
|
||||||
|
|
||||||
if (response.ok) {
|
if (response.ok) {
|
||||||
// Usuwa kartę z DOM (bez przeładowania strony)
|
// Usuwa kartę z DOM (bez przeładowania strony)
|
||||||
const card = target.closest(".event-card");
|
const card = target.closest(".event-card");
|
||||||
if (card) card.remove();
|
if (card) card.remove();
|
||||||
} else {
|
} else {
|
||||||
alert("Błąd podczas usuwania wydarzenia.");
|
alert("Błąd podczas usuwania wydarzenia.");
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
alert("Błąd połączenia z serwerem.");
|
alert("Błąd połączenia z serwerem.");
|
||||||
console.error(err);
|
console.error(err);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -1,12 +1,47 @@
|
|||||||
document.addEventListener("DOMContentLoaded", async () => {
|
import { getEvent, getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||||
|
|
||||||
|
var isAscending: boolean = false;
|
||||||
|
|
||||||
|
function toggleListSortOrder(org_id: number) {
|
||||||
|
isAscending = !isAscending;
|
||||||
|
loadEvents(org_id);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function getEvents(titleOrDescription?: string) {
|
||||||
|
|
||||||
|
var res: Response;
|
||||||
|
|
||||||
|
if (titleOrDescription == null) {
|
||||||
|
res = await fetch("/api/events" + (isAscending ? "?sort=asc" : ""));
|
||||||
|
if (!res.ok) throw new Error("Błąd pobierania wydarzeń");
|
||||||
|
} else {
|
||||||
|
const payload = {
|
||||||
|
titleOrDescription
|
||||||
|
};
|
||||||
|
res = await fetch('/api/events/search', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(payload)
|
||||||
|
});
|
||||||
|
if (!res.ok) throw new Error("Błąd wyszukiwania wydarzeń");
|
||||||
|
}
|
||||||
|
|
||||||
|
const events = await res.json();
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function loadEvents(org_id: number, evs?: Promise<any>) {
|
||||||
const container = document.getElementById("eventList");
|
const container = document.getElementById("eventList");
|
||||||
if (!container) return;
|
if (!container) return;
|
||||||
|
var events: any;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/events");
|
if (evs == null) {
|
||||||
if (!res.ok) throw new Error("Błąd pobierania wydarzeń");
|
events = await getEvents();
|
||||||
|
}
|
||||||
const events = await res.json();
|
else {
|
||||||
|
events = await evs;
|
||||||
|
}
|
||||||
|
|
||||||
if (events.length === 0) {
|
if (events.length === 0) {
|
||||||
container.innerHTML = "<p class='text-muted'>Brak wydarzeń do wyświetlenia.</p>";
|
container.innerHTML = "<p class='text-muted'>Brak wydarzeń do wyświetlenia.</p>";
|
||||||
@@ -19,14 +54,68 @@
|
|||||||
for (const ev of events) {
|
for (const ev of events) {
|
||||||
const card = document.createElement("div");
|
const card = document.createElement("div");
|
||||||
card.className = "event-card filled";
|
card.className = "event-card filled";
|
||||||
|
//card.innerHTML = `
|
||||||
|
// <span>${ev.title}</span>`
|
||||||
|
// Do odkomentowania kiedy widok podglądu wydarzeń będzie gotowy
|
||||||
card.innerHTML = `
|
card.innerHTML = `
|
||||||
<span>${ev.title}</span>
|
<span>
|
||||||
<button class="remove-btn delete-btn" data-id="${ev.eventId}">−</button>
|
<a href="/view.html?event=${ev.eventId}" style="color: #2898BD">${ev.title}</a>
|
||||||
`;
|
<p style="margin: 0">${ev.organisation}</p>
|
||||||
|
</span>`
|
||||||
|
if (org_id == ev.organisationId) {
|
||||||
|
card.innerHTML += `
|
||||||
|
<div>
|
||||||
|
<button class="edit-btn mod-btn" data-id="${ev.eventId}" id="edit-btn">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#FFFFFF"><path d="M200-200h57l391-391-57-57-391 391v57Zm-80 80v-170l528-527q12-11 26.5-17t30.5-6q16 0 31 6t26 18l55 56q12 11 17.5 26t5.5 30q0 16-5.5 30.5T817-647L290-120H120Zm640-584-56-56 56 56Zm-141 85-28-29 57 57-29-28Z"/></svg>
|
||||||
|
</button>
|
||||||
|
<button class="remove-btn mod-btn" data-id="${ev.eventId}" id="remove-btn">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#FFFFFF"><path d="M280-440h400v-80H280v80ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>
|
||||||
|
</button>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
|
||||||
container.appendChild(card);
|
container.appendChild(card);
|
||||||
}
|
}
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
container.innerHTML = `<p class="text-danger">Błąd ładowania danych.</p>`;
|
container.innerHTML = `<p class="text-danger">Błąd ładowania danych.</p>`;
|
||||||
console.error(err);
|
console.error(err);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
|
|
||||||
|
var org_id: number = -1;
|
||||||
|
|
||||||
|
try {
|
||||||
|
var user = await getMyAccount();
|
||||||
|
|
||||||
|
if (user) {
|
||||||
|
if (user.isOrganisation) {
|
||||||
|
unhideElementById(document, "mainContainer");
|
||||||
|
unhideElementById(document, "addnewevent-btn");
|
||||||
|
org_id = user.organisationId;
|
||||||
|
}
|
||||||
|
unhideElementById(document, "logout-btn");
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
// console.log("User not signed in. Failing gracefully.");
|
||||||
|
unhideElementById(document, "joinnow-btn");
|
||||||
|
unhideElementById(document, "signin-btn");
|
||||||
|
}
|
||||||
|
|
||||||
|
loadEvents(org_id);
|
||||||
|
// listen for clicks
|
||||||
|
const listSortToggleButton = document.getElementById("list-sort-btn");
|
||||||
|
if (listSortToggleButton) {
|
||||||
|
listSortToggleButton.addEventListener("click", () => toggleListSortOrder(org_id));
|
||||||
|
}
|
||||||
|
// and for enter in search bar
|
||||||
|
const searchBar = document.getElementById('searchbar') as HTMLInputElement;
|
||||||
|
searchBar.addEventListener('keydown', (event) => {
|
||||||
|
if (event.key === 'Enter') {
|
||||||
|
// console.log('Enter key pressed!');
|
||||||
|
var searchResults = getEvents(searchBar.value);
|
||||||
|
loadEvents(org_id, searchResults);
|
||||||
|
}
|
||||||
|
})
|
||||||
});
|
});
|
||||||
102
WebApp/ts/eventModify.ts
Normal file
102
WebApp/ts/eventModify.ts
Normal file
@@ -0,0 +1,102 @@
|
|||||||
|
import { getEvent, getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||||
|
|
||||||
|
const queryString = window.location.search;
|
||||||
|
const urlParams = new URLSearchParams(queryString);
|
||||||
|
const eventId = urlParams.get('event');
|
||||||
|
|
||||||
|
async function modifyEvent()
|
||||||
|
{
|
||||||
|
// Pobieranie danych z formularza
|
||||||
|
const title = (document.getElementById('title') as HTMLInputElement).value;
|
||||||
|
const location = (document.getElementById('location') as HTMLInputElement).value;
|
||||||
|
const description = (document.getElementById('description') as HTMLTextAreaElement).value;
|
||||||
|
const eventDateRaw = (document.getElementById('eventDate') as HTMLInputElement).value;
|
||||||
|
|
||||||
|
// Walidacja prostych pól
|
||||||
|
if (!title || !location || !eventDateRaw)
|
||||||
|
{
|
||||||
|
alert("Please fill out all of the required fields!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
const eventDate = new Date(eventDateRaw).toISOString();
|
||||||
|
|
||||||
|
const payload = {
|
||||||
|
title,
|
||||||
|
location,
|
||||||
|
description,
|
||||||
|
eventDate,
|
||||||
|
};
|
||||||
|
|
||||||
|
try
|
||||||
|
{
|
||||||
|
const response = await fetch('/api/events/' + eventId, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(payload)
|
||||||
|
});
|
||||||
|
|
||||||
|
if (!response.ok)
|
||||||
|
{
|
||||||
|
const errorText = await response.text();
|
||||||
|
throw new Error(errorText);
|
||||||
|
}
|
||||||
|
|
||||||
|
alert("Wydarzenie zmodyfikowane!");
|
||||||
|
window.location.href = "/"; // Przekierowanie do strony głównej
|
||||||
|
} catch (error) {
|
||||||
|
console.error("Błąd podczas modyfikowania:", error);
|
||||||
|
alert("Nie udało się zmodyfikować wydarzenia: " + error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
|
var container = document.getElementById("mainContainer");
|
||||||
|
const saveBtn = document.getElementById("saveBtn");
|
||||||
|
|
||||||
|
try {
|
||||||
|
var user = await getMyAccount();
|
||||||
|
if (user) {
|
||||||
|
if (user.isOrganisation) {
|
||||||
|
unhideElementById(document, "mainContainer");
|
||||||
|
}
|
||||||
|
unhideElementById(document, "logout-btn");
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
unhideElementById(document, "joinnow-btn");
|
||||||
|
unhideElementById(document, "signin-btn");
|
||||||
|
}
|
||||||
|
|
||||||
|
if (saveBtn)
|
||||||
|
{
|
||||||
|
saveBtn.addEventListener("click", (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
modifyEvent();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (eventId !== null && container !== null) {
|
||||||
|
|
||||||
|
try {
|
||||||
|
const titleInput = document.getElementById( 'title') as HTMLInputElement;
|
||||||
|
const locationInput = document.getElementById( 'location') as HTMLInputElement;
|
||||||
|
const descriptionInput = document.getElementById('description') as HTMLInputElement;
|
||||||
|
const dateInput = document.getElementById( 'eventDate') as HTMLInputElement;
|
||||||
|
var ev = await getEvent(eventId);
|
||||||
|
|
||||||
|
if (ev === null) {
|
||||||
|
container.innerHTML = "<p class='text-muted'>Brak wydarzeń do wyświetlenia.</p>";
|
||||||
|
return;
|
||||||
|
} else {
|
||||||
|
titleInput.value = ev.title || '';
|
||||||
|
locationInput.value = ev.location || '';
|
||||||
|
descriptionInput.value = ev.description || '';
|
||||||
|
dateInput.value = ev.eventDate.slice(0, 16) || '';
|
||||||
|
}
|
||||||
|
|
||||||
|
} catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
container.innerHTML = `<p class="text-danger">` + err + `</p>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
});
|
||||||
97
WebApp/ts/eventView.ts
Normal file
97
WebApp/ts/eventView.ts
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
import { getEvent, getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||||
|
|
||||||
|
const queryString = window.location.search;
|
||||||
|
const urlParams = new URLSearchParams(queryString);
|
||||||
|
const eventId = urlParams.get('event');
|
||||||
|
|
||||||
|
document.addEventListener("DOMContentLoaded", async () => {
|
||||||
|
|
||||||
|
var container = document.getElementById("mainContainer");
|
||||||
|
const modifyBtn = document.getElementById("editBtn");
|
||||||
|
const removeBtn = document.getElementById("removeBtn");
|
||||||
|
var org_id: number = -1;
|
||||||
|
|
||||||
|
try {
|
||||||
|
var user = await getMyAccount();
|
||||||
|
if (user) {
|
||||||
|
if (user.isOrganisation) {
|
||||||
|
org_id = user.organisationId;
|
||||||
|
}
|
||||||
|
unhideElementById(document, "logout-btn");
|
||||||
|
}
|
||||||
|
} catch {
|
||||||
|
unhideElementById(document, "joinnow-btn");
|
||||||
|
unhideElementById(document, "signin-btn");
|
||||||
|
}
|
||||||
|
|
||||||
|
var thisEvent = null;
|
||||||
|
try {
|
||||||
|
if (eventId) thisEvent = await getEvent(eventId);
|
||||||
|
} catch (err) {
|
||||||
|
if (container !== null) container.innerHTML = `<p class="text-danger">To wydarzenie nie istnieje! <a href="/" style="color:#2898BD;">Powrót -></a></p>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (thisEvent == null) {
|
||||||
|
if (container !== null) container.innerHTML = `<p class="text-danger">B³¹d we wczytywaniu wydarzenia. <a href="/" style="color:#2898BD;">Powrót -></a></p>`;
|
||||||
|
} else {
|
||||||
|
|
||||||
|
const titleText = document.getElementById( "titleText") as HTMLElement;
|
||||||
|
const locationText = document.getElementById( "locationText") as HTMLElement;
|
||||||
|
const descText = document.getElementById( "descText") as HTMLElement;
|
||||||
|
const dateText = document.getElementById( "dateText") as HTMLElement;
|
||||||
|
const organizerText = document.getElementById("organizerText") as HTMLElement;
|
||||||
|
const newdateText = new Date(thisEvent.eventDate).toLocaleDateString('pl-PL');
|
||||||
|
const newtimeText = new Date(thisEvent.eventDate).toLocaleTimeString('pl-PL');
|
||||||
|
|
||||||
|
|
||||||
|
titleText.innerHTML = thisEvent.title + ` (#${eventId})`;
|
||||||
|
locationText.innerHTML = "Place: " + thisEvent.location;
|
||||||
|
descText.innerHTML = thisEvent.description;
|
||||||
|
dateText.innerHTML = "When: " + newdateText + " " + newtimeText; //thisEvent.eventDate;
|
||||||
|
organizerText.innerHTML = "Organized by: " + thisEvent.organisationName;
|
||||||
|
|
||||||
|
if (org_id == thisEvent.organisationId) {
|
||||||
|
// U¿ytkownik jest organizacj¹, która
|
||||||
|
// stworzy³a to wydarzenie
|
||||||
|
unhideElementById(document, "editBtn");
|
||||||
|
unhideElementById(document, "removeBtn");
|
||||||
|
} else if (org_id == -1) {
|
||||||
|
// U¿ytkownik jest wolontariuszem
|
||||||
|
unhideElementById(document, "applyBtn");
|
||||||
|
}
|
||||||
|
|
||||||
|
unhideElementById(document, "mainContainer");
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
if (modifyBtn) {
|
||||||
|
modifyBtn.addEventListener("click", (e) => {
|
||||||
|
window.location.href = "/modify.html?event=" + eventId;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
if (removeBtn) {
|
||||||
|
removeBtn.addEventListener("click", async (e) => {
|
||||||
|
const confirmed = confirm("Really delete?");
|
||||||
|
if (!confirmed) return;
|
||||||
|
|
||||||
|
try {
|
||||||
|
// Wysy³a ¿¹danie DELETE do API
|
||||||
|
const response = await fetch(`/api/events/${eventId}`, {
|
||||||
|
method: "DELETE"
|
||||||
|
});
|
||||||
|
|
||||||
|
if (response.ok) {
|
||||||
|
alert("Event deleted.");
|
||||||
|
window.location.href = "/";
|
||||||
|
} else {
|
||||||
|
alert("Couldn't delete event.");
|
||||||
|
}
|
||||||
|
} catch (err) {
|
||||||
|
alert("Couldn't connect.");
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
});
|
||||||
44
WebApp/ts/generalUseHelpers.ts
Normal file
44
WebApp/ts/generalUseHelpers.ts
Normal file
@@ -0,0 +1,44 @@
|
|||||||
|
interface EventData {
|
||||||
|
title: string;
|
||||||
|
location: string;
|
||||||
|
description: string;
|
||||||
|
eventDate: string;
|
||||||
|
organisationName: string,
|
||||||
|
organisationId: number
|
||||||
|
}
|
||||||
|
|
||||||
|
interface MyAccount {
|
||||||
|
userId: number;
|
||||||
|
email: string;
|
||||||
|
firstName: string;
|
||||||
|
lastName: string;
|
||||||
|
createdAt: string;
|
||||||
|
isOrganisation: boolean;
|
||||||
|
organisationId: number;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function unhideElementById(document: Document, e: string) {
|
||||||
|
var element = document.getElementById(e);
|
||||||
|
if (element) {
|
||||||
|
element.classList.remove('hidden-before-load');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getEvent(id: string): Promise<EventData> {
|
||||||
|
const res = await fetch("/api/events/" + id);
|
||||||
|
if (!res.ok) {
|
||||||
|
throw Error("To wydarzenie nie istnieje");
|
||||||
|
}
|
||||||
|
const events = await res.json();
|
||||||
|
return events;
|
||||||
|
}
|
||||||
|
|
||||||
|
export async function getMyAccount(): Promise<MyAccount> {
|
||||||
|
const res = await fetch("/api/auth/my_account");
|
||||||
|
if (!res.ok) {
|
||||||
|
throw Error("U¿ytkownik niezalogowany!");
|
||||||
|
}
|
||||||
|
const data = await res.json();
|
||||||
|
return data;
|
||||||
|
}
|
||||||
|
|
||||||
38
WebApp/ts/login.ts
Normal file
38
WebApp/ts/login.ts
Normal file
@@ -0,0 +1,38 @@
|
|||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
const form = document.getElementById("loginForm") as HTMLFormElement;
|
||||||
|
const message = document.getElementById("message") as HTMLParagraphElement;
|
||||||
|
|
||||||
|
form.addEventListener("submit", async (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
message.textContent = "";
|
||||||
|
|
||||||
|
const email = (document.getElementById("email") as HTMLInputElement).value;
|
||||||
|
const password = (document.getElementById("password") as HTMLInputElement).value;
|
||||||
|
|
||||||
|
try {
|
||||||
|
const response = await fetch("/api/auth/login", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ email, password }),
|
||||||
|
});
|
||||||
|
|
||||||
|
const data = await response.json();
|
||||||
|
|
||||||
|
if (!response.ok) {
|
||||||
|
message.textContent = data.message || "Login failed.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
document.cookie = `token=${data.token}; path=/; SameSite=Lax; Secure`;
|
||||||
|
message.style.color = "green";
|
||||||
|
message.textContent = "Login successful!";
|
||||||
|
|
||||||
|
window.location.href = "/index.html";
|
||||||
|
} catch (error) {
|
||||||
|
message.textContent = "Something went wrong.";
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
});
|
||||||
@@ -2,7 +2,7 @@
|
|||||||
<html lang="pl">
|
<html lang="pl">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8">
|
<meta charset="UTF-8">
|
||||||
<title>Nowe wydarzenie</title>
|
<title>New event</title>
|
||||||
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap" rel="stylesheet">
|
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap" rel="stylesheet">
|
||||||
<link rel="stylesheet" href="/css/style.css" />
|
<link rel="stylesheet" href="/css/style.css" />
|
||||||
@@ -48,28 +48,29 @@
|
|||||||
<div class="topnav d-flex justify-content-between align-items-center shadow">
|
<div class="topnav d-flex justify-content-between align-items-center shadow">
|
||||||
<a href="index.html" class="eventsText m-0 logo text-decoration-none">Lend a Hand</a>
|
<a href="index.html" class="eventsText m-0 logo text-decoration-none">Lend a Hand</a>
|
||||||
<div>
|
<div>
|
||||||
<button class="button-join">Join now</button>
|
<button class="button-join hidden-before-load" id="joinnow-btn">Join now</button>
|
||||||
<button class="button-sign">Sign In</button>
|
<button class="button-sign hidden-before-load" id="signin-btn">Sign In</button>
|
||||||
|
<button class="button-sign hidden-before-load" id="logout-btn">Log out</button>
|
||||||
<svg class="position-relative" xmlns="http://www.w3.org/2000/svg" height="50px" viewBox="0 -960 960 960" width="50px" fill="#2898BD"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z" /></svg>
|
<svg class="position-relative" xmlns="http://www.w3.org/2000/svg" height="50px" viewBox="0 -960 960 960" width="50px" fill="#2898BD"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z" /></svg>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
<div class="main">
|
<div class="main hidden-before-load" id="mainContainer">
|
||||||
<h1 class="mb-4">Create a new event</h1>
|
<h1 class="mb-4">Create a new event</h1>
|
||||||
|
|
||||||
<div class="form-group mb-2">
|
<div class="form-group mb-2">
|
||||||
<label for="title">Tytuł</label>
|
<label for="title">Title</label>
|
||||||
<input id="title" class="form-control input-field" />
|
<input id="title" class="form-control input-field" />
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group mb-2">
|
<div class="form-group mb-2">
|
||||||
<label for="location">Lokalizacja</label>
|
<label for="location">Location</label>
|
||||||
<input id="location" class="form-control input-field" />
|
<input id="location" class="form-control input-field" />
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group mb-2">
|
<div class="form-group mb-2">
|
||||||
<label for="description">Opis</label>
|
<label for="description">Description</label>
|
||||||
<textarea id="description" class="form-control input-field"></textarea>
|
<textarea id="description" class="form-control input-field"></textarea>
|
||||||
</div>
|
</div>
|
||||||
<div class="form-group mb-2">
|
<div class="form-group mb-2">
|
||||||
<label for="eventDate">Data</label>
|
<label for="eventDate">Date</label>
|
||||||
<input id="eventDate" type="datetime-local" class="form-control input-field" />
|
<input id="eventDate" type="datetime-local" class="form-control input-field" />
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
@@ -78,6 +79,9 @@
|
|||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="module" src="/js/eventCreate.js"></script>
|
<script type="module" src="/js/eventCreate.js"></script>
|
||||||
|
<script type="module" src="/js/generalUseHelpers.js"></script>
|
||||||
|
<script type="module" src="/js/auth.js"></script>
|
||||||
|
|
||||||
</body>
|
</body>
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -4,6 +4,11 @@
|
|||||||
font-size: 36px;
|
font-size: 36px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hidden-before-load {
|
||||||
|
display: none !important;
|
||||||
|
visibility: hidden !important;
|
||||||
|
}
|
||||||
|
|
||||||
body {
|
body {
|
||||||
font-family: 'Segoe UI', sans-serif;
|
font-family: 'Segoe UI', sans-serif;
|
||||||
}
|
}
|
||||||
@@ -166,6 +171,7 @@ body {
|
|||||||
width: 99px;
|
width: 99px;
|
||||||
height: 50px;
|
height: 50px;
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
|
margin: 0 5px 0 5px;
|
||||||
}
|
}
|
||||||
#eventList .event-card .remove-btn:hover {
|
#eventList .event-card .remove-btn:hover {
|
||||||
background-color: #CD4A31;
|
background-color: #CD4A31;
|
||||||
@@ -176,6 +182,31 @@ body {
|
|||||||
width: 99px;
|
width: 99px;
|
||||||
height: 50px;
|
height: 50px;
|
||||||
line-height: 1;
|
line-height: 1;
|
||||||
|
margin: 0 5px 0 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#eventList .event-card .edit-btn {
|
||||||
|
background-color: #9B9B9B;
|
||||||
|
border: none;
|
||||||
|
border-radius: 30px;
|
||||||
|
color: white;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
width: 99px;
|
||||||
|
height: 50px;
|
||||||
|
line-height: 1;
|
||||||
|
margin: 0 5px 0 5px;
|
||||||
|
}
|
||||||
|
|
||||||
|
#eventList .event-card .edit-btn:hover {
|
||||||
|
background-color: #777;
|
||||||
|
border: none;
|
||||||
|
border-radius: 30px;
|
||||||
|
color: white;
|
||||||
|
font-size: 1.2rem;
|
||||||
|
width: 99px;
|
||||||
|
height: 50px;
|
||||||
|
line-height: 1;
|
||||||
|
margin: 0 5px 0 5px;
|
||||||
}
|
}
|
||||||
|
|
||||||
.center-text {
|
.center-text {
|
||||||
|
|||||||
@@ -2,6 +2,11 @@ html {
|
|||||||
font-size: 14px;
|
font-size: 14px;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hidden-before-load {
|
||||||
|
display: none !important;
|
||||||
|
visibility: hidden !important;
|
||||||
|
}
|
||||||
|
|
||||||
@media (min-width: 768px) {
|
@media (min-width: 768px) {
|
||||||
html {
|
html {
|
||||||
font-size: 16px;
|
font-size: 16px;
|
||||||
|
|||||||
@@ -1,6 +1,12 @@
|
|||||||
body {
|
body {
|
||||||
color: #2898BD;
|
color: #2898BD;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
.hidden-before-load {
|
||||||
|
display: none !important;
|
||||||
|
visibility: hidden !important;
|
||||||
|
}
|
||||||
|
|
||||||
.input-field {
|
.input-field {
|
||||||
border-radius: 10px;
|
border-radius: 10px;
|
||||||
padding: 10px;
|
padding: 10px;
|
||||||
|
|||||||
@@ -1,4 +1,4 @@
|
|||||||
<!DOCTYPE html>
|
<!DOCTYPE html>
|
||||||
<html lang="pl">
|
<html lang="pl">
|
||||||
<head>
|
<head>
|
||||||
<meta charset="UTF-8" />
|
<meta charset="UTF-8" />
|
||||||
@@ -46,8 +46,9 @@
|
|||||||
<div class="topnav d-flex justify-content-between align-items-center shadow">
|
<div class="topnav d-flex justify-content-between align-items-center shadow">
|
||||||
<a href="index.html" class="eventsText m-0 logo text-decoration-none">Lend a Hand</a>
|
<a href="index.html" class="eventsText m-0 logo text-decoration-none">Lend a Hand</a>
|
||||||
<div>
|
<div>
|
||||||
<button class="button-join">Join now</button>
|
<button class="button-join hidden-before-load" id="joinnow-btn">Join now</button>
|
||||||
<button class="button-sign">Sign In</button>
|
<button class="button-sign hidden-before-load" id="signin-btn">Sign In</button>
|
||||||
|
<button class="button-sign hidden-before-load" id="logout-btn">Log out</button>
|
||||||
<svg class="position-relative" xmlns="http://www.w3.org/2000/svg" height="50px" viewBox="0 -960 960 960" width="50px" fill="#2898BD"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z" /></svg>
|
<svg class="position-relative" xmlns="http://www.w3.org/2000/svg" height="50px" viewBox="0 -960 960 960" width="50px" fill="#2898BD"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z" /></svg>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
@@ -55,15 +56,15 @@
|
|||||||
<!-- Main content -->
|
<!-- Main content -->
|
||||||
<div class="main">
|
<div class="main">
|
||||||
<div class="position-relative search-bar">
|
<div class="position-relative search-bar">
|
||||||
<input type="text" class="form-control pe-5" placeholder="" />
|
<input type="text" class="form-control pe-5" placeholder="" id="searchbar" />
|
||||||
<span class="position-absolute top-50 end-0 translate-middle-y me-3">
|
<span class="position-absolute top-50 end-0 translate-middle-y me-3">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400Z" /></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M784-120 532-372q-30 24-69 38t-83 14q-109 0-184.5-75.5T120-580q0-109 75.5-184.5T380-840q109 0 184.5 75.5T640-580q0 44-14 83t-38 69l252 252-56 56ZM380-400q75 0 127.5-52.5T560-580q0-75-52.5-127.5T380-760q-75 0-127.5 52.5T200-580q0 75 52.5 127.5T380-400Z" /></svg>
|
||||||
</span>
|
</span>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<!--<a href="/create.html" class="button-add text-decoration-none">
|
<!--<a href="/create.html" class="button-add text-decoration-none">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#FFFFFF"><path d="M440-440H200v-80h240v-240h80v240h240v80H520v240h-80v-240Z" /></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#FFFFFF"><path d="M440-440H200v-80h240v-240h80v240h240v80H520v240h-80v-240Z" /></svg>
|
||||||
</a>-->
|
</a>-->
|
||||||
<div class="events-card bg-white p-4 rounded-4 shadow position-relative">
|
<div class="events-card bg-white p-4 rounded-4 shadow position-relative">
|
||||||
<div class="d-flex justify-content-between align-items-center mb-3">
|
<div class="d-flex justify-content-between align-items-center mb-3">
|
||||||
<h2 class="eventsText">Events</h2>
|
<h2 class="eventsText">Events</h2>
|
||||||
@@ -71,25 +72,26 @@
|
|||||||
<button class="btn btn-link" onclick="">
|
<button class="btn btn-link" onclick="">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M440-120v-240h80v80h320v80H520v80h-80Zm-320-80v-80h240v80H120Zm160-160v-80H120v-80h160v-80h80v240h-80Zm160-80v-80h400v80H440Zm160-160v-240h80v80h160v80H680v80h-80Zm-480-80v-80h400v80H120Z" /></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M440-120v-240h80v80h320v80H520v80h-80Zm-320-80v-80h240v80H120Zm160-160v-80H120v-80h160v-80h80v240h-80Zm160-80v-80h400v80H440Zm160-160v-240h80v80h160v80H680v80h-80Zm-480-80v-80h400v80H120Z" /></svg>
|
||||||
</button>
|
</button>
|
||||||
<button class="btn btn-link" onclick=""><svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M320-440v-287L217-624l-57-56 200-200 200 200-57 56-103-103v287h-80ZM600-80 400-280l57-56 103 103v-287h80v287l103-103 57 56L600-80Z" /></svg></button>
|
<button class="btn btn-link" id="list-sort-btn" onclick=""><svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M320-440v-287L217-624l-57-56 200-200 200 200-57 56-103-103v287h-80ZM600-80 400-280l57-56 103 103v-287h80v287l103-103 57 56L600-80Z" /></svg></button>
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<div id="eventList" class="d-grid gap-3">
|
<div id="eventList" class="d-grid gap-3">
|
||||||
<!-- Karty wydarzeń będą ładowane tutaj -->
|
<!-- Karty wydarzeń będą ładowane tutaj -->
|
||||||
<div class="event-card filled">
|
<div class="event-card filled">
|
||||||
<span>Event Title</span>
|
<span>Loading events... please wait.</span>
|
||||||
<button class="remove-btn delete-btn" data-id="5"><svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#FFFFFF"><path d="M280-440h400v-80H280v80ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z" /></svg></button> <!-- Przyciski usuwania z ID -->
|
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
<script type="module" src="/js/eventList.js"></script>
|
<script type="module" src="/js/eventList.js"></script>
|
||||||
<script type="module" src="/js/eventDelete.js"></script>
|
<script type="module" src="/js/eventDelete.js"></script>
|
||||||
|
<script type="module" src="/js/generalUseHelpers.js"></script>
|
||||||
|
|
||||||
</div>
|
</div>
|
||||||
<a href="/create.html" class="button-add mt-xl-auto rounded-5 align-content-center center-text">
|
<a href="/create.html" class="button-add mt-xl-auto rounded-5 align-content-center center-text hidden-before-load" id="addnewevent-btn">
|
||||||
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#FFFFFF"><path d="M440-440H200v-80h240v-240h80v240h240v80H520v240h-80v-240Z" /></svg>
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#FFFFFF"><path d="M440-440H200v-80h240v-240h80v240h240v80H520v240h-80v-240Z" /></svg>
|
||||||
</a>
|
</a>
|
||||||
|
<script type="module" src="/js/auth.js"></script>
|
||||||
</body>
|
</body>
|
||||||
</html>
|
</html>
|
||||||
56
WebApp/wwwroot/js/auth.js
Normal file
56
WebApp/wwwroot/js/auth.js
Normal file
@@ -0,0 +1,56 @@
|
|||||||
|
"use strict";
|
||||||
|
// /js/auth.ts
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
function deleteCookie(name) {
|
||||||
|
document.cookie = `${name}=; path=/; expires=Thu, 01 Jan 1970 00:00:00 GMT`;
|
||||||
|
}
|
||||||
|
function logoutUser() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
yield fetch("/api/auth/logout", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
});
|
||||||
|
deleteCookie('token');
|
||||||
|
window.location.href = "/index.html";
|
||||||
|
});
|
||||||
|
}
|
||||||
|
function redirectToLogin() {
|
||||||
|
window.location.href = 'login.html';
|
||||||
|
}
|
||||||
|
function checkAuth() {
|
||||||
|
// Basic auth check via presence of token cookie
|
||||||
|
return document.cookie.includes('token=');
|
||||||
|
}
|
||||||
|
function setupAuthUI() {
|
||||||
|
const joinNowBtn = document.getElementById('joinnow-btn');
|
||||||
|
const signInBtn = document.getElementById('signin-btn');
|
||||||
|
const logoutBtn = document.getElementById('logout-btn');
|
||||||
|
const isAuthenticated = checkAuth();
|
||||||
|
if (joinNowBtn) {
|
||||||
|
joinNowBtn.classList.toggle('d-none', isAuthenticated);
|
||||||
|
joinNowBtn.addEventListener('click', redirectToLogin);
|
||||||
|
}
|
||||||
|
if (signInBtn) {
|
||||||
|
signInBtn.classList.toggle('d-none', isAuthenticated);
|
||||||
|
signInBtn.addEventListener('click', redirectToLogin);
|
||||||
|
}
|
||||||
|
if (logoutBtn) {
|
||||||
|
logoutBtn.classList.toggle('d-none', !isAuthenticated);
|
||||||
|
logoutBtn.addEventListener('click', (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
logoutUser();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Initialize on load
|
||||||
|
document.addEventListener('DOMContentLoaded', setupAuthUI);
|
||||||
@@ -1,4 +1,3 @@
|
|||||||
"use strict";
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
@@ -8,7 +7,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
console.log("TypeScript działa!");
|
import { getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||||
function createEvent() {
|
function createEvent() {
|
||||||
return __awaiter(this, void 0, void 0, function* () {
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
// Pobieranie danych z formularza
|
// Pobieranie danych z formularza
|
||||||
@@ -16,20 +15,17 @@ function createEvent() {
|
|||||||
const location = document.getElementById('location').value;
|
const location = document.getElementById('location').value;
|
||||||
const description = document.getElementById('description').value;
|
const description = document.getElementById('description').value;
|
||||||
const eventDateRaw = document.getElementById('eventDate').value;
|
const eventDateRaw = document.getElementById('eventDate').value;
|
||||||
const organisationIdRaw = document.getElementById('organisationId').value;
|
|
||||||
// Walidacja prostych pól
|
// Walidacja prostych pól
|
||||||
if (!title || !location || !eventDateRaw || !organisationIdRaw) {
|
if (!title || !location || !eventDateRaw) {
|
||||||
alert("Uzupełnij wszystkie wymagane pola!");
|
alert("Please fill out all of the required fields!");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
const eventDate = new Date(eventDateRaw).toISOString();
|
const eventDate = new Date(eventDateRaw).toISOString();
|
||||||
const organisationId = parseInt(organisationIdRaw);
|
|
||||||
const payload = {
|
const payload = {
|
||||||
title,
|
title,
|
||||||
location,
|
location,
|
||||||
description,
|
description,
|
||||||
eventDate,
|
eventDate,
|
||||||
organisationId
|
|
||||||
};
|
};
|
||||||
try {
|
try {
|
||||||
const response = yield fetch('/api/events', {
|
const response = yield fetch('/api/events', {
|
||||||
@@ -41,21 +37,32 @@ function createEvent() {
|
|||||||
const errorText = yield response.text();
|
const errorText = yield response.text();
|
||||||
throw new Error(errorText);
|
throw new Error(errorText);
|
||||||
}
|
}
|
||||||
alert("Wydarzenie zostało utworzone!");
|
alert("Event created successfully!");
|
||||||
window.location.href = "/"; // Przekierowanie do strony głównej
|
window.location.href = "/"; // Przekierowanie do strony głównej
|
||||||
}
|
}
|
||||||
catch (error) {
|
catch (error) {
|
||||||
console.error("Błąd podczas tworzenia:", error);
|
console.error("Couldn't create event:", error);
|
||||||
alert("Nie udało się utworzyć wydarzenia: " + error);
|
alert("Couldn't create new event: " + error);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
document.addEventListener("DOMContentLoaded", () => {
|
document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const saveBtn = document.getElementById("saveBtn");
|
const saveBtn = document.getElementById("saveBtn");
|
||||||
|
var user = yield getMyAccount();
|
||||||
|
if (user) {
|
||||||
|
if (user.isOrganisation) {
|
||||||
|
unhideElementById(document, "mainContainer");
|
||||||
|
}
|
||||||
|
unhideElementById(document, "logout-btn");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
unhideElementById(document, "joinnow-btn");
|
||||||
|
unhideElementById(document, "signin-btn");
|
||||||
|
}
|
||||||
if (saveBtn) {
|
if (saveBtn) {
|
||||||
saveBtn.addEventListener("click", (e) => {
|
saveBtn.addEventListener("click", (e) => {
|
||||||
e.preventDefault();
|
e.preventDefault();
|
||||||
createEvent();
|
createEvent();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
});
|
}));
|
||||||
|
|||||||
@@ -12,32 +12,39 @@ document.addEventListener("DOMContentLoaded", () => {
|
|||||||
// Obsługuje kliknięcie na przycisk "Usuń"
|
// Obsługuje kliknięcie na przycisk "Usuń"
|
||||||
document.body.addEventListener("click", (e) => __awaiter(void 0, void 0, void 0, function* () {
|
document.body.addEventListener("click", (e) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
const target = e.target;
|
const target = e.target;
|
||||||
if (!target.matches(".delete-btn"))
|
if (!target.matches(".mod-btn"))
|
||||||
return; // Sprawdza, czy kliknięto przycisk "Usuń"
|
return; // Sprawdza, czy kliknięto przycisk "Usuń" lub "Edytuj"
|
||||||
const id = target.getAttribute("data-id"); // Pobiera ID wydarzenia
|
const id = target.getAttribute("data-id"); // Pobiera ID wydarzenia
|
||||||
if (!id)
|
if (!id)
|
||||||
return;
|
return;
|
||||||
const confirmed = confirm("Na pewno chcesz usunąć to wydarzenie?"); // Potwierdzenie usunięcia
|
switch (target.id) {
|
||||||
if (!confirmed)
|
case "edit-btn":
|
||||||
return;
|
window.location.href = "/modify.html?event=" + id;
|
||||||
try {
|
break;
|
||||||
// Wysyła żądanie DELETE do API
|
case "remove-btn":
|
||||||
const response = yield fetch(`/api/events/${id}`, {
|
const confirmed = confirm("Na pewno chcesz usunąć to wydarzenie?"); // Potwierdzenie usunięcia
|
||||||
method: "DELETE"
|
if (!confirmed)
|
||||||
});
|
return;
|
||||||
if (response.ok) {
|
try {
|
||||||
// Usuwa kartę z DOM (bez przeładowania strony)
|
// Wysyła żądanie DELETE do API
|
||||||
const card = target.closest(".event-card");
|
const response = yield fetch(`/api/events/${id}`, {
|
||||||
if (card)
|
method: "DELETE"
|
||||||
card.remove();
|
});
|
||||||
}
|
if (response.ok) {
|
||||||
else {
|
// Usuwa kartę z DOM (bez przeładowania strony)
|
||||||
alert("Błąd podczas usuwania wydarzenia.");
|
const card = target.closest(".event-card");
|
||||||
}
|
if (card)
|
||||||
}
|
card.remove();
|
||||||
catch (err) {
|
}
|
||||||
alert("Błąd połączenia z serwerem.");
|
else {
|
||||||
console.error(err);
|
alert("Błąd podczas usuwania wydarzenia.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
alert("Błąd połączenia z serwerem.");
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}));
|
}));
|
||||||
});
|
});
|
||||||
|
|||||||
@@ -1,4 +1,3 @@
|
|||||||
"use strict";
|
|
||||||
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
return new (P || (P = Promise))(function (resolve, reject) {
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
@@ -8,33 +7,117 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|||||||
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, void 0, function* () {
|
import { getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||||
const container = document.getElementById("eventList");
|
var isAscending = false;
|
||||||
if (!container)
|
function toggleListSortOrder(org_id) {
|
||||||
return;
|
isAscending = !isAscending;
|
||||||
try {
|
loadEvents(org_id);
|
||||||
const res = yield fetch("/api/events");
|
}
|
||||||
if (!res.ok)
|
function getEvents(titleOrDescription) {
|
||||||
throw new Error("Błąd pobierania wydarzeń");
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
var res;
|
||||||
|
if (titleOrDescription == null) {
|
||||||
|
res = yield fetch("/api/events" + (isAscending ? "?sort=asc" : ""));
|
||||||
|
if (!res.ok)
|
||||||
|
throw new Error("Błąd pobierania wydarzeń");
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const payload = {
|
||||||
|
titleOrDescription
|
||||||
|
};
|
||||||
|
res = yield fetch('/api/events/search', {
|
||||||
|
method: 'POST',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(payload)
|
||||||
|
});
|
||||||
|
if (!res.ok)
|
||||||
|
throw new Error("Błąd wyszukiwania wydarzeń");
|
||||||
|
}
|
||||||
const events = yield res.json();
|
const events = yield res.json();
|
||||||
if (events.length === 0) {
|
return events;
|
||||||
container.innerHTML = "<p class='text-muted'>Brak wydarzeń do wyświetlenia.</p>";
|
});
|
||||||
|
}
|
||||||
|
function loadEvents(org_id, evs) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const container = document.getElementById("eventList");
|
||||||
|
if (!container)
|
||||||
return;
|
return;
|
||||||
|
var events;
|
||||||
|
try {
|
||||||
|
if (evs == null) {
|
||||||
|
events = yield getEvents();
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
events = yield evs;
|
||||||
|
}
|
||||||
|
if (events.length === 0) {
|
||||||
|
container.innerHTML = "<p class='text-muted'>Brak wydarzeń do wyświetlenia.</p>";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
// Wyczyść kontener przed dodaniem nowych
|
||||||
|
container.innerHTML = '';
|
||||||
|
for (const ev of events) {
|
||||||
|
const card = document.createElement("div");
|
||||||
|
card.className = "event-card filled";
|
||||||
|
//card.innerHTML = `
|
||||||
|
// <span>${ev.title}</span>`
|
||||||
|
// Do odkomentowania kiedy widok podglądu wydarzeń będzie gotowy
|
||||||
|
card.innerHTML = `
|
||||||
|
<span>
|
||||||
|
<a href="/view.html?event=${ev.eventId}" style="color: #2898BD">${ev.title}</a>
|
||||||
|
<p style="margin: 0">${ev.organisation}</p>
|
||||||
|
</span>`;
|
||||||
|
if (org_id == ev.organisationId) {
|
||||||
|
card.innerHTML += `
|
||||||
|
<div>
|
||||||
|
<button class="edit-btn mod-btn" data-id="${ev.eventId}" id="edit-btn">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="24px" viewBox="0 -960 960 960" width="24px" fill="#FFFFFF"><path d="M200-200h57l391-391-57-57-391 391v57Zm-80 80v-170l528-527q12-11 26.5-17t30.5-6q16 0 31 6t26 18l55 56q12 11 17.5 26t5.5 30q0 16-5.5 30.5T817-647L290-120H120Zm640-584-56-56 56 56Zm-141 85-28-29 57 57-29-28Z"/></svg>
|
||||||
|
</button>
|
||||||
|
<button class="remove-btn mod-btn" data-id="${ev.eventId}" id="remove-btn">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#FFFFFF"><path d="M280-440h400v-80H280v80ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg>
|
||||||
|
</button>
|
||||||
|
</div>`;
|
||||||
|
}
|
||||||
|
container.appendChild(card);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
// Wyczyść kontener przed dodaniem nowych
|
catch (err) {
|
||||||
container.innerHTML = '';
|
container.innerHTML = `<p class="text-danger">Błąd ładowania danych.</p>`;
|
||||||
for (const ev of events) {
|
console.error(err);
|
||||||
const card = document.createElement("div");
|
}
|
||||||
card.className = "event-card filled";
|
});
|
||||||
card.innerHTML = `
|
}
|
||||||
<span>${ev.title}</span>
|
document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
<button class="remove-btn delete-btn" data-id="${ev.eventId}"><svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#FFFFFF"><path d="M280-440h400v-80H280v80ZM480-80q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q134 0 227-93t93-227q0-134-93-227t-227-93q-134 0-227 93t-93 227q0 134 93 227t227 93Zm0-320Z"/></svg></button>
|
var org_id = -1;
|
||||||
`;
|
try {
|
||||||
container.appendChild(card);
|
var user = yield getMyAccount();
|
||||||
|
if (user) {
|
||||||
|
if (user.isOrganisation) {
|
||||||
|
unhideElementById(document, "mainContainer");
|
||||||
|
unhideElementById(document, "addnewevent-btn");
|
||||||
|
org_id = user.organisationId;
|
||||||
|
}
|
||||||
|
unhideElementById(document, "logout-btn");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
catch (err) {
|
catch (_a) {
|
||||||
container.innerHTML = `<p class="text-danger">Błąd ładowania danych.</p>`;
|
// console.log("User not signed in. Failing gracefully.");
|
||||||
console.error(err);
|
unhideElementById(document, "joinnow-btn");
|
||||||
|
unhideElementById(document, "signin-btn");
|
||||||
}
|
}
|
||||||
|
loadEvents(org_id);
|
||||||
|
// listen for clicks
|
||||||
|
const listSortToggleButton = document.getElementById("list-sort-btn");
|
||||||
|
if (listSortToggleButton) {
|
||||||
|
listSortToggleButton.addEventListener("click", () => toggleListSortOrder(org_id));
|
||||||
|
}
|
||||||
|
// and for enter in search bar
|
||||||
|
const searchBar = document.getElementById('searchbar');
|
||||||
|
searchBar.addEventListener('keydown', (event) => {
|
||||||
|
if (event.key === 'Enter') {
|
||||||
|
// console.log('Enter key pressed!');
|
||||||
|
var searchResults = getEvents(searchBar.value);
|
||||||
|
loadEvents(org_id, searchResults);
|
||||||
|
}
|
||||||
|
});
|
||||||
}));
|
}));
|
||||||
|
|||||||
97
WebApp/wwwroot/js/eventModify.js
Normal file
97
WebApp/wwwroot/js/eventModify.js
Normal file
@@ -0,0 +1,97 @@
|
|||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
import { getEvent, getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||||
|
const queryString = window.location.search;
|
||||||
|
const urlParams = new URLSearchParams(queryString);
|
||||||
|
const eventId = urlParams.get('event');
|
||||||
|
function modifyEvent() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
// Pobieranie danych z formularza
|
||||||
|
const title = document.getElementById('title').value;
|
||||||
|
const location = document.getElementById('location').value;
|
||||||
|
const description = document.getElementById('description').value;
|
||||||
|
const eventDateRaw = document.getElementById('eventDate').value;
|
||||||
|
// Walidacja prostych pól
|
||||||
|
if (!title || !location || !eventDateRaw) {
|
||||||
|
alert("Please fill out all of the required fields!");
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const eventDate = new Date(eventDateRaw).toISOString();
|
||||||
|
const payload = {
|
||||||
|
title,
|
||||||
|
location,
|
||||||
|
description,
|
||||||
|
eventDate,
|
||||||
|
};
|
||||||
|
try {
|
||||||
|
const response = yield fetch('/api/events/' + eventId, {
|
||||||
|
method: 'PUT',
|
||||||
|
headers: { 'Content-Type': 'application/json' },
|
||||||
|
body: JSON.stringify(payload)
|
||||||
|
});
|
||||||
|
if (!response.ok) {
|
||||||
|
const errorText = yield response.text();
|
||||||
|
throw new Error(errorText);
|
||||||
|
}
|
||||||
|
alert("Wydarzenie zmodyfikowane!");
|
||||||
|
window.location.href = "/"; // Przekierowanie do strony głównej
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
console.error("Błąd podczas modyfikowania:", error);
|
||||||
|
alert("Nie udało się zmodyfikować wydarzenia: " + error);
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
|
var container = document.getElementById("mainContainer");
|
||||||
|
const saveBtn = document.getElementById("saveBtn");
|
||||||
|
try {
|
||||||
|
var user = yield getMyAccount();
|
||||||
|
if (user) {
|
||||||
|
if (user.isOrganisation) {
|
||||||
|
unhideElementById(document, "mainContainer");
|
||||||
|
}
|
||||||
|
unhideElementById(document, "logout-btn");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (_a) {
|
||||||
|
unhideElementById(document, "joinnow-btn");
|
||||||
|
unhideElementById(document, "signin-btn");
|
||||||
|
}
|
||||||
|
if (saveBtn) {
|
||||||
|
saveBtn.addEventListener("click", (e) => {
|
||||||
|
e.preventDefault();
|
||||||
|
modifyEvent();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (eventId !== null && container !== null) {
|
||||||
|
try {
|
||||||
|
const titleInput = document.getElementById('title');
|
||||||
|
const locationInput = document.getElementById('location');
|
||||||
|
const descriptionInput = document.getElementById('description');
|
||||||
|
const dateInput = document.getElementById('eventDate');
|
||||||
|
var ev = yield getEvent(eventId);
|
||||||
|
if (ev === null) {
|
||||||
|
container.innerHTML = "<p class='text-muted'>Brak wydarzeń do wyświetlenia.</p>";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
titleInput.value = ev.title || '';
|
||||||
|
locationInput.value = ev.location || '';
|
||||||
|
descriptionInput.value = ev.description || '';
|
||||||
|
dateInput.value = ev.eventDate.slice(0, 16) || '';
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
console.log(err);
|
||||||
|
container.innerHTML = `<p class="text-danger">` + err + `</p>`;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}));
|
||||||
99
WebApp/wwwroot/js/eventView.js
Normal file
99
WebApp/wwwroot/js/eventView.js
Normal file
@@ -0,0 +1,99 @@
|
|||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
import { getEvent, getMyAccount, unhideElementById } from './generalUseHelpers.js';
|
||||||
|
const queryString = window.location.search;
|
||||||
|
const urlParams = new URLSearchParams(queryString);
|
||||||
|
const eventId = urlParams.get('event');
|
||||||
|
document.addEventListener("DOMContentLoaded", () => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
|
var container = document.getElementById("mainContainer");
|
||||||
|
const modifyBtn = document.getElementById("editBtn");
|
||||||
|
const removeBtn = document.getElementById("removeBtn");
|
||||||
|
var org_id = -1;
|
||||||
|
try {
|
||||||
|
var user = yield getMyAccount();
|
||||||
|
if (user) {
|
||||||
|
if (user.isOrganisation) {
|
||||||
|
org_id = user.organisationId;
|
||||||
|
}
|
||||||
|
unhideElementById(document, "logout-btn");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (_a) {
|
||||||
|
unhideElementById(document, "joinnow-btn");
|
||||||
|
unhideElementById(document, "signin-btn");
|
||||||
|
}
|
||||||
|
var thisEvent = null;
|
||||||
|
try {
|
||||||
|
if (eventId)
|
||||||
|
thisEvent = yield getEvent(eventId);
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
if (container !== null)
|
||||||
|
container.innerHTML = `<p class="text-danger">To wydarzenie nie istnieje! <a href="/" style="color:#2898BD;">Powrót -></a></p>`;
|
||||||
|
}
|
||||||
|
if (thisEvent == null) {
|
||||||
|
if (container !== null)
|
||||||
|
container.innerHTML = `<p class="text-danger">Błąd we wczytywaniu wydarzenia. <a href="/" style="color:#2898BD;">Powrót -></a></p>`;
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
const titleText = document.getElementById("titleText");
|
||||||
|
const locationText = document.getElementById("locationText");
|
||||||
|
const descText = document.getElementById("descText");
|
||||||
|
const dateText = document.getElementById("dateText");
|
||||||
|
const organizerText = document.getElementById("organizerText");
|
||||||
|
const newdateText = new Date(thisEvent.eventDate).toLocaleDateString('pl-PL');
|
||||||
|
const newtimeText = new Date(thisEvent.eventDate).toLocaleTimeString('pl-PL');
|
||||||
|
titleText.innerHTML = thisEvent.title + ` (#${eventId})`;
|
||||||
|
locationText.innerHTML = "Place: " + thisEvent.location;
|
||||||
|
descText.innerHTML = thisEvent.description;
|
||||||
|
dateText.innerHTML = "When: " + newdateText + " " + newtimeText; //thisEvent.eventDate;
|
||||||
|
organizerText.innerHTML = "Organized by: " + thisEvent.organisationName;
|
||||||
|
if (org_id == thisEvent.organisationId) {
|
||||||
|
// Użytkownik jest organizacją, która
|
||||||
|
// stworzyła to wydarzenie
|
||||||
|
unhideElementById(document, "editBtn");
|
||||||
|
unhideElementById(document, "removeBtn");
|
||||||
|
}
|
||||||
|
else if (org_id == -1) {
|
||||||
|
// Użytkownik jest wolontariuszem
|
||||||
|
unhideElementById(document, "applyBtn");
|
||||||
|
}
|
||||||
|
unhideElementById(document, "mainContainer");
|
||||||
|
}
|
||||||
|
if (modifyBtn) {
|
||||||
|
modifyBtn.addEventListener("click", (e) => {
|
||||||
|
window.location.href = "/modify.html?event=" + eventId;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
if (removeBtn) {
|
||||||
|
removeBtn.addEventListener("click", (e) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
|
const confirmed = confirm("Really delete?");
|
||||||
|
if (!confirmed)
|
||||||
|
return;
|
||||||
|
try {
|
||||||
|
// Wysyła żądanie DELETE do API
|
||||||
|
const response = yield fetch(`/api/events/${eventId}`, {
|
||||||
|
method: "DELETE"
|
||||||
|
});
|
||||||
|
if (response.ok) {
|
||||||
|
alert("Event deleted.");
|
||||||
|
window.location.href = "/";
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
alert("Couldn't delete event.");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
catch (err) {
|
||||||
|
alert("Couldn't connect.");
|
||||||
|
console.error(err);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
}
|
||||||
|
}));
|
||||||
37
WebApp/wwwroot/js/generalUseHelpers.js
Normal file
37
WebApp/wwwroot/js/generalUseHelpers.js
Normal file
@@ -0,0 +1,37 @@
|
|||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
export function unhideElementById(document, e) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
var element = document.getElementById(e);
|
||||||
|
if (element) {
|
||||||
|
element.classList.remove('hidden-before-load');
|
||||||
|
}
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export function getEvent(id) {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const res = yield fetch("/api/events/" + id);
|
||||||
|
if (!res.ok) {
|
||||||
|
throw Error("To wydarzenie nie istnieje");
|
||||||
|
}
|
||||||
|
const events = yield res.json();
|
||||||
|
return events;
|
||||||
|
});
|
||||||
|
}
|
||||||
|
export function getMyAccount() {
|
||||||
|
return __awaiter(this, void 0, void 0, function* () {
|
||||||
|
const res = yield fetch("/api/auth/my_account");
|
||||||
|
if (!res.ok) {
|
||||||
|
throw Error("U<>ytkownik niezalogowany!");
|
||||||
|
}
|
||||||
|
const data = yield res.json();
|
||||||
|
return data;
|
||||||
|
});
|
||||||
|
}
|
||||||
42
WebApp/wwwroot/js/login.js
Normal file
42
WebApp/wwwroot/js/login.js
Normal file
@@ -0,0 +1,42 @@
|
|||||||
|
"use strict";
|
||||||
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
||||||
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
||||||
|
return new (P || (P = Promise))(function (resolve, reject) {
|
||||||
|
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
||||||
|
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
||||||
|
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
||||||
|
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
||||||
|
});
|
||||||
|
};
|
||||||
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
const form = document.getElementById("loginForm");
|
||||||
|
const message = document.getElementById("message");
|
||||||
|
form.addEventListener("submit", (e) => __awaiter(void 0, void 0, void 0, function* () {
|
||||||
|
e.preventDefault();
|
||||||
|
message.textContent = "";
|
||||||
|
const email = document.getElementById("email").value;
|
||||||
|
const password = document.getElementById("password").value;
|
||||||
|
try {
|
||||||
|
const response = yield fetch("/api/auth/login", {
|
||||||
|
method: "POST",
|
||||||
|
headers: {
|
||||||
|
"Content-Type": "application/json",
|
||||||
|
},
|
||||||
|
body: JSON.stringify({ email, password }),
|
||||||
|
});
|
||||||
|
const data = yield response.json();
|
||||||
|
if (!response.ok) {
|
||||||
|
message.textContent = data.message || "Login failed.";
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
document.cookie = `token=${data.token}; path=/; SameSite=Lax; Secure`;
|
||||||
|
message.style.color = "green";
|
||||||
|
message.textContent = "Login successful!";
|
||||||
|
window.location.href = "/index.html";
|
||||||
|
}
|
||||||
|
catch (error) {
|
||||||
|
message.textContent = "Something went wrong.";
|
||||||
|
console.error(error);
|
||||||
|
}
|
||||||
|
}));
|
||||||
|
});
|
||||||
91
WebApp/wwwroot/login.html
Normal file
91
WebApp/wwwroot/login.html
Normal file
@@ -0,0 +1,91 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html>
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Sign in</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="/css/style.css" />
|
||||||
|
<link rel="stylesheet" href="/css/panel.css" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<body class="bg-light">
|
||||||
|
<div class="">
|
||||||
|
<!-- Sidebar -->
|
||||||
|
<div class="sidebar">
|
||||||
|
<div class="text-center mb-4">
|
||||||
|
</div>
|
||||||
|
<nav class="sidebar d-flex flex-column align-items-center pt-3">
|
||||||
|
<div class="icon-box my-2">
|
||||||
|
<a href="index.html" class="nav-link text-info mb-3">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M240-200h120v-240h240v240h120v-360L480-740 240-560v360Zm-80 80v-480l320-240 320 240v480H520v-240h-80v240H160Zm320-350Z" /></svg>
|
||||||
|
<br /><h8 class="iconText">Home</h8>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="icon-box my-2">
|
||||||
|
<a href="#" class="nav-link text-info mb-3">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M880-80 720-240H320q-33 0-56.5-23.5T240-320v-40h440q33 0 56.5-23.5T760-440v-280h40q33 0 56.5 23.5T880-640v560ZM160-473l47-47h393v-280H160v327ZM80-280v-520q0-33 23.5-56.5T160-880h440q33 0 56.5 23.5T680-800v280q0 33-23.5 56.5T600-440H240L80-280Zm80-240v-280 280Z" /></svg>
|
||||||
|
<br /><h8 class="iconText">Chats</h8>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="icon-box my-2">
|
||||||
|
<a href="#" class="nav-link text-info mb-3">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M580-240q-42 0-71-29t-29-71q0-42 29-71t71-29q42 0 71 29t29 71q0 42-29 71t-71 29ZM200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33 0 56.5 23.5T840-720v560q0 33-23.5 56.5T760-80H200Zm0-80h560v-400H200v400Zm0-480h560v-80H200v80Zm0 0v-80 80Z" /></svg>
|
||||||
|
<br /><h8 class="iconText">Calendar</h8>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="icon-box mt-auto mb-4">
|
||||||
|
<a href="#" class="nav-link text-info mb-3">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="m370-80-16-128q-13-5-24.5-12T307-235l-119 50L78-375l103-78q-1-7-1-13.5v-27q0-6.5 1-13.5L78-585l110-190 119 50q11-8 23-15t24-12l16-128h220l16 128q13 5 24.5 12t22.5 15l119-50 110 190-103 78q1 7 1 13.5v27q0 6.5-2 13.5l103 78-110 190-118-50q-11 8-23 15t-24 12L590-80H370Zm70-80h79l14-106q31-8 57.5-23.5T639-327l99 41 39-68-86-65q5-14 7-29.5t2-31.5q0-16-2-31.5t-7-29.5l86-65-39-68-99 42q-22-23-48.5-38.5T533-694l-13-106h-79l-14 106q-31 8-57.5 23.5T321-633l-99-41-39 68 86 64q-5 15-7 30t-2 32q0 16 2 31t7 30l-86 65 39 68 99-42q22 23 48.5 38.5T427-266l13 106Zm42-180q58 0 99-41t41-99q0-58-41-99t-99-41q-59 0-99.5 41T342-480q0 58 40.5 99t99.5 41Zm-2-140Z" /></svg>
|
||||||
|
<br /><h8 class="iconText">Settings</h8>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
<!-- Top Nav -->
|
||||||
|
<div class="topnav d-flex justify-content-between align-items-center shadow">
|
||||||
|
<a href="index.html" class="eventsText m-0 logo text-decoration-none">Lend a Hand</a>
|
||||||
|
<div>
|
||||||
|
<button class="button-join hidden-before-load" id="joinnow-btn">Join now</button>
|
||||||
|
<button class="button-sign hidden-before-load" id="signin-btn">Sign In</button>
|
||||||
|
<button class="button-sign hidden-before-load" id="logout-btn">Log out</button>
|
||||||
|
<svg class="position-relative" xmlns="http://www.w3.org/2000/svg" height="50px" viewBox="0 -960 960 960" width="50px" fill="#2898BD"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z" /></svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="main" id="mainContainer">
|
||||||
|
<h1 class="mb-4">Sign in to your organizational/volunteer account</h1>
|
||||||
|
|
||||||
|
<form id="loginForm">
|
||||||
|
|
||||||
|
<div class="form-group mb-2">
|
||||||
|
<label for="email">Login</label>
|
||||||
|
<input type="email" id="email" class="form-control input-field" required />
|
||||||
|
</div>
|
||||||
|
<div class="form-group mb-2">
|
||||||
|
<label for="password">Password</label>
|
||||||
|
<input type="password" id="password" class="form-control input-field" required />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<br />
|
||||||
|
|
||||||
|
<button id="logInBtn" class="button" type="submit">
|
||||||
|
<span>Log in</span>
|
||||||
|
<span>⮞</span>
|
||||||
|
</button>
|
||||||
|
<button id="signUpBtn" class="button" type="button" onclick="alert('Coming soon!')">
|
||||||
|
<span>Sign up</span>
|
||||||
|
<span>⮞</span>
|
||||||
|
</button>
|
||||||
|
<p id="message" style="color: red;"></p>
|
||||||
|
|
||||||
|
</form>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="module" src="/js/login.js"></script> <!-- defer? -->
|
||||||
|
<script type="module" src="/js/generalUseHelpers.js"></script>
|
||||||
|
<script type="module" src="/js/auth.js"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
</html>
|
||||||
88
WebApp/wwwroot/modify.html
Normal file
88
WebApp/wwwroot/modify.html
Normal file
@@ -0,0 +1,88 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="pl">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>Modify existing event</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="/css/style.css" />
|
||||||
|
<link rel="stylesheet" href="/css/panel.css" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<body class="bg-light">
|
||||||
|
<div class="">
|
||||||
|
<!-- Sidebar -->
|
||||||
|
<div class="sidebar">
|
||||||
|
<div class="text-center mb-4">
|
||||||
|
</div>
|
||||||
|
<nav class="sidebar d-flex flex-column align-items-center pt-3">
|
||||||
|
<div class="icon-box my-2">
|
||||||
|
<a href="index.html" class="nav-link text-info mb-3">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M240-200h120v-240h240v240h120v-360L480-740 240-560v360Zm-80 80v-480l320-240 320 240v480H520v-240h-80v240H160Zm320-350Z" /></svg>
|
||||||
|
<br /><h8 class="iconText">Home</h8>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="icon-box my-2">
|
||||||
|
<a href="#" class="nav-link text-info mb-3">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M880-80 720-240H320q-33 0-56.5-23.5T240-320v-40h440q33 0 56.5-23.5T760-440v-280h40q33 0 56.5 23.5T880-640v560ZM160-473l47-47h393v-280H160v327ZM80-280v-520q0-33 23.5-56.5T160-880h440q33 0 56.5 23.5T680-800v280q0 33-23.5 56.5T600-440H240L80-280Zm80-240v-280 280Z" /></svg>
|
||||||
|
<br /><h8 class="iconText">Chats</h8>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="icon-box my-2">
|
||||||
|
<a href="#" class="nav-link text-info mb-3">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M580-240q-42 0-71-29t-29-71q0-42 29-71t71-29q42 0 71 29t29 71q0 42-29 71t-71 29ZM200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33 0 56.5 23.5T840-720v560q0 33-23.5 56.5T760-80H200Zm0-80h560v-400H200v400Zm0-480h560v-80H200v80Zm0 0v-80 80Z" /></svg>
|
||||||
|
<br /><h8 class="iconText">Calendar</h8>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="icon-box mt-auto mb-4">
|
||||||
|
<a href="#" class="nav-link text-info mb-3">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="m370-80-16-128q-13-5-24.5-12T307-235l-119 50L78-375l103-78q-1-7-1-13.5v-27q0-6.5 1-13.5L78-585l110-190 119 50q11-8 23-15t24-12l16-128h220l16 128q13 5 24.5 12t22.5 15l119-50 110 190-103 78q1 7 1 13.5v27q0 6.5-2 13.5l103 78-110 190-118-50q-11 8-23 15t-24 12L590-80H370Zm70-80h79l14-106q31-8 57.5-23.5T639-327l99 41 39-68-86-65q5-14 7-29.5t2-31.5q0-16-2-31.5t-7-29.5l86-65-39-68-99 42q-22-23-48.5-38.5T533-694l-13-106h-79l-14 106q-31 8-57.5 23.5T321-633l-99-41-39 68 86 64q-5 15-7 30t-2 32q0 16 2 31t7 30l-86 65 39 68 99-42q22 23 48.5 38.5T427-266l13 106Zm42-180q58 0 99-41t41-99q0-58-41-99t-99-41q-59 0-99.5 41T342-480q0 58 40.5 99t99.5 41Zm-2-140Z" /></svg>
|
||||||
|
<br /><h8 class="iconText">Settings</h8>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
<!-- Top Nav -->
|
||||||
|
<div class="topnav d-flex justify-content-between align-items-center shadow">
|
||||||
|
<a href="index.html" class="eventsText m-0 logo text-decoration-none">Lend a Hand</a>
|
||||||
|
<div>
|
||||||
|
<button class="button-join hidden-before-load" id="joinnow-btn">Join now</button>
|
||||||
|
<button class="button-sign hidden-before-load" id="signin-btn">Sign In</button>
|
||||||
|
<button class="button-sign hidden-before-load" id="logout-btn">Log out</button>
|
||||||
|
<svg class="position-relative" xmlns="http://www.w3.org/2000/svg" height="50px" viewBox="0 -960 960 960" width="50px" fill="#2898BD"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z" /></svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="main hidden-before-load" id="mainContainer">
|
||||||
|
<h1 class="mb-4">Modify an existing event</h1>
|
||||||
|
|
||||||
|
<div class="form-group mb-2">
|
||||||
|
<label for="title">Title</label>
|
||||||
|
<input id="title" class="form-control input-field" />
|
||||||
|
</div>
|
||||||
|
<div class="form-group mb-2">
|
||||||
|
<label for="location">Location</label>
|
||||||
|
<input id="location" class="form-control input-field" />
|
||||||
|
</div>
|
||||||
|
<div class="form-group mb-2">
|
||||||
|
<label for="description">Description</label>
|
||||||
|
<textarea id="description" class="form-control input-field"></textarea>
|
||||||
|
</div>
|
||||||
|
<div class="form-group mb-2">
|
||||||
|
<label for="eventDate">Date</label>
|
||||||
|
<input id="eventDate" type="datetime-local" class="form-control input-field" />
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<button id="saveBtn" class="button"><span>Update</span><span>⮞</span></button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="module" src="/js/eventModify.js"></script>
|
||||||
|
<script type="module" src="/js/generalUseHelpers.js"></script>
|
||||||
|
</body>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</html>
|
||||||
81
WebApp/wwwroot/view.html
Normal file
81
WebApp/wwwroot/view.html
Normal file
@@ -0,0 +1,81 @@
|
|||||||
|
<!DOCTYPE html>
|
||||||
|
<html lang="pl">
|
||||||
|
<head>
|
||||||
|
<meta charset="UTF-8">
|
||||||
|
<title>View event details</title>
|
||||||
|
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet">
|
||||||
|
<link href="https://fonts.googleapis.com/css2?family=Nunito:wght@400;600;700;800&display=swap" rel="stylesheet">
|
||||||
|
<link rel="stylesheet" href="/css/style.css" />
|
||||||
|
<link rel="stylesheet" href="/css/panel.css" />
|
||||||
|
</head>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
<body class="bg-light">
|
||||||
|
<div class="">
|
||||||
|
<!-- Sidebar -->
|
||||||
|
<div class="sidebar">
|
||||||
|
<div class="text-center mb-4">
|
||||||
|
</div>
|
||||||
|
<nav class="sidebar d-flex flex-column align-items-center pt-3">
|
||||||
|
<div class="icon-box my-2">
|
||||||
|
<a href="index.html" class="nav-link text-info mb-3">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M240-200h120v-240h240v240h120v-360L480-740 240-560v360Zm-80 80v-480l320-240 320 240v480H520v-240h-80v240H160Zm320-350Z" /></svg>
|
||||||
|
<br /><h8 class="iconText">Home</h8>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="icon-box my-2">
|
||||||
|
<a href="#" class="nav-link text-info mb-3">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M880-80 720-240H320q-33 0-56.5-23.5T240-320v-40h440q33 0 56.5-23.5T760-440v-280h40q33 0 56.5 23.5T880-640v560ZM160-473l47-47h393v-280H160v327ZM80-280v-520q0-33 23.5-56.5T160-880h440q33 0 56.5 23.5T680-800v280q0 33-23.5 56.5T600-440H240L80-280Zm80-240v-280 280Z" /></svg>
|
||||||
|
<br /><h8 class="iconText">Chats</h8>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="icon-box my-2">
|
||||||
|
<a href="#" class="nav-link text-info mb-3">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="M580-240q-42 0-71-29t-29-71q0-42 29-71t71-29q42 0 71 29t29 71q0 42-29 71t-71 29ZM200-80q-33 0-56.5-23.5T120-160v-560q0-33 23.5-56.5T200-800h40v-80h80v80h320v-80h80v80h40q33 0 56.5 23.5T840-720v560q0 33-23.5 56.5T760-80H200Zm0-80h560v-400H200v400Zm0-480h560v-80H200v80Zm0 0v-80 80Z" /></svg>
|
||||||
|
<br /><h8 class="iconText">Calendar</h8>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
<div class="icon-box mt-auto mb-4">
|
||||||
|
<a href="#" class="nav-link text-info mb-3">
|
||||||
|
<svg xmlns="http://www.w3.org/2000/svg" height="30px" viewBox="0 -960 960 960" width="30px" fill="#2898BD"><path d="m370-80-16-128q-13-5-24.5-12T307-235l-119 50L78-375l103-78q-1-7-1-13.5v-27q0-6.5 1-13.5L78-585l110-190 119 50q11-8 23-15t24-12l16-128h220l16 128q13 5 24.5 12t22.5 15l119-50 110 190-103 78q1 7 1 13.5v27q0 6.5-2 13.5l103 78-110 190-118-50q-11 8-23 15t-24 12L590-80H370Zm70-80h79l14-106q31-8 57.5-23.5T639-327l99 41 39-68-86-65q5-14 7-29.5t2-31.5q0-16-2-31.5t-7-29.5l86-65-39-68-99 42q-22-23-48.5-38.5T533-694l-13-106h-79l-14 106q-31 8-57.5 23.5T321-633l-99-41-39 68 86 64q-5 15-7 30t-2 32q0 16 2 31t7 30l-86 65 39 68 99-42q22 23 48.5 38.5T427-266l13 106Zm42-180q58 0 99-41t41-99q0-58-41-99t-99-41q-59 0-99.5 41T342-480q0 58 40.5 99t99.5 41Zm-2-140Z" /></svg>
|
||||||
|
<br /><h8 class="iconText">Settings</h8>
|
||||||
|
</a>
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
</div>
|
||||||
|
<!-- Top Nav -->
|
||||||
|
<div class="topnav d-flex justify-content-between align-items-center shadow">
|
||||||
|
<a href="index.html" class="eventsText m-0 logo text-decoration-none">Lend a Hand</a>
|
||||||
|
<div>
|
||||||
|
<button class="button-join hidden-before-load" id="joinnow-btn">Join now</button>
|
||||||
|
<button class="button-sign hidden-before-load" id="signin-btn">Sign In</button>
|
||||||
|
<button class="button-sign hidden-before-load" id="logout-btn">Log out</button>
|
||||||
|
<svg class="position-relative" xmlns="http://www.w3.org/2000/svg" height="50px" viewBox="0 -960 960 960" width="50px" fill="#2898BD"><path d="M234-276q51-39 114-61.5T480-360q69 0 132 22.5T726-276q35-41 54.5-93T800-480q0-133-93.5-226.5T480-800q-133 0-226.5 93.5T160-480q0 59 19.5 111t54.5 93Zm246-164q-59 0-99.5-40.5T340-580q0-59 40.5-99.5T480-720q59 0 99.5 40.5T620-580q0 59-40.5 99.5T480-440Zm0 360q-83 0-156-31.5T197-197q-54-54-85.5-127T80-480q0-83 31.5-156T197-763q54-54 127-85.5T480-880q83 0 156 31.5T763-763q54 54 85.5 127T880-480q0 83-31.5 156T763-197q-54 54-127 85.5T480-80Zm0-80q53 0 100-15.5t86-44.5q-39-29-86-44.5T480-280q-53 0-100 15.5T294-220q39 29 86 44.5T480-160Zm0-360q26 0 43-17t17-43q0-26-17-43t-43-17q-26 0-43 17t-17 43q0 26 17 43t43 17Zm0-60Zm0 360Z" /></svg>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="main hidden-before-load" id="mainContainer">
|
||||||
|
<h1 class="mb-4" id="titleText">Event title</h1>
|
||||||
|
|
||||||
|
<h2 id="organizerText">Organized by: dummy organization</h2>
|
||||||
|
<h2 id="locationText">Place: 127.0.0.1</h2>
|
||||||
|
<h2 id="dateText">When: now or never!</h2>
|
||||||
|
<h3>Description:</h3>
|
||||||
|
<h4 id="descText"></h4><br />
|
||||||
|
|
||||||
|
<button id="applyBtn" class="button hidden-before-load"><span>Apply</span><span>⮞</span></button>
|
||||||
|
<button id="editBtn" class="button hidden-before-load"><span>Modify</span><span>⮞</span></button>
|
||||||
|
<button id="removeBtn" class="button hidden-before-load" style="background-color: red;"><span>Remove permanently</span><span>⮞</span></button>
|
||||||
|
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<script type="module" src="/js/eventView.js"></script>
|
||||||
|
<script type="module" src="/js/generalUseHelpers.js"></script>
|
||||||
|
<script type="module" src="/js/auth.js"></script>
|
||||||
|
|
||||||
|
</body>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
</html>
|
||||||
@@ -5,7 +5,8 @@
|
|||||||
"strict": true,
|
"strict": true,
|
||||||
"esModuleInterop": true,
|
"esModuleInterop": true,
|
||||||
"outDir": "WebApp/wwwroot/js",
|
"outDir": "WebApp/wwwroot/js",
|
||||||
"lib": [ "es2015", "dom" ]
|
"lib": [ "es2017", "dom" ]
|
||||||
},
|
},
|
||||||
"include": [ "WebApp/ts/**/*" ]
|
"include": [ "WebApp/ts/**/*" ],
|
||||||
|
"compileOnSave": true
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user