Loading Kollectionized.Api/Controllers/AccountUpdateController.cs +1 −2 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Kollectionized.Api.Data; using Kollectionized.Api.Dtos; using Kollectionized.Api.Models; namespace Kollectionized.Api.Controllers; Loading @@ -25,7 +24,7 @@ public class AccountUpdateController(AppDbContext context) : ControllerBase user.Username = dto.NewUsername; } user.Bio = dto.Bio ?? user.Bio; user.Bio = dto.Bio; context.Users.Update(user); await context.SaveChangesAsync(); Loading Kollectionized.Api/Controllers/AuthController.cs +10 −37 Original line number Diff line number Diff line Loading @@ -55,13 +55,14 @@ public class AuthController(AppDbContext context) : ControllerBase if (!BCrypt.Net.BCrypt.Verify(dto.Password, user.PasswordHash)) return Unauthorized("Invalid credentials."); var userDto = new UserDto( Id: user.Id, Username: user.Username, CreatedAt: user.CreatedAt, LastUsername: user.LastUsername ?? string.Empty, Bio: user.Bio ?? string.Empty ); var userDto = new UserDto { Id = user.Id, Username = user.Username, CreatedAt = user.CreatedAt, LastUsername = user.LastUsername ?? string.Empty, Bio = user.Bio ?? string.Empty, }; return Ok(userDto); } Loading @@ -72,12 +73,12 @@ public class AuthController(AppDbContext context) : ControllerBase } [HttpDelete("user/{username}")] public async Task<IActionResult> DeleteAccount(string username, [FromBody] PasswordOnlyDto dto) public async Task<IActionResult> DeleteAccount(string username, string password) { try { var user = await context.Users.FirstOrDefaultAsync(u => u.Username == username); if (user == null || !BCrypt.Net.BCrypt.Verify(dto.Password, user.PasswordHash)) if (user == null || !BCrypt.Net.BCrypt.Verify(password, user.PasswordHash)) return Unauthorized("Invalid password."); if (user.Username.StartsWith("[del-")) Loading @@ -104,32 +105,4 @@ public class AuthController(AppDbContext context) : ControllerBase return StatusCode(500, "Something went wrong on the server"); } } [HttpPut("change-username")] public async Task<IActionResult> ChangeUsername([FromBody] UsernameChangeDto dto) { try { var user = await context.Users.FirstOrDefaultAsync(u => u.Username == dto.CurrentUsername); if (user == null || !BCrypt.Net.BCrypt.Verify(dto.Password, user.PasswordHash)) return Unauthorized("Invalid username or password."); if (!UsernameValidation.IsValid(dto.NewUsername, out var error)) return BadRequest(error); var exists = await context.Users.AnyAsync(u => u.Username == dto.NewUsername && u.Id != user.Id); if (exists) return BadRequest("That username is already taken."); user.Username = dto.NewUsername; context.Users.Update(user); await context.SaveChangesAsync(); return Ok(new { message = "Name changed successfully." }); } catch { return StatusCode(500, "Something went wrong on the server."); } } } No newline at end of file Kollectionized.Api/Controllers/UserCardsController.cs +6 −6 Original line number Diff line number Diff line Loading @@ -47,7 +47,7 @@ public class UserCardController(AppDbContext context) : ControllerBase CurrentOwner = user.Id, Grade = dto.Grade, GradingCompany = dto.GradingCompany ?? string.Empty, Notes = dto.Notes ?? string.Empty, Notes = dto.Notes, CreatedAt = DateTime.UtcNow }; Loading @@ -62,7 +62,7 @@ public class UserCardController(AppDbContext context) : ControllerBase } } [HttpPut("{id}")] [HttpPut("{id:guid}")] public async Task<IActionResult> UpdateCardInstance(string username, Guid id, [FromBody] CardInstanceUpdateDto dto) { try Loading @@ -77,7 +77,7 @@ public class UserCardController(AppDbContext context) : ControllerBase instance.Grade = dto.Grade; instance.GradingCompany = dto.GradingCompany ?? string.Empty; instance.Notes = dto.Notes ?? string.Empty; instance.Notes = dto.Notes; await context.SaveChangesAsync(); return Ok(new { message = "Card instance updated." }); Loading @@ -88,13 +88,13 @@ public class UserCardController(AppDbContext context) : ControllerBase } } [HttpDelete("{id}")] public async Task<IActionResult> DeleteCardInstance(string username, Guid id, [FromBody] PasswordOnlyDto dto) [HttpDelete("{id:guid}")] public async Task<IActionResult> DeleteCardInstance(string username, Guid id, string password) { try { var user = await context.Users.FirstOrDefaultAsync(u => u.Username == username); if (user == null || !BCrypt.Net.BCrypt.Verify(dto.Password, user.PasswordHash)) if (user == null || !BCrypt.Net.BCrypt.Verify(password, user.PasswordHash)) return Unauthorized("Invalid credentials."); var instance = Loading Kollectionized.Api/Controllers/UsersController.cs +3 −3 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ public class UsersController(AppDbContext context) : ControllerBase var users = await context.Users .Where(u => !u.Username.StartsWith("[del-")) .OrderBy(u => u.Username) .Select(u => new UserDto(u.Id, u.Username, u.CreatedAt, u.LastUsername, u.Bio)) .Select(u => new UserDto{Id = u.Id, Username = u.Username, CreatedAt = u.CreatedAt, LastUsername = u.LastUsername, Bio = u.Bio}) .ToListAsync(); return Ok(users); Loading @@ -28,14 +28,14 @@ public class UsersController(AppDbContext context) : ControllerBase } } [HttpGet("{id}")] [HttpGet("{id:guid}")] public async Task<ActionResult<UserDto>> GetUserByUsername(Guid id) { try { var user = await context.Users .Where(u => u.Id == id && !u.Username.StartsWith("[del-")) .Select(u => new UserDto(u.Id, u.Username, u.CreatedAt, u.LastUsername, u.Bio)) .Select(u => new UserDto{Id = u.Id, Username = u.Username, CreatedAt = u.CreatedAt, LastUsername = u.LastUsername, Bio = u.Bio}) .FirstOrDefaultAsync(); return user is null ? NotFound("User not found.") : Ok(user); Loading Kollectionized.Api/Data/AppDbContext.cs +1 −1 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(op public DbSet<PokemonDeck> PokemonDecks => Set<PokemonDeck>(); public DbSet<PokemonCard> PokemonCards => Set<PokemonCard>(); public DbSet<CardInstance> PokemonCardInstances => Set<CardInstance>(); public DbSet<PokemonSet> PokemonSets { get; set; } public DbSet<PokemonSet> PokemonSets => Set<PokemonSet>(); protected override void OnModelCreating(ModelBuilder modelBuilder) { Loading Loading
Kollectionized.Api/Controllers/AccountUpdateController.cs +1 −2 Original line number Diff line number Diff line Loading @@ -2,7 +2,6 @@ using Microsoft.AspNetCore.Mvc; using Microsoft.EntityFrameworkCore; using Kollectionized.Api.Data; using Kollectionized.Api.Dtos; using Kollectionized.Api.Models; namespace Kollectionized.Api.Controllers; Loading @@ -25,7 +24,7 @@ public class AccountUpdateController(AppDbContext context) : ControllerBase user.Username = dto.NewUsername; } user.Bio = dto.Bio ?? user.Bio; user.Bio = dto.Bio; context.Users.Update(user); await context.SaveChangesAsync(); Loading
Kollectionized.Api/Controllers/AuthController.cs +10 −37 Original line number Diff line number Diff line Loading @@ -55,13 +55,14 @@ public class AuthController(AppDbContext context) : ControllerBase if (!BCrypt.Net.BCrypt.Verify(dto.Password, user.PasswordHash)) return Unauthorized("Invalid credentials."); var userDto = new UserDto( Id: user.Id, Username: user.Username, CreatedAt: user.CreatedAt, LastUsername: user.LastUsername ?? string.Empty, Bio: user.Bio ?? string.Empty ); var userDto = new UserDto { Id = user.Id, Username = user.Username, CreatedAt = user.CreatedAt, LastUsername = user.LastUsername ?? string.Empty, Bio = user.Bio ?? string.Empty, }; return Ok(userDto); } Loading @@ -72,12 +73,12 @@ public class AuthController(AppDbContext context) : ControllerBase } [HttpDelete("user/{username}")] public async Task<IActionResult> DeleteAccount(string username, [FromBody] PasswordOnlyDto dto) public async Task<IActionResult> DeleteAccount(string username, string password) { try { var user = await context.Users.FirstOrDefaultAsync(u => u.Username == username); if (user == null || !BCrypt.Net.BCrypt.Verify(dto.Password, user.PasswordHash)) if (user == null || !BCrypt.Net.BCrypt.Verify(password, user.PasswordHash)) return Unauthorized("Invalid password."); if (user.Username.StartsWith("[del-")) Loading @@ -104,32 +105,4 @@ public class AuthController(AppDbContext context) : ControllerBase return StatusCode(500, "Something went wrong on the server"); } } [HttpPut("change-username")] public async Task<IActionResult> ChangeUsername([FromBody] UsernameChangeDto dto) { try { var user = await context.Users.FirstOrDefaultAsync(u => u.Username == dto.CurrentUsername); if (user == null || !BCrypt.Net.BCrypt.Verify(dto.Password, user.PasswordHash)) return Unauthorized("Invalid username or password."); if (!UsernameValidation.IsValid(dto.NewUsername, out var error)) return BadRequest(error); var exists = await context.Users.AnyAsync(u => u.Username == dto.NewUsername && u.Id != user.Id); if (exists) return BadRequest("That username is already taken."); user.Username = dto.NewUsername; context.Users.Update(user); await context.SaveChangesAsync(); return Ok(new { message = "Name changed successfully." }); } catch { return StatusCode(500, "Something went wrong on the server."); } } } No newline at end of file
Kollectionized.Api/Controllers/UserCardsController.cs +6 −6 Original line number Diff line number Diff line Loading @@ -47,7 +47,7 @@ public class UserCardController(AppDbContext context) : ControllerBase CurrentOwner = user.Id, Grade = dto.Grade, GradingCompany = dto.GradingCompany ?? string.Empty, Notes = dto.Notes ?? string.Empty, Notes = dto.Notes, CreatedAt = DateTime.UtcNow }; Loading @@ -62,7 +62,7 @@ public class UserCardController(AppDbContext context) : ControllerBase } } [HttpPut("{id}")] [HttpPut("{id:guid}")] public async Task<IActionResult> UpdateCardInstance(string username, Guid id, [FromBody] CardInstanceUpdateDto dto) { try Loading @@ -77,7 +77,7 @@ public class UserCardController(AppDbContext context) : ControllerBase instance.Grade = dto.Grade; instance.GradingCompany = dto.GradingCompany ?? string.Empty; instance.Notes = dto.Notes ?? string.Empty; instance.Notes = dto.Notes; await context.SaveChangesAsync(); return Ok(new { message = "Card instance updated." }); Loading @@ -88,13 +88,13 @@ public class UserCardController(AppDbContext context) : ControllerBase } } [HttpDelete("{id}")] public async Task<IActionResult> DeleteCardInstance(string username, Guid id, [FromBody] PasswordOnlyDto dto) [HttpDelete("{id:guid}")] public async Task<IActionResult> DeleteCardInstance(string username, Guid id, string password) { try { var user = await context.Users.FirstOrDefaultAsync(u => u.Username == username); if (user == null || !BCrypt.Net.BCrypt.Verify(dto.Password, user.PasswordHash)) if (user == null || !BCrypt.Net.BCrypt.Verify(password, user.PasswordHash)) return Unauthorized("Invalid credentials."); var instance = Loading
Kollectionized.Api/Controllers/UsersController.cs +3 −3 Original line number Diff line number Diff line Loading @@ -17,7 +17,7 @@ public class UsersController(AppDbContext context) : ControllerBase var users = await context.Users .Where(u => !u.Username.StartsWith("[del-")) .OrderBy(u => u.Username) .Select(u => new UserDto(u.Id, u.Username, u.CreatedAt, u.LastUsername, u.Bio)) .Select(u => new UserDto{Id = u.Id, Username = u.Username, CreatedAt = u.CreatedAt, LastUsername = u.LastUsername, Bio = u.Bio}) .ToListAsync(); return Ok(users); Loading @@ -28,14 +28,14 @@ public class UsersController(AppDbContext context) : ControllerBase } } [HttpGet("{id}")] [HttpGet("{id:guid}")] public async Task<ActionResult<UserDto>> GetUserByUsername(Guid id) { try { var user = await context.Users .Where(u => u.Id == id && !u.Username.StartsWith("[del-")) .Select(u => new UserDto(u.Id, u.Username, u.CreatedAt, u.LastUsername, u.Bio)) .Select(u => new UserDto{Id = u.Id, Username = u.Username, CreatedAt = u.CreatedAt, LastUsername = u.LastUsername, Bio = u.Bio}) .FirstOrDefaultAsync(); return user is null ? NotFound("User not found.") : Ok(user); Loading
Kollectionized.Api/Data/AppDbContext.cs +1 −1 Original line number Diff line number Diff line Loading @@ -11,7 +11,7 @@ public class AppDbContext(DbContextOptions<AppDbContext> options) : DbContext(op public DbSet<PokemonDeck> PokemonDecks => Set<PokemonDeck>(); public DbSet<PokemonCard> PokemonCards => Set<PokemonCard>(); public DbSet<CardInstance> PokemonCardInstances => Set<CardInstance>(); public DbSet<PokemonSet> PokemonSets { get; set; } public DbSet<PokemonSet> PokemonSets => Set<PokemonSet>(); protected override void OnModelCreating(ModelBuilder modelBuilder) { Loading