Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[RSN-67] Add more event statuses and fix some errors #53

Merged
merged 5 commits into from
Jun 9, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion 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 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 Expand Up @@ -281,8 +282,8 @@
.HasConstraintName("user_interest_user_id_fkey");
});

OnModelCreatingPartial(modelBuilder);

Check warning on line 285 in Server/ReasnAPI/ReasnAPI/Models/Database/ReasnContext.cs

View workflow job for this annotation

GitHub Actions / dotnet-tests (ubuntu-latest)

Supply an implementation for the partial method, otherwise this call will be ignored. (https://rules.sonarsource.com/csharp/RSPEC-3251)

Check warning on line 285 in Server/ReasnAPI/ReasnAPI/Models/Database/ReasnContext.cs

View workflow job for this annotation

GitHub Actions / dotnet-tests (ubuntu-latest)

Supply an implementation for the partial method, otherwise this call will be ignored. (https://rules.sonarsource.com/csharp/RSPEC-3251)

Check warning on line 285 in Server/ReasnAPI/ReasnAPI/Models/Database/ReasnContext.cs

View workflow job for this annotation

GitHub Actions / dotnet-tests (macos-latest)

Supply an implementation for the partial method, otherwise this call will be ignored. (https://rules.sonarsource.com/csharp/RSPEC-3251)

Check warning on line 285 in Server/ReasnAPI/ReasnAPI/Models/Database/ReasnContext.cs

View workflow job for this annotation

GitHub Actions / dotnet-tests (macos-latest)

Supply an implementation for the partial method, otherwise this call will be ignored. (https://rules.sonarsource.com/csharp/RSPEC-3251)

Check warning on line 285 in Server/ReasnAPI/ReasnAPI/Models/Database/ReasnContext.cs

View workflow job for this annotation

GitHub Actions / dotnet-tests (windows-latest)

Supply an implementation for the partial method, otherwise this call will be ignored. (https://rules.sonarsource.com/csharp/RSPEC-3251)

Check warning on line 285 in Server/ReasnAPI/ReasnAPI/Models/Database/ReasnContext.cs

View workflow job for this annotation

GitHub Actions / dotnet-tests (windows-latest)

Supply an implementation for the partial method, otherwise this call will be ignored. (https://rules.sonarsource.com/csharp/RSPEC-3251)
}

partial void OnModelCreatingPartial(ModelBuilder modelBuilder);

Check warning on line 288 in Server/ReasnAPI/ReasnAPI/Models/Database/ReasnContext.cs

View workflow job for this annotation

GitHub Actions / dotnet-tests (ubuntu-latest)

Supply an implementation for this partial method. (https://rules.sonarsource.com/csharp/RSPEC-3251)

Check warning on line 288 in Server/ReasnAPI/ReasnAPI/Models/Database/ReasnContext.cs

View workflow job for this annotation

GitHub Actions / dotnet-tests (ubuntu-latest)

Supply an implementation for this partial method. (https://rules.sonarsource.com/csharp/RSPEC-3251)

Check warning on line 288 in Server/ReasnAPI/ReasnAPI/Models/Database/ReasnContext.cs

View workflow job for this annotation

GitHub Actions / dotnet-tests (macos-latest)

Supply an implementation for this partial method. (https://rules.sonarsource.com/csharp/RSPEC-3251)

Check warning on line 288 in Server/ReasnAPI/ReasnAPI/Models/Database/ReasnContext.cs

View workflow job for this annotation

GitHub Actions / dotnet-tests (macos-latest)

Supply an implementation for this partial method. (https://rules.sonarsource.com/csharp/RSPEC-3251)

Check warning on line 288 in Server/ReasnAPI/ReasnAPI/Models/Database/ReasnContext.cs

View workflow job for this annotation

GitHub Actions / dotnet-tests (windows-latest)

Supply an implementation for this partial method. (https://rules.sonarsource.com/csharp/RSPEC-3251)

Check warning on line 288 in Server/ReasnAPI/ReasnAPI/Models/Database/ReasnContext.cs

View workflow job for this annotation

GitHub Actions / dotnet-tests (windows-latest)

Supply an implementation for this partial method. (https://rules.sonarsource.com/csharp/RSPEC-3251)
}
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,
raczu marked this conversation as resolved.
Show resolved Hide resolved
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
Comment on lines +71 to +72
Copy link
Owner

Choose a reason for hiding this comment

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

Suggested change
ZipCode = !string.IsNullOrEmpty(request.Address.ZipCode) ?
request.Address.ZipCode : null
ZipCode = request?.Address?.ZipCode

Copy link
Owner

Choose a reason for hiding this comment

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

Context: we can use null propagation to check for nulls, for empty ones I think we don't care really, propably it will be handled on FE anyways

Copy link
Owner

Choose a reason for hiding this comment

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

But if you really want to check it for being empty then alright, let's go with that

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Turned out that not existing fields are set to null by default, however if their value will be set to empty string this violates database and causing exception

}
};
_context.Users.Add(user);
Expand Down
Loading