mirror of
https://github.com/aaronpo97/the-biergarten-app.git
synced 2026-02-16 10:42:08 +00:00
Restructure data access layer/data layer
This commit is contained in:
@@ -1,75 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace WebAPI.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/beers")]
|
||||
public class BeersController : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public IActionResult GetBeers([FromQuery] int page_num, [FromQuery] int page_size)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet("search")]
|
||||
public IActionResult SearchBeers([FromQuery] string search)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet("styles")]
|
||||
public IActionResult GetBeerStyles([FromQuery] int page_num, [FromQuery] int page_size)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost("styles/create")]
|
||||
public IActionResult CreateBeerStyle([FromBody] BeerStyleCreateRequest request)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPut("{postId}")]
|
||||
public IActionResult EditBeer(string postId, [FromBody] BeerEditRequest request)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpDelete("{postId}")]
|
||||
public IActionResult DeleteBeer(string postId)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet("{postId}/recommendations")]
|
||||
public IActionResult GetBeerRecommendations([FromQuery] int page_num, [FromQuery] int page_size, string postId)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost("{postId}/comments")]
|
||||
public IActionResult AddBeerComment(string postId, [FromBody] BeerCommentRequest request)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet("{postId}/comments")]
|
||||
public IActionResult GetBeerComments([FromQuery] int page_num, [FromQuery] int page_size, string postId)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPut("{postId}/comments/{commentId}")]
|
||||
public IActionResult EditBeerComment(string postId, string commentId, [FromBody] BeerCommentRequest request)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpDelete("{postId}/comments/{commentId}")]
|
||||
public IActionResult DeleteBeerComment(string postId, string commentId)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,57 +0,0 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace WebAPI.Controllers
|
||||
{
|
||||
[ApiController]
|
||||
[Route("api/breweries")]
|
||||
public class BreweriesController : ControllerBase
|
||||
{
|
||||
[HttpGet]
|
||||
public IActionResult GetBreweries([FromQuery] int page_num, [FromQuery] int page_size)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet("map")]
|
||||
public IActionResult GetBreweriesMap([FromQuery] int page_num, [FromQuery] int page_size)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPut("{postId}")]
|
||||
public IActionResult EditBrewery(string postId, [FromBody] BreweryEditRequest request)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpDelete("{postId}")]
|
||||
public IActionResult DeleteBrewery(string postId)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPost("{postId}/comments")]
|
||||
public IActionResult AddBreweryComment(string postId, [FromBody] BreweryCommentRequest request)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpGet("{postId}/comments")]
|
||||
public IActionResult GetBreweryComments([FromQuery] int page_num, [FromQuery] int page_size, string postId)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpPut("{postId}/comments/{commentId}")]
|
||||
public IActionResult EditBreweryComment(string postId, string commentId, [FromBody] BreweryCommentRequest request)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
[HttpDelete("{postId}/comments/{commentId}")]
|
||||
public IActionResult DeleteBreweryComment(string postId, string commentId)
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,5 +1,6 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using DataAccessLayer;
|
||||
using DataAccessLayer.Entities;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
|
||||
namespace WebAPI.Controllers
|
||||
{
|
||||
@@ -7,7 +8,7 @@ namespace WebAPI.Controllers
|
||||
[Route("api/users")]
|
||||
public class UsersController : ControllerBase
|
||||
{
|
||||
private readonly UserAccountRepository _userAccountRepository;
|
||||
private readonly IUserAccountRepository _userAccountRepository;
|
||||
|
||||
public UsersController()
|
||||
{
|
||||
@@ -15,6 +16,7 @@ namespace WebAPI.Controllers
|
||||
}
|
||||
|
||||
// all users
|
||||
[HttpGet]
|
||||
[HttpGet("users")]
|
||||
public IActionResult GetAllUsers()
|
||||
{
|
||||
@@ -22,5 +24,61 @@ namespace WebAPI.Controllers
|
||||
return Ok(users);
|
||||
}
|
||||
|
||||
[HttpGet("{id:guid}")]
|
||||
public IActionResult GetUserById(Guid id)
|
||||
{
|
||||
var user = _userAccountRepository.GetById(id);
|
||||
return user is null ? NotFound() : Ok(user);
|
||||
}
|
||||
|
||||
[HttpGet("by-username/{username}")]
|
||||
public IActionResult GetUserByUsername(string username)
|
||||
{
|
||||
var user = _userAccountRepository.GetByUsername(username);
|
||||
return user is null ? NotFound() : Ok(user);
|
||||
}
|
||||
|
||||
[HttpGet("by-email/{email}")]
|
||||
public IActionResult GetUserByEmail(string email)
|
||||
{
|
||||
var user = _userAccountRepository.GetByEmail(email);
|
||||
return user is null ? NotFound() : Ok(user);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult CreateUser([FromBody] UserAccount userAccount)
|
||||
{
|
||||
if (userAccount.UserAccountID == Guid.Empty)
|
||||
{
|
||||
userAccount.UserAccountID = Guid.NewGuid();
|
||||
}
|
||||
|
||||
_userAccountRepository.Add(userAccount);
|
||||
return CreatedAtAction(
|
||||
nameof(GetUserById),
|
||||
new { id = userAccount.UserAccountID },
|
||||
userAccount
|
||||
);
|
||||
}
|
||||
|
||||
[HttpPut("{id:guid}")]
|
||||
public IActionResult UpdateUser(Guid id, [FromBody] UserAccount userAccount)
|
||||
{
|
||||
if (userAccount.UserAccountID != Guid.Empty && userAccount.UserAccountID != id)
|
||||
{
|
||||
return BadRequest("UserAccountID does not match route id.");
|
||||
}
|
||||
|
||||
userAccount.UserAccountID = id;
|
||||
_userAccountRepository.Update(userAccount);
|
||||
return NoContent();
|
||||
}
|
||||
|
||||
[HttpDelete("{id:guid}")]
|
||||
public IActionResult DeleteUser(Guid id)
|
||||
{
|
||||
_userAccountRepository.Delete(id);
|
||||
return NoContent();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,17 +30,22 @@ catch
|
||||
|
||||
var builder = WebApplication.CreateBuilder(args);
|
||||
|
||||
// Add services to the container.
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddOpenApi();
|
||||
// Add services to the container.
|
||||
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
|
||||
builder.Services.AddControllers();
|
||||
builder.Services.AddEndpointsApiExplorer();
|
||||
builder.Services.AddSwaggerGen();
|
||||
builder.Services.AddOpenApi();
|
||||
|
||||
var app = builder.Build();
|
||||
|
||||
// Configure the HTTP request pipeline.
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.MapOpenApi();
|
||||
}
|
||||
if (app.Environment.IsDevelopment())
|
||||
{
|
||||
app.UseSwagger();
|
||||
app.UseSwaggerUI();
|
||||
app.MapOpenApi();
|
||||
}
|
||||
|
||||
app.UseHttpsRedirection();
|
||||
|
||||
@@ -58,24 +63,6 @@ var summaries = new[]
|
||||
"Scorching",
|
||||
};
|
||||
|
||||
app.MapGet(
|
||||
"/weatherforecast",
|
||||
() =>
|
||||
{
|
||||
var forecast = Enumerable
|
||||
.Range(1, 5)
|
||||
.Select(index => new WeatherForecast(
|
||||
DateOnly.FromDateTime(DateTime.Now.AddDays(index)),
|
||||
Random.Shared.Next(-20, 55),
|
||||
summaries[Random.Shared.Next(summaries.Length)]
|
||||
))
|
||||
.ToArray();
|
||||
return forecast;
|
||||
}
|
||||
)
|
||||
.WithName("GetWeatherForecast");
|
||||
|
||||
// Register controllers
|
||||
app.MapControllers();
|
||||
app.Run();
|
||||
|
||||
|
||||
@@ -5,9 +5,10 @@
|
||||
<ImplicitUsings>enable</ImplicitUsings>
|
||||
</PropertyGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.11" />
|
||||
</ItemGroup>
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="9.0.11" />
|
||||
<PackageReference Include="Swashbuckle.AspNetCore" Version="6.6.2" />
|
||||
</ItemGroup>
|
||||
|
||||
<ItemGroup>
|
||||
<ProjectReference Include="../DataAccessLayer/DataAccessLayer.csproj" />
|
||||
|
||||
@@ -1,6 +1,64 @@
|
||||
@WebAPI_HostAddress = http://localhost:5069
|
||||
|
||||
GET {{WebAPI_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
GET {{WebAPI_HostAddress}}/weatherforecast/
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
|
||||
GET {{WebAPI_HostAddress}}/api/users
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
|
||||
GET {{WebAPI_HostAddress}}/api/users/{{userId}}
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
|
||||
GET {{WebAPI_HostAddress}}/api/users/by-username/{{username}}
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
|
||||
GET {{WebAPI_HostAddress}}/api/users/by-email/{{email}}
|
||||
Accept: application/json
|
||||
|
||||
###
|
||||
|
||||
POST {{WebAPI_HostAddress}}/api/users
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
|
||||
{
|
||||
"userAccountID": "00000000-0000-0000-0000-000000000000",
|
||||
"username": "testuser",
|
||||
"firstName": "Test",
|
||||
"lastName": "User",
|
||||
"email": "testuser@example.com",
|
||||
"createdAt": "2025-01-01T00:00:00Z",
|
||||
"updatedAt": null,
|
||||
"dateOfBirth": "1990-01-01T00:00:00Z",
|
||||
"timer": null
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
PUT {{WebAPI_HostAddress}}/api/users/{{userId}}
|
||||
Content-Type: application/json
|
||||
Accept: application/json
|
||||
|
||||
{
|
||||
"userAccountID": "{{userId}}",
|
||||
"username": "testuser",
|
||||
"firstName": "Updated",
|
||||
"lastName": "User",
|
||||
"email": "testuser@example.com",
|
||||
"createdAt": "2025-01-01T00:00:00Z",
|
||||
"updatedAt": "2025-02-01T00:00:00Z",
|
||||
"dateOfBirth": "1990-01-01T00:00:00Z",
|
||||
"timer": null
|
||||
}
|
||||
|
||||
###
|
||||
|
||||
DELETE {{WebAPI_HostAddress}}/api/users/{{userId}}
|
||||
|
||||
Reference in New Issue
Block a user