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

User auth #61

Draft
wants to merge 3 commits into
base: main
Choose a base branch
from
Draft
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
21 changes: 21 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -390,3 +390,24 @@ FodyWeavers.xsd
.idea/
*.sln.iml

# Vim gitignore
# https://github.com/github/gitignore/blob/main/Global/Vim.gitignore
# Swap
[._]*.s[a-v][a-z]
!*.svg # comment out if you don't need vector files
[._]*.sw[a-p]
[._]s[a-rt-v][a-z]
[._]ss[a-gi-z]
[._]sw[a-p]

# Session
Session.vim
Sessionx.vim

# Temporary
.netrwhist
*~
# Auto-generated tag files
tags
# Persistent undo
[._]*.un~
1 change: 1 addition & 0 deletions migrations/20220206082350_add-user.down.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DROP TABLE IF EXISTS `user`;
9 changes: 9 additions & 0 deletions migrations/20220206082350_add-user.up.sql
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
CREATE TABLE IF NOT EXISTS `user` (
id BIGINT NOT NULL AUTO_INCREMENT PRIMARY KEY,
email varchar(255) NOT NULL COMMENT 'Email',
password_hash varchar(255) NOT NULL COMMENT 'Hashed password',
is_deleted TINYINT(1) NOT NULL DEFAULT 0 COMMENT 'Whether the item is deleted or not. 0 = active, 1 = deleted',
created_on DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP COMMENT 'The DateTime when the item was created',
updated_on DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT 'The DateTime when the item was created',
KEY `idx_email` (`email`)
) ENGINE=INNODB COMMENT 'Contains user information.';
47 changes: 47 additions & 0 deletions src/Api/Controllers/AccountController.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
using Shared.Models;
using Shared.Repositories;
using System.Collections.Generic;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Mvc;
using Microsoft.Extensions.Logging;
using System.Data;

namespace Api.Controllers
{
[ApiController]
[Route("[controller]")]
public class AccountController : ControllerBase
{
private readonly ILogger<AccountController> _logger;
private readonly IDbTransaction _transaction;
private readonly IUserRepository _userRepository;

public AccountController(ILogger<AccountController> logger, IDbTransaction transaction, IUserRepository userRepository)
{
_logger = logger;
_transaction = transaction;
_userRepository = userRepository;
}

[HttpPost("register")]
public async Task Register()
{
await Task.Delay(1);
throw new System.NotImplementedException();
}

[HttpPost("login")]
public async Task Login()
{
await Task.Delay(1);
throw new System.NotImplementedException();
}

[HttpGet("me")]
public async Task Get()
{
await Task.Delay(1);
throw new System.NotImplementedException();
}
}
}
1 change: 1 addition & 0 deletions src/Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
});
services.AddScoped<IJobRepository, JobRepository>();
services.AddScoped<ICompanyRepository, CompanyRepository>();
services.AddScoped<IUserRepository, UserRepository>();

services.AddControllers();
services.AddSwaggerGen(c =>
Expand Down
14 changes: 14 additions & 0 deletions src/Shared/IUserRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Shared.Models;

namespace Shared.Repositories
{
public interface IUserRepository
{
Task<List<User>> Get();
Task<User> Get(int id);
Task Insert(User User);
Task Update(User User);
}
}
8 changes: 8 additions & 0 deletions src/Shared/Models/User.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
namespace Shared.Models
{
public class User : BaseModel
{
public string Email { get; set; }
public string PasswordHash { get; set; }
}
}
29 changes: 29 additions & 0 deletions src/Shared/Repositories/UserRepository.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
using System.Collections.Generic;
using System.Threading.Tasks;
using Shared.Models;

namespace Shared.Repositories
{
public class UserRepository : IUserRepository
{
public Task<List<User>> Get()
{
throw new System.NotImplementedException();
}

public Task<User> Get(int id)
{
throw new System.NotImplementedException();
}

public Task Insert(User User)
{
throw new System.NotImplementedException();
}

public Task Update(User User)
{
throw new System.NotImplementedException();
}
}
}