Skip to content
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
11 changes: 7 additions & 4 deletions .config/dotnet-tools.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,13 @@
"tools": {
"csharpier": {
"version": "1.1.2",
"commands": [
"csharpier"
],
"commands": ["csharpier"],
"rollForward": false
},
"dotnet-ef": {
"version": "9.0.10",
"commands": ["dotnet-ef"],
"rollForward": false
}
}
}
}
13 changes: 0 additions & 13 deletions Project.App/Project.Api/.config/dotnet-tools.json

This file was deleted.

2 changes: 1 addition & 1 deletion Project.App/Project.Api/DTOs/ExampleDTO.cs
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
namespace Project.DTOs;
public class ExampleDTO { }

public class ExampleDTO { }
1 change: 1 addition & 0 deletions Project.App/Project.Api/Data/MappingProfile.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using Project.DTOs;

namespace Project.Api.Data;

public class MappingProfile : Profile
{
public MappingProfile() { }
Expand Down
3 changes: 2 additions & 1 deletion Project.App/Project.Api/Enums/roleEnum.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
namespace Project.Api.Enums;

public enum Role
{
Admin,
Moderator,
Player,
}
}
3 changes: 2 additions & 1 deletion Project.App/Project.Api/Enums/statusEnum.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
namespace Project.Api.Enums;

public enum Status
{
Active,
Inactive,
Away,
Left,
}
}
2 changes: 1 addition & 1 deletion Project.App/Project.Api/Models/Room.cs
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@

using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;

namespace Project.Api.Models;

public class Room
{
[Key]
Expand Down
45 changes: 34 additions & 11 deletions Project.App/Project.Api/Repositories/HandRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ namespace Project.Api.Repositories;
public class HandRepository : IHandRepository
{
private readonly AppDbContext _context;

// Constructor
public HandRepository(AppDbContext context)
{
_context = context;
}

// Implement the methods
// Get a hand by its ID
public async Task<Hand?> GetHandAsyncById(Guid handId)
Expand All @@ -33,6 +35,7 @@ public HandRepository(AppDbContext context)
// return hand or throw exception if not found
return hand ?? throw new Exception("Hand not found");
}

public async Task<List<Hand>> GetHandsByRoomIdAsync(Guid roomId)
{
// Validate roomId
Expand All @@ -41,13 +44,14 @@ public async Task<List<Hand>> GetHandsByRoomIdAsync(Guid roomId)
throw new ArgumentException("Invalid roomId");
}
// Retrieve the hands from the database
List<Hand> hands = await _context.Hands
.Include(h => h.RoomPlayer)
List<Hand> hands = await _context
.Hands.Include(h => h.RoomPlayer)
.Where(h => h.RoomPlayer != null && h.RoomPlayer.RoomId == roomId)
.ToListAsync();
// return hands or throw exception if not found
return (hands == null || hands.Count == 0) ? throw new Exception("No hands found") : hands;
}

public async Task<List<Hand>> GetHandsByUserIdAsync(Guid roomId, Guid userId)
{
// Validate roomId and userId
Expand All @@ -56,13 +60,18 @@ public async Task<List<Hand>> GetHandsByUserIdAsync(Guid roomId, Guid userId)
throw new ArgumentException(userId == Guid.Empty ? "Invalid userId" : "Invalid roomId");
}
// Retrieve the hands from the database
List<Hand> hands = await _context.Hands
.Include(h => h.RoomPlayer)
.Where(h => h.RoomPlayer != null && h.RoomPlayer.RoomId == roomId && h.RoomPlayer.UserId == userId)
List<Hand> hands = await _context
.Hands.Include(h => h.RoomPlayer)
.Where(h =>
h.RoomPlayer != null
&& h.RoomPlayer.RoomId == roomId
&& h.RoomPlayer.UserId == userId
)
.ToListAsync();
// return hands or throw exception if not found
return (hands == null || hands.Count == 0) ? throw new Exception("No hands found") : hands;
}

// Create a new hand
public async Task<Hand> CreateHandAsync(Hand hand)
{
Expand All @@ -75,14 +84,17 @@ public async Task<Hand> CreateHandAsync(Hand hand)
// Asynchronously add the hand to the context and save changes
await _context.Hands.AddAsync(hand);
await SaveChangesAsync();
// return hand
// return hand
return hand;
}

