Skip to content
This repository has been archived by the owner on Jun 23, 2024. It is now read-only.

Commit

Permalink
wtf
Browse files Browse the repository at this point in the history
Signed-off-by: AlexNg <contact@ngjx.org>
  • Loading branch information
caffeine-addictt committed Jun 21, 2024
1 parent 0b154c9 commit b06d2aa
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 15 deletions.
6 changes: 5 additions & 1 deletion WebApplication1/WebApplication1/Controllers/Saloon.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ public class SaloonCreateRequest

[HttpPost("/api/saloon")]
[ProducesResponseType(StatusCodes.Status201Created)]
[ProducesResponseType(StatusCodes.Status401Unauthorized)]
[ProducesResponseType(StatusCodes.Status400BadRequest)]
public IActionResult Create(SaloonCreateRequest req)
{
Expand All @@ -32,7 +33,10 @@ public IActionResult Create(SaloonCreateRequest req)
.FirstOrDefault(u => u.UserId == req.UserId);

if (usr == null)
return Unauthorized(new { Status = 401, Message = $"Unauthorized" });
return Unauthorized(new { Status = 401, Message = "Unauthorized" });

if (ctx.Saloons.Any(s => s.Name == req.Name))
return BadRequest(new { Status = 400, Message = "A saloon with this name already exists!" });

Saloon newSaloon = new Saloon()
{
Expand Down
30 changes: 19 additions & 11 deletions WebApplication1/WebApplication1/Controllers/Workshop.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,19 +13,27 @@ public class WorkshopController : ControllerBase
{
[HttpGet("/api/workshop")]
[ProducesResponseType(StatusCodes.Status200OK)]
public IActionResult GetList()
public IActionResult GetList([FromQuery] int? status, [FromQuery] int? userid)
{
List<object?> marshalled = new List<object?>();
using (Ws1Context ws1Context = new Ws1Context())
using (Ws1Context ctx = new Ws1Context())
{
foreach (Workshop w in ws1Context.Workshops.Include(w => w.Category))
marshalled.Add(Marshall.Json(w, 1));
IQueryable<Workshop> query = ctx.Workshops
.Include(w => w.Category)
.Include(w => w.Saloon);

if (status != null)
query = query.Where(w => w.Status == status);
if (userid != null)
query = query.Where(w => w.UserId == userid);

return Ok(new
{
Status = 200,
Message = "Successfully fetched workshops!",
Data = query
.Select(w => Marshall.Json(w, 1))
.ToList(),
});
}
return Ok(new
{
Status = 200,
Message = "Successfully fetched workshops!",
Data = marshalled,
});
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ public class WorkshopRequestCreateRequest
/// </summary>
public int Timeslot { get; set; }
public string Category { get; set; } = null!;
public int SaloonId { get; set; }
public string Saloon { get; set; } = null!;
}

[HttpPost("/api/workshop-request")]
Expand Down Expand Up @@ -61,10 +61,10 @@ public IActionResult Create(WorkshopRequestCreateRequest req)
// Check for valid saloonID
Saloon? saloon = ctx.Saloons
.Include(s => s.Workshops)
.FirstOrDefault(s => s.SaloonId == req.SaloonId);
.FirstOrDefault(s => s.Name == req.Saloon);

if (saloon == null)
return BadRequest(new { Status = 400, Message = $"SaloonID {req.SaloonId} does not exist" });
return BadRequest(new { Status = 400, Message = $"Saloon {req.Saloon} does not exist" });
if (saloon.Workshops.Any(w =>
w.Status == 1
&& Time.Overlaps(w.StartDate, w.EndDate, req.StartDate, req.EndDate)
Expand All @@ -86,6 +86,8 @@ public IActionResult Create(WorkshopRequestCreateRequest req)
WorkshopId = ctx.Workshops.Count(),
Title = req.Title,
Timeslot = req.Timeslot,
StartDate = req.StartDate,
EndDate = req.EndDate,
Category = cat
};

Expand Down
2 changes: 2 additions & 0 deletions WebApplication1/WebApplication1/Utils/Marshall.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ public static class Marshall
StartDate = w.StartDate,
Timeslot = Timeslot.AsString(w.Timeslot),
Title = w.Title,
Status = w.Status == 0 ? "Pending" : (w.Status == 1 ? "Accepted" : "Rejected"),
RequestDate = w.RequestDate,
Category = Json(w.Category, depth - 1),
Saloon = Json(w.Saloon, depth - 1),
};
Expand Down

0 comments on commit b06d2aa

Please sign in to comment.