Skip to content

Commit

Permalink
[RSN-67] Add more event statuses and fix some errors (#53)
Browse files Browse the repository at this point in the history
* feat: add more event statuses and refactor exsiting ones

* fix: register now properly handles missing phone and zip-code

* chore: add proper library of FluentValidation

Additionally, added 'ValidateNever' attribute to login and register
request classes to get rid of default validation performed by
ApiController.

* refactor: remove redundant null checks

* Revert "refactor: remove redundant null checks"

This reverts commit 7a5bf14.
  • Loading branch information
raczu authored Jun 9, 2024
1 parent fa322e2 commit f1e6889
Show file tree
Hide file tree
Showing 11 changed files with 57 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Database/init-db.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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');

Expand Down
12 changes: 6 additions & 6 deletions Database/init-dev-data.sql
Original file line number Diff line number Diff line change
Expand Up @@ -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));

Expand Down
Empty file modified Database/init-users.sh
100644 → 100755
Empty file.
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
using Microsoft.AspNetCore.Mvc.ModelBinding.Validation;

namespace ReasnAPI.Models.Authentication;

[ValidateNever]
public class LoginRequest
{
public string Email { get; set; } = null!;
Expand Down
Original file line number Diff line number Diff line change
@@ -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!;
Expand Down
9 changes: 5 additions & 4 deletions Server/ReasnAPI/ReasnAPI/Models/Database/ReasnContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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<EventStatus>("common", "event_status")
.HasPostgresEnum<ObjectType>("common", "object_type")
.HasPostgresEnum<ParticipantStatus>("common", "participant_status")
.HasPostgresEnum<UserRole>("users", "role");

modelBuilder.Entity<Address>(entity =>
{
entity.HasKey(e => e.Id).HasName("address_pkey");
Expand Down
25 changes: 20 additions & 5 deletions Server/ReasnAPI/ReasnAPI/Models/Enums/EventStatus.cs
Original file line number Diff line number Diff line change
@@ -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
}
9 changes: 7 additions & 2 deletions Server/ReasnAPI/ReasnAPI/Models/Enums/ObjectType.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
namespace ReasnAPI.Models.Enums;
using NpgsqlTypes;

namespace ReasnAPI.Models.Enums;

public enum ObjectType
{
Event,
[PgName("Event")]
Event,

[PgName("User")]
User
}
9 changes: 7 additions & 2 deletions Server/ReasnAPI/ReasnAPI/Models/Enums/ParticipantStatus.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
namespace ReasnAPI.Models.Enums;
using NpgsqlTypes;

namespace ReasnAPI.Models.Enums;

public enum ParticipantStatus
{
Interested,
[PgName("Interested")]
Interested,

[PgName("Participating")]
Participating
}
3 changes: 2 additions & 1 deletion Server/ReasnAPI/ReasnAPI/ReasnAPI.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="FluentValidation.AspNetCore" Version="11.3.0" />
<PackageReference Include="FluentValidation" Version="11.9.1" />
<PackageReference Include="FluentValidation.DependencyInjectionExtensions" Version="11.9.1" />
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.5" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
using ReasnAPI.Models.Authentication;
using ReasnAPI.Models.Database;
using ReasnAPI.Models.Enums;
Expand Down Expand Up @@ -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)
{
Expand All @@ -59,6 +58,7 @@ public User Register(RegisterRequest request)
Email = request.Email,
Username = request.Username,
Role = Enum.Parse<UserRole>(request.Role),
Phone = !string.IsNullOrEmpty(request.Phone) ? request.Phone : null,
IsActive = true,
CreatedAt = DateTime.UtcNow,
UpdatedAt = DateTime.UtcNow,
Expand All @@ -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);
Expand Down

0 comments on commit f1e6889

Please sign in to comment.