diff --git a/Database/init-db.sql b/Database/init-db.sql index 206c7fed..e178ba36 100644 --- a/Database/init-db.sql +++ b/Database/init-db.sql @@ -3,7 +3,7 @@ CREATE SCHEMA users; CREATE SCHEMA common; CREATE TYPE common.participant_status AS ENUM ('Interested', 'Participating'); -CREATE TYPE common.event_status AS ENUM ('Completed', 'In progress', 'Approved', 'Waiting for approval'); +CREATE TYPE common.event_status AS ENUM ('Completed', 'Ongoing', 'Cancelled', 'Approved', 'Pending approval', 'Rejected'); CREATE TYPE users.role AS ENUM ('User', 'Organizer', 'Admin'); CREATE TYPE common.object_type AS ENUM ('Event', 'User'); diff --git a/Database/init-dev-data.sql b/Database/init-dev-data.sql index 818e37d3..5588d9ce 100644 --- a/Database/init-dev-data.sql +++ b/Database/init-dev-data.sql @@ -26,14 +26,14 @@ SELECT setval('users.user_id_seq', (SELECT MAX(id) FROM users.user)); INSERT INTO events.event ("id", "name", "address_id", "description", "organizer_id", "start_at", "end_at", "created_at", "updated_at", "slug", "status") VALUES (1, 'Tech Conference', 1, 'Annual tech conference', 1, '2023-10-01 09:00:00', '2023-10-02 17:00:00', '2023-09-01 08:00:00', '2023-09-01 08:00:00', 'tech-conference', 'Approved'), -(2, 'Health Symposium', 2, 'Health and wellness symposium', 2, '2023-11-05 09:00:00', '2023-11-06 17:00:00', '2023-10-05 08:00:00', '2023-10-05 08:00:00', 'health-symposium', 'In progress'), -(3, 'Koncert Rockowy', 3, 'Występ ulubionych zespołów rockowych', 2, CURRENT_TIMESTAMP - '1 day'::INTERVAL, CURRENT_TIMESTAMP + '4 hours'::INTERVAL, '2023-09-01 08:00:00', '2023-09-01 08:00:00', 'koncert-rockowy', 'Waiting for approval'), +(2, 'Health Symposium', 2, 'Health and wellness symposium', 2, '2023-11-05 09:00:00', '2023-11-06 17:00:00', '2023-10-05 08:00:00', '2023-10-05 08:00:00', 'health-symposium', 'Ongoing'), +(3, 'Koncert Rockowy', 3, 'Występ ulubionych zespołów rockowych', 2, CURRENT_TIMESTAMP - '1 day'::INTERVAL, CURRENT_TIMESTAMP + '4 hours'::INTERVAL, '2023-09-01 08:00:00', '2023-09-01 08:00:00', 'koncert-rockowy', 'Pending approval'), (4, 'Konferencja IT', 4, 'Coroczna konferencja technologiczna', 1, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP + '3 hours'::INTERVAL, '2023-10-02 17:00:00', '2023-10-02 18:00:00', 'konferencja-it', 'Completed'), -(5, 'Mecz Piłki Nożnej', 5, 'Mecz drużynowej rywalizacji w piłce nożnej', 3, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP + '3 hours'::INTERVAL, '2022-12-01 08:00:00', '2023-09-01 08:30:00', 'mecz-pilki-noznej', 'In progress'), -(6, 'Festiwal Elektroniczny', 6, 'Największe hity muzyki elektronicznej', 4, CURRENT_TIMESTAMP - '4 day'::INTERVAL, CURRENT_TIMESTAMP - '2 days'::INTERVAL, '2023-09-01 08:00:00', '2023-09-02 08:00:00', 'festiwal-elektroniczny', 'Waiting for approval'), +(5, 'Mecz Piłki Nożnej', 5, 'Mecz drużynowej rywalizacji w piłce nożnej', 3, CURRENT_TIMESTAMP, CURRENT_TIMESTAMP + '3 hours'::INTERVAL, '2022-12-01 08:00:00', '2023-09-01 08:30:00', 'mecz-pilki-noznej', 'Ongoing'), +(6, 'Festiwal Elektroniczny', 6, 'Największe hity muzyki elektronicznej', 4, CURRENT_TIMESTAMP - '4 day'::INTERVAL, CURRENT_TIMESTAMP - '2 days'::INTERVAL, '2023-09-01 08:00:00', '2023-09-02 08:00:00', 'festiwal-elektroniczny', 'Pending approval'), (7, 'Koncert Hip-Hopowy', 7, 'Najnowsze hity hip-hopu w wykonaniu gwiazd', 6, CURRENT_TIMESTAMP + '2 days'::INTERVAL, CURRENT_TIMESTAMP + '2 days'::INTERVAL + '4 hours'::INTERVAL, '2023-10-08 17:00:00', '2023-11-01 09:19:22', 'koncert-hip-hopowy', 'Completed'), -(8, 'Wieczór Jazzowy', 8, 'Relaksujące dźwięki jazzu w kameralnej atmosferze', 8, CURRENT_TIMESTAMP + '1 day'::INTERVAL, CURRENT_TIMESTAMP + '1 day'::INTERVAL + '5 hours'::INTERVAL, '2023-09-01 08:00:00', '2023-09-01 08:00:00', 'wieczor-jazzowy', 'In progress'), -(9, 'Koncert Klasyczny', 9, 'Muzyka klasyczna w wykonaniu renomowanych artystów', 10, CURRENT_TIMESTAMP + '1 day'::INTERVAL, CURRENT_TIMESTAMP + '1 day'::INTERVAL + '3 hours'::INTERVAL, '2023-01-01 15:00:00', '2023-02-01 08:00:00', 'koncert-klasyczny', 'Waiting for approval'), +(8, 'Wieczór Jazzowy', 8, 'Relaksujące dźwięki jazzu w kameralnej atmosferze', 8, CURRENT_TIMESTAMP + '1 day'::INTERVAL, CURRENT_TIMESTAMP + '1 day'::INTERVAL + '5 hours'::INTERVAL, '2023-09-01 08:00:00', '2023-09-01 08:00:00', 'wieczor-jazzowy', 'Ongoing'), +(9, 'Koncert Klasyczny', 9, 'Muzyka klasyczna w wykonaniu renomowanych artystów', 10, CURRENT_TIMESTAMP + '1 day'::INTERVAL, CURRENT_TIMESTAMP + '1 day'::INTERVAL + '3 hours'::INTERVAL, '2023-01-01 15:00:00', '2023-02-01 08:00:00', 'koncert-klasyczny', 'Pending approval'), (10, 'Turniej w League of Legends', 10, 'Turniej LAN dla miłośnikow esportu i gry League of Legends', 10, CURRENT_TIMESTAMP - '1 day'::INTERVAL, CURRENT_TIMESTAMP - '3 hours'::INTERVAL, '2023-01-01 15:00:00', '2023-02-01 08:00:00', 'turniej-lol', 'Completed'); SELECT setval('events.event_id_seq', (SELECT MAX(id) FROM events.event)); diff --git a/Database/init-users.sh b/Database/init-users.sh old mode 100644 new mode 100755 diff --git a/Server/ReasnAPI/ReasnAPI/Models/Authentication/LoginRequest.cs b/Server/ReasnAPI/ReasnAPI/Models/Authentication/LoginRequest.cs index addc4f34..f5486b70 100644 --- a/Server/ReasnAPI/ReasnAPI/Models/Authentication/LoginRequest.cs +++ b/Server/ReasnAPI/ReasnAPI/Models/Authentication/LoginRequest.cs @@ -1,5 +1,8 @@ +using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; + namespace ReasnAPI.Models.Authentication; +[ValidateNever] public class LoginRequest { public string Email { get; set; } = null!; diff --git a/Server/ReasnAPI/ReasnAPI/Models/Authentication/RegisterRequest.cs b/Server/ReasnAPI/ReasnAPI/Models/Authentication/RegisterRequest.cs index cbcbb81a..bbf22c8b 100644 --- a/Server/ReasnAPI/ReasnAPI/Models/Authentication/RegisterRequest.cs +++ b/Server/ReasnAPI/ReasnAPI/Models/Authentication/RegisterRequest.cs @@ -1,7 +1,9 @@ +using Microsoft.AspNetCore.Mvc.ModelBinding.Validation; using ReasnAPI.Models.DTOs; namespace ReasnAPI.Models.Authentication; +[ValidateNever] public class RegisterRequest { public string Name { get; set; } = null!; diff --git a/Server/ReasnAPI/ReasnAPI/Models/Database/ReasnContext.cs b/Server/ReasnAPI/ReasnAPI/Models/Database/ReasnContext.cs index 45232529..ed05f407 100644 --- a/Server/ReasnAPI/ReasnAPI/Models/Database/ReasnContext.cs +++ b/Server/ReasnAPI/ReasnAPI/Models/Database/ReasnContext.cs @@ -48,10 +48,11 @@ protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder) { modelBuilder - .HasPostgresEnum("common", "event_status", new[] { "Completed", "In progress", "Approved", "Waiting for approval" }) - .HasPostgresEnum("common", "object_type", new[] { "Event", "User" }) - .HasPostgresEnum("common", "participant_status", new[] { "Interested", "Participating" }) - .HasPostgresEnum("users", "role", new[] { "User", "Organizer", "Admin" }); + .HasPostgresEnum("common", "event_status") + .HasPostgresEnum("common", "object_type") + .HasPostgresEnum("common", "participant_status") + .HasPostgresEnum("users", "role"); + modelBuilder.Entity
(entity => { entity.HasKey(e => e.Id).HasName("address_pkey"); diff --git a/Server/ReasnAPI/ReasnAPI/Models/Enums/EventStatus.cs b/Server/ReasnAPI/ReasnAPI/Models/Enums/EventStatus.cs index 102991eb..a9c31d57 100644 --- a/Server/ReasnAPI/ReasnAPI/Models/Enums/EventStatus.cs +++ b/Server/ReasnAPI/ReasnAPI/Models/Enums/EventStatus.cs @@ -1,9 +1,24 @@ -namespace ReasnAPI.Models.Enums; +using NpgsqlTypes; + +namespace ReasnAPI.Models.Enums; public enum EventStatus { - Completed, - Inprogress, - Approved, - WaitingForApproval + [PgName("Completed")] + Completed, + + [PgName("Ongoing")] + Ongoing, + + [PgName("Cancelled")] + Cancelled, + + [PgName("Approved")] + Approved, + + [PgName("Pending approval")] + PendingApproval, + + [PgName("Rejected")] + Rejected } \ No newline at end of file diff --git a/Server/ReasnAPI/ReasnAPI/Models/Enums/ObjectType.cs b/Server/ReasnAPI/ReasnAPI/Models/Enums/ObjectType.cs index bb194063..1fbc4a30 100644 --- a/Server/ReasnAPI/ReasnAPI/Models/Enums/ObjectType.cs +++ b/Server/ReasnAPI/ReasnAPI/Models/Enums/ObjectType.cs @@ -1,7 +1,12 @@ -namespace ReasnAPI.Models.Enums; +using NpgsqlTypes; + +namespace ReasnAPI.Models.Enums; public enum ObjectType { - Event, + [PgName("Event")] + Event, + + [PgName("User")] User } \ No newline at end of file diff --git a/Server/ReasnAPI/ReasnAPI/Models/Enums/ParticipantStatus.cs b/Server/ReasnAPI/ReasnAPI/Models/Enums/ParticipantStatus.cs index 0584f578..d15b6e1b 100644 --- a/Server/ReasnAPI/ReasnAPI/Models/Enums/ParticipantStatus.cs +++ b/Server/ReasnAPI/ReasnAPI/Models/Enums/ParticipantStatus.cs @@ -1,7 +1,12 @@ -namespace ReasnAPI.Models.Enums; +using NpgsqlTypes; + +namespace ReasnAPI.Models.Enums; public enum ParticipantStatus { - Interested, + [PgName("Interested")] + Interested, + + [PgName("Participating")] Participating } \ No newline at end of file diff --git a/Server/ReasnAPI/ReasnAPI/ReasnAPI.csproj b/Server/ReasnAPI/ReasnAPI/ReasnAPI.csproj index 312bd617..58635dd3 100644 --- a/Server/ReasnAPI/ReasnAPI/ReasnAPI.csproj +++ b/Server/ReasnAPI/ReasnAPI/ReasnAPI.csproj @@ -9,7 +9,8 @@ - + + all diff --git a/Server/ReasnAPI/ReasnAPI/Services/Authentication/AuthService.cs b/Server/ReasnAPI/ReasnAPI/Services/Authentication/AuthService.cs index 6b35076c..c59f47e8 100644 --- a/Server/ReasnAPI/ReasnAPI/Services/Authentication/AuthService.cs +++ b/Server/ReasnAPI/ReasnAPI/Services/Authentication/AuthService.cs @@ -1,5 +1,4 @@ using Microsoft.AspNetCore.Identity; -using Microsoft.EntityFrameworkCore; using ReasnAPI.Models.Authentication; using ReasnAPI.Models.Database; using ReasnAPI.Models.Enums; @@ -44,7 +43,7 @@ public User Register(RegisterRequest request) var userAlreadyExists = _context.Users.Any(u => u.Email.ToUpper() == request.Email.ToUpper() || u.Username.ToUpper() == request.Username.ToUpper() || - u.Phone == request.Phone); + (!string.IsNullOrEmpty(request.Phone) && u.Phone == request.Phone)); if (userAlreadyExists) { @@ -59,6 +58,7 @@ public User Register(RegisterRequest request) Email = request.Email, Username = request.Username, Role = Enum.Parse(request.Role), + Phone = !string.IsNullOrEmpty(request.Phone) ? request.Phone : null, IsActive = true, CreatedAt = DateTime.UtcNow, UpdatedAt = DateTime.UtcNow, @@ -68,6 +68,8 @@ public User Register(RegisterRequest request) City = request.Address.City, Street = request.Address.Street, State = request.Address.State, + ZipCode = !string.IsNullOrEmpty(request.Address.ZipCode) ? + request.Address.ZipCode : null } }; _context.Users.Add(user);