Skip to content

Commit d9f13f2

Browse files
authored
Merge pull request #57 from jmdotdev/add-user-model-and-auth-logic
Add user entity and registration logic
2 parents c75ffb2 + 15d4788 commit d9f13f2

10 files changed

Lines changed: 162 additions & 0 deletions

File tree

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
using Microsoft.AspNetCore.Http;
2+
using Microsoft.AspNetCore.Mvc;
3+
4+
namespace Eventz.Api.Controllers
5+
{
6+
[Route("api/[controller]")]
7+
[ApiController]
8+
public class AuthController : ControllerBase
9+
{
10+
}
11+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Eventz.Application.Dtos
8+
{
9+
internal class LoginDto
10+
{
11+
public string Email { get; set; }
12+
public string Password { get; set; }
13+
}
14+
}
Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Eventz.Application.Dtos
8+
{
9+
public class RegisterDto
10+
{
11+
public string Email { get; set; }
12+
13+
public string UserName { get; set; }
14+
public string Password { get; set; }
15+
16+
}
17+
}
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Eventz.Application.Features.Auth.Login
8+
{
9+
internal class LoginCommand
10+
{
11+
}
12+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Eventz.Application.Common;
2+
using Eventz.Application.Dtos;
3+
using MediatR;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Eventz.Application.Features.Auth.Register
11+
{
12+
internal class RegisterCommand
13+
{
14+
public record RegistrationCommand (string UserName, string Email, string Password) : IRequest<ApiResponse<RegisterDto>>;
15+
}
16+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
using MediatR;
2+
using System;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Text;
6+
using System.Threading.Tasks;
7+
8+
namespace Eventz.Application.Features.Auth.Register
9+
{
10+
internal class RegisterHandler
11+
{
12+
13+
}
14+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
using Eventz.Application.Dtos;
2+
using Eventz.Domain.Entitites;
3+
using System;
4+
using System.Collections.Generic;
5+
using System.Linq;
6+
using System.Text;
7+
using System.Threading.Tasks;
8+
9+
namespace Eventz.Application.Interfaces
10+
{
11+
public interface IAuth
12+
{
13+
public Task<RegisterDto> RegisterUser(RegisterDto registerDto);
14+
}
15+
16+
}
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
using System;
2+
using System.Collections.Generic;
3+
using System.Linq;
4+
using System.Text;
5+
using System.Threading.Tasks;
6+
7+
namespace Eventz.Domain.Entitites
8+
{
9+
public class User
10+
{
11+
public string Id { get; set; }
12+
public Guid UserToken { get; set; } = new Guid();
13+
public string UserName { get; set; }
14+
public string Email { get; set; }
15+
public string Password { get; set; }
16+
public DateTime CreatedAt { get; set; }
17+
public List<Ticket> Tickets { get; set; }
18+
public List<Event> Events { get; set; }
19+
}
20+
}

eventz-api/Eventz.Infrastructure/AppDbContext.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,5 +12,7 @@ public AppDbContext(DbContextOptions<AppDbContext> options) : base(options)
1212
public DbSet<Event> Events => Set<Event>();
1313

1414
public DbSet<Category> Categories => Set<Category>();
15+
16+
public DbSet<User> Users => Set<User>();
1517
}
1618
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
using Eventz.Application.Dtos;
2+
using Eventz.Application.Interfaces;
3+
using Eventz.Domain.Entitites;
4+
using System;
5+
using System.Collections.Generic;
6+
using System.Linq;
7+
using System.Text;
8+
using System.Threading.Tasks;
9+
10+
namespace Eventz.Infrastructure.Repositories.Auth
11+
{
12+
public class AuthRepository : IAuth
13+
{
14+
private AppDbContext _context;
15+
16+
public AuthRepository(AppDbContext context)
17+
{
18+
_context = context;
19+
}
20+
21+
public async Task<RegisterDto> RegisterUser (RegisterDto registerDto)
22+
{
23+
var user = new User{
24+
UserName = registerDto.UserName,
25+
Email = registerDto.Email,
26+
Password = registerDto.Password, //TODO: Hash password
27+
CreatedAt = DateTime.Now
28+
};
29+
await _context.Users.AddAsync(user);
30+
await _context.SaveChangesAsync();
31+
return new RegisterDto
32+
{
33+
UserName = registerDto.UserName,
34+
Email = registerDto.Email,
35+
Password = registerDto.Password,
36+
};
37+
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)