Skip to content

Commit

Permalink
feat: add db
Browse files Browse the repository at this point in the history
  • Loading branch information
fernirteam committed May 12, 2024
1 parent 2de2aae commit 1adef39
Show file tree
Hide file tree
Showing 16 changed files with 977 additions and 35 deletions.
2 changes: 1 addition & 1 deletion server/Booking.Api/Booking.Api.csproj
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk.Web">
<Project Sdk="Microsoft.NET.Sdk.Web">

<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
Expand Down
2 changes: 1 addition & 1 deletion server/Booking.Api/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
// Add Layers
builder.Services
.AddApplication()
.AddInfrastructure(builder.Configuration);
.AddInfrastructure(builder.Configuration, builder.Environment);

builder.Services
.AddHttpContextAccessor()
Expand Down
4 changes: 3 additions & 1 deletion server/Booking.Api/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,9 @@
}
},
"AllowedHosts": "*",
"ConnectionStrings": {},
"ConnectionStrings": {
"SQL_SERVER_DB": "Data Source=(LocalDB)\\MSSQLLocalDB;AttachDbFilename=C:\\Users\\kiril\\Projects\\www Projects\\Booking-app\\server\\Booking.Infrastructure\\BookingDB.mdf;Integrated Security=True"
},
"JwtOptions": {
"Issuer": "",
"Audience": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public async Task<AdvertDto> Handle(Create.Request request, CancellationToken ca

var advert = Advert.Create(
request.Name, request.Description, user,
(decimal)request.PricePerNight, request.NumberOfBathrooms, request.NumberOfSingleBeds, request.NumberOfDoubleBeds, request.MaxPeople,
request.PricePerNight, request.NumberOfBathrooms, request.NumberOfSingleBeds, request.NumberOfDoubleBeds, request.MaxPeople,
request.Wifi, request.PetsAllowed, request.TV, request.Refrigerator, request.Kitchen,
request.Washer, request.Heating, request.Dryer,
category
Expand Down Expand Up @@ -93,7 +93,7 @@ public async Task<AdvertDto> Handle(Update.Request request, CancellationToken ca

advert.Name = request.Name;
advert.Description = request.Description;
advert.PricePerNight = (decimal)request.PricePerNight;
advert.PricePerNight = request.PricePerNight;
advert.NumberOfBathrooms = request.NumberOfBathrooms;
advert.NumberOfSingleBeds = request.NumberOfSingleBeds;
advert.NumberOfDoubleBeds = request.NumberOfDoubleBeds;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public record Response(
string Name,
string Description,
UserDto? Owner,
decimal PricePerNight,
float PricePerNight,
int NumberOfBathrooms,
int NumberOfSingleBeds,
int NumberOfDoubleBeds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,15 +33,6 @@ IHttpContextAccessor httpContextAccessor
if (userId != null)
user = unitOfWork.Users.GetById(userId);

var author = new UserDto
{
Id = Guid.NewGuid().ToString(),
Avatar = "",
Name = "Cyril",
Initials = "Cy",
Email = "cyril@morozov.com",
PhoneNumber = "+380000000000"
};
var reviews = unitOfWork.Reviews.GetByAdvertId(advert.Id);
return new(
advert.Id,
Expand Down
6 changes: 4 additions & 2 deletions server/Booking.Core/Entities/Advert.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ public class Advert : EntityBase
public string Description { get; set; }
public string OwnerId { get; set; }
public User? Owner { get; set; }
public decimal PricePerNight { get; set; }
public float PricePerNight { get; set; }
public int NumberOfBathrooms { get; set; }
public int NumberOfSingleBeds { get; set; }
public int NumberOfDoubleBeds { get; set; }
Expand All @@ -25,9 +25,11 @@ public class Advert : EntityBase
public Category Category { get; set; }
public List<string> Photos { get; set; } = new();
public List<Reservation> Reservations { get; set; } = new();
public List<User> LikedByUsers { get; set; } = new();
public List<Review> Reviews { get; set; } = new();

public static Advert Create(
string name, string description, User owner, decimal pricePerNight,
string name, string description, User owner, float pricePerNight,
int numberOfBathrooms, int numberOfSingleBeds, int numberOfDoubleBeds, int maxPeople,
bool wifi, bool petsAllowed, bool tv, bool refrigerator, bool kitchen, bool washer, bool heating, bool dryer,
Category category
Expand Down
1 change: 1 addition & 0 deletions server/Booking.Core/Entities/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ public class User : EntityBase
public string PhoneNumber { get; set; }
public string? Token { get; set; }
public DateTime ExpiryIn { get; set; }
public List<Reservation> Reservations { get; set; } = new();
public List<Advert> Adverts { get; set; } = new();
public List<Advert> Likes { get; set; } = new();
public List<Review> Reviews { get; set; } = new();
Expand Down
9 changes: 9 additions & 0 deletions server/Booking.Infrastructure/Booking.Infrastructure.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,16 @@
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Authentication.JwtBearer" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Design" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<PackageReference Include="Microsoft.EntityFrameworkCore.InMemory" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="8.0.3" />
<PackageReference Include="Microsoft.EntityFrameworkCore.Tools" Version="8.0.3">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
</PackageReference>
<FrameworkReference Include="Microsoft.AspNetCore.App" />
</ItemGroup>

Expand Down
14 changes: 8 additions & 6 deletions server/Booking.Infrastructure/DependencyInjection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
using Booking.Core.Common;
using Booking.Core.Repositories;
using Booking.Application.Services;
using Booking.Infrastructure.Options;
using Booking.Infrastructure.Persistence;
using Booking.Infrastructure.Persistence.Repositories;
using Booking.Infrastructure.Services;
Expand All @@ -11,16 +10,18 @@
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.IdentityModel.Tokens;
using Microsoft.AspNetCore.Hosting;
using Booking.Infrastructure.Options;

namespace Booking.Infrastructure;

public static class DependencyInjection
{
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration)
public static IServiceCollection AddInfrastructure(this IServiceCollection services, IConfiguration configuration, IWebHostEnvironment environment)
{
services
.AddJwtAuth(configuration)
.AddDatabase(configuration)
.AddDatabase(configuration, environment)

.AddTransient<IUserRepository, UserRepository>()
.AddTransient<IAdvertRepository, AdvertRepository>()
Expand Down Expand Up @@ -57,9 +58,10 @@ private static IServiceCollection AddJwtAuth(this IServiceCollection services, I
return services;
}

private static IServiceCollection AddDatabase(this IServiceCollection services, IConfiguration configuration)
private static IServiceCollection AddDatabase(this IServiceCollection services, IConfiguration configuration, IWebHostEnvironment environment)
{
services.AddDbContext<BookingDbContext>(opt => opt.UseInMemoryDatabase("Booking.DB"));
//services.AddDbContext<BookingDbContext>(opt => opt.UseInMemoryDatabase("Booking.DB"));
services.AddDbContext<BookingDbContext>(opt => opt.UseSqlServer(configuration.GetConnectionString("SQL_SERVER_DB")));
return services;
}
}
}
Loading

0 comments on commit 1adef39

Please sign in to comment.