// Update an existing hand
public async Task<Hand> UpdateHandAsync(Guid handId, Hand hand)
{
//check if hand does not exist add hand if it does
var existingHand = await _context.Hands.FindAsync(handId) ?? throw new KeyNotFoundException("Hand not found");
var existingHand =
await _context.Hands.FindAsync(handId)
?? throw new KeyNotFoundException("Hand not found");

// Update properties
existingHand.Order = hand.Order;
Expand All @@ -96,11 +108,19 @@ public async Task<Hand> UpdateHandAsync(Guid handId, Hand hand)
// return newly updated hand
return existingHand;
}

// update specific properties of an existing hand
public async Task<Hand> PatchHandAsync(Guid handId, int? Order = null, string? CardsJson = null, int? Bet = null)
public async Task<Hand> PatchHandAsync(
Guid handId,
int? Order = null,
string? CardsJson = null,
int? Bet = null
)
{
// Check if hand exists and retrieve it
var existingHand = await _context.Hands.FindAsync(handId) ?? throw new KeyNotFoundException("Hand not found");
var existingHand =
await _context.Hands.FindAsync(handId)
?? throw new KeyNotFoundException("Hand not found");

// Update properties if provided
existingHand.Order = Order ?? existingHand.Order;
Expand All @@ -114,11 +134,14 @@ public async Task<Hand> PatchHandAsync(Guid handId, int? Order = null, string? C
// Return the updated hand
return existingHand;
}

// Delete an existing hand
public async Task<Hand> DeleteHandAsync(Guid handId)
{
// Check if hand exists and retrieve it
var existingHand = await _context.Hands.FindAsync(handId) ?? throw new KeyNotFoundException("Hand not found");
var existingHand =
await _context.Hands.FindAsync(handId)
?? throw new KeyNotFoundException("Hand not found");

// Remove the hand from the context and save changes
_context.Hands.Remove(existingHand);
Expand All @@ -127,11 +150,11 @@ public async Task<Hand> DeleteHandAsync(Guid handId)
// Return the deleted hand
return existingHand;
}

// Save changes to the database
public async Task SaveChangesAsync()
{
// Save changes to the database
await _context.SaveChangesAsync();
}

}
16 changes: 14 additions & 2 deletions Project.App/Project.Api/Repositories/Interface/IHandRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,37 @@
using Project.Api.Repositories;

namespace Project.Api.Repositories;

public interface IHandRepository
{
// Define Fields
// Get a hand by its ID
Task<Hand?> GetHandAsyncById(Guid handId);

// Get all hands in a room

Task<List<Hand>> GetHandsByRoomIdAsync(Guid roomId);

// Get all hands by a user in a room
Task<List<Hand>> GetHandsByUserIdAsync(Guid roomId, Guid userId);

// Create a new hand
Task<Hand> CreateHandAsync(Hand hand);

// Update an existing hand
Task<Hand> UpdateHandAsync(Guid handId, Hand hand);

// Partially update an existing hand
Task<Hand> PatchHandAsync(Guid handId, int? Order = null, string? CardsJson = null, int? Bet = null);
Task<Hand> PatchHandAsync(
Guid handId,
int? Order = null,
string? CardsJson = null,
int? Bet = null
);

// Delete a hand
Task<Hand> DeleteHandAsync(Guid handId);

// Save changes to the database
Task SaveChangesAsync();
}

Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Project.Api.Models;
using Project.Api.Enums;
using Project.Api.Models;

namespace Project.Api.Repositories.Interface
{
Expand All @@ -25,4 +25,4 @@ public interface IRoomPlayerRepository
Task UpdatePlayerStatusAsync(Guid id, Status status);
Task UpdatePlayerBalanceAsync(Guid id, long balance);
}
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using Project.Api.Models;

namespace Project.Api.Repositories.Interface;

public interface IRoomRepository
{
Task<Room?> GetByIdAsync(Guid id);
Expand All @@ -13,4 +14,3 @@ public interface IRoomRepository
Task<bool> DeleteAsync(Guid id);
Task<bool> ExistsAsync(Guid id);
}

Loading