Skip to content

Commit

Permalink
pre-publishing with errors
Browse files Browse the repository at this point in the history
  • Loading branch information
franconeilglovasa committed Jul 30, 2020
1 parent 0b4a804 commit 8c3bbee
Show file tree
Hide file tree
Showing 30 changed files with 1,153 additions and 86 deletions.
4 changes: 2 additions & 2 deletions DatingApp-SPA/angular.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
"build": {
"builder": "@angular-devkit/build-angular:browser",
"options": {
"outputPath": "dist/DatingApp-SPA",
"outputPath": "../DatingApp.API/wwwroot",
"index": "src/index.html",
"main": "src/main.ts",
"polyfills": "src/polyfills.ts",
Expand Down Expand Up @@ -46,7 +46,7 @@
"aot": true,
"extractLicenses": true,
"vendorChunk": false,
"buildOptimizer": true,
"buildOptimizer": false,
"budgets": [
{
"type": "initial",
Expand Down
2 changes: 1 addition & 1 deletion DatingApp-SPA/src/app/_models/user.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ export interface User {
age: number;
gender: string;
created: Date;
lastActive: Date;
lastActive: any;
photoUrl: string;
city: string;
country: string;
Expand Down
Empty file.
3 changes: 0 additions & 3 deletions DatingApp-SPA/src/app/value/value.component.html

This file was deleted.

28 changes: 0 additions & 28 deletions DatingApp-SPA/src/app/value/value.component.spec.ts

This file was deleted.

25 changes: 0 additions & 25 deletions DatingApp-SPA/src/app/value/value.component.ts

This file was deleted.

3 changes: 2 additions & 1 deletion DatingApp-SPA/src/environments/environment.prod.ts
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
export const environment = {
production: true
production: true,
apiUrl: 'api/'
};
3 changes: 2 additions & 1 deletion DatingApp.API/.gitignore
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
.vscode
bin
obj
*.db
*.db
wwwroot
Binary file modified DatingApp.API/.vs/DatingApp.API/DesignTimeBuild/.dtbcache.v2
Binary file not shown.
Binary file modified DatingApp.API/.vs/DatingApp.API/v16/.suo
Binary file not shown.
15 changes: 15 additions & 0 deletions DatingApp.API/Controllers/Fallback.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
using System.IO;
using Microsoft.AspNetCore.Mvc;

namespace DatingApp.API.Controllers
{
public class Fallback : Controller
{
public IActionResult Index()
{
return PhysicalFile(Path.Combine(Directory.GetCurrentDirectory(), "wwwroot",
"index.html"), "text/HTML");
}

}
}
16 changes: 5 additions & 11 deletions DatingApp.API/Data/DatingRepository.cs
Original file line number Diff line number Diff line change
Expand Up @@ -45,13 +45,13 @@ public async Task<Photo> GetPhoto(int id)

public async Task<User> GetUser(int id)
{
var user = await _context.Users.Include(p => p.Photos).FirstOrDefaultAsync(u => u.Id == id);
var user = await _context.Users.FirstOrDefaultAsync(u => u.Id == id);
return user;
}

public async Task<PagedList<User>> GetUsers(UserParams userParams)
{
var users = _context.Users.Include(p => p.Photos)
var users = _context.Users
.OrderBy(u => u.LastActive).AsQueryable();
users = users.Where(u => u.Id != userParams.UserId);
users = users.Where(u => u.Gender == userParams.Gender);
Expand Down Expand Up @@ -96,9 +96,7 @@ public async Task<PagedList<User>> GetUsers(UserParams userParams)
private async Task<IEnumerable<int>> GetUserLikes(int id, bool likers)
{
var user = await _context.Users
.Include(x => x.Likers)
.Include(x => x.Likees)
.FirstOrDefaultAsync(u => u.Id == id);
.FirstOrDefaultAsync(u => u.Id == id);

if (likers)
{
Expand All @@ -123,9 +121,7 @@ public async Task<Message> GetMessage(int id)
public async Task<PagedList<Message>> GetMessagesForUser(MessageParams messageParams)
{
var messages = _context.Messages
.Include(u => u.Sender).ThenInclude(p => p.Photos)
.Include(u => u.Recipient).ThenInclude(p => p.Photos)
.AsQueryable(); //and since we added where, need to add queryable
.AsQueryable(); //and since we added where, need to add queryable

switch (messageParams.MessageContainer)
{
Expand Down Expand Up @@ -161,9 +157,7 @@ public async Task<IEnumerable<Message>> GetMessageThread(int userId, int recipie
// return messages;

var messages = await _context.Messages
.Include(u => u.Sender).ThenInclude(p => p.Photos)
.Include(u => u.Recipient).ThenInclude(p => p.Photos)
.Where(m => m.RecipientId == userId && m.RecipientDeleted == false
.Where(m => m.RecipientId == userId && m.RecipientDeleted == false
&& m.SenderId == recipientId
|| m.RecipientId == recipientId && m.SenderId == userId
&& m.SenderDeleted == false)
Expand Down
3 changes: 3 additions & 0 deletions DatingApp.API/DatingApp.API.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,8 @@
<PackageReference Include="Microsoft.AspNetCore.Mvc.NewtonsoftJson" Version="3.1.0"/>
<PackageReference Include="AutoMapper.Extensions.Microsoft.DependencyInjection" Version="7.0.0"/>
<PackageReference Include="CloudinaryDotNet" Version="1.8.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.SqlServer" Version="3.1.0"/>
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="3.1.0"/>
<PackageReference Include="Microsoft.EntityFrameworkCore.Proxies" Version="3.1.0"/>
</ItemGroup>
</Project>
15 changes: 14 additions & 1 deletion DatingApp.API/Migrations/20200715085128_InitialCreate.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace DatingApp.API.Migrations
Expand All @@ -11,7 +12,11 @@ protected override void Up(MigrationBuilder migrationBuilder)
name: "Users",
columns: table => new
{
Id = table.Column<int>(nullable: false)
Id = table.Column<int>(nullable: false) // add these 2 for production on every migration
.Annotation("SqlServer:ValueGenerationStrategy",
SqlServerValueGenerationStrategy.IdentityColumn)
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn)
.Annotation("Sqlite:Autoincrement", true),
Username = table.Column<string>(nullable: true),
PasswordHash = table.Column<byte[]>(nullable: true),
Expand All @@ -37,6 +42,10 @@ protected override void Up(MigrationBuilder migrationBuilder)
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy",
SqlServerValueGenerationStrategy.IdentityColumn)
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn)
.Annotation("Sqlite:Autoincrement", true),
Name = table.Column<string>(nullable: true)
},
Expand All @@ -50,6 +59,10 @@ protected override void Up(MigrationBuilder migrationBuilder)
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy",
SqlServerValueGenerationStrategy.IdentityColumn)
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn)
.Annotation("Sqlite:Autoincrement", true),
Url = table.Column<string>(nullable: true),
Description = table.Column<string>(nullable: true),
Expand Down
5 changes: 5 additions & 0 deletions DatingApp.API/Migrations/20200728032903_MessageEntityAdded.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System;
using Microsoft.EntityFrameworkCore.Metadata;
using Microsoft.EntityFrameworkCore.Migrations;

namespace DatingApp.API.Migrations
Expand All @@ -12,6 +13,10 @@ protected override void Up(MigrationBuilder migrationBuilder)
columns: table => new
{
Id = table.Column<int>(nullable: false)
.Annotation("SqlServer:ValueGenerationStrategy",
SqlServerValueGenerationStrategy.IdentityColumn)
.Annotation("MySql:ValueGenerationStrategy",
MySqlValueGenerationStrategy.IdentityColumn)
.Annotation("Sqlite:Autoincrement", true),
SenderId = table.Column<int>(nullable: false),
RecipientId = table.Column<int>(nullable: false),
Expand Down
4 changes: 2 additions & 2 deletions DatingApp.API/Models/Like.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ public class Like
{
public int LikerId { get; set; }
public int LikeeId { get; set; }
public User Liker { get; set; }
public User Likee { get; set; }
public virtual User Liker { get; set; }
public virtual User Likee { get; set; }
}
}
4 changes: 2 additions & 2 deletions DatingApp.API/Models/Message.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ public class Message
{
public int Id { get; set; }
public int SenderId { get; set; }
public User Sender { get; set; }
public virtual User Sender { get; set; }
public int RecipientId { get; set; }
public User Recipient { get; set; }
public virtual User Recipient { get; set; }
public string Content { get; set; }
public bool IsRead { get; set; }
public DateTime? DateRead { get; set; }
Expand Down
10 changes: 5 additions & 5 deletions DatingApp.API/Models/User.cs
Original file line number Diff line number Diff line change
Expand Up @@ -19,11 +19,11 @@ public class User
public string Interests { get; set; }
public string City { get; set; }
public string Country { get; set; }
public ICollection<Photo> Photos { get; set; }
public ICollection<Like> Likers { get; set; }
public ICollection<Like> Likees { get; set; }
public ICollection<Message> MessagesSent { get; set; }
public ICollection<Message> MessagesReceived { get; set; }
public virtual ICollection<Photo> Photos { get; set; }
public virtual ICollection<Like> Likers { get; set; }
public virtual ICollection<Like> Likees { get; set; }
public virtual ICollection<Message> MessagesSent { get; set; }
public virtual ICollection<Message> MessagesReceived { get; set; }

}
}
34 changes: 31 additions & 3 deletions DatingApp.API/Startup.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,11 +32,34 @@ public Startup(IConfiguration configuration)

public IConfiguration Configuration { get; }

public void ConfigureDevelopmentServices(IServiceCollection services)
{
services.AddDbContext<DataContext>(x =>
{
x.UseLazyLoadingProxies();
x.UseSqlite(Configuration.GetConnectionString("DefaultConnection"));
});

ConfigureServices(services);
}

public void ConfigureProductionServices(IServiceCollection services)
{
services.AddDbContext<DataContext>(x =>
{
x.UseLazyLoadingProxies();
x.UseMySql(Configuration.GetConnectionString("DefaultConnection"));
});

ConfigureServices(services);
}


// This method gets called by the runtime. Use this method to add services to the container.
public void ConfigureServices(IServiceCollection services)
{
//services.AddDbContext<DataContext>(x => x.UseSqlite("ConnectionString"));
services.AddDbContext<DataContext>(x => x.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
//services.AddDbContext<DataContext>(x => x.UseSqlite(Configuration.GetConnectionString("DefaultConnection")));
services.AddControllers().AddNewtonsoftJson(opt =>
{
opt.SerializerSettings.ReferenceLoopHandling =
Expand Down Expand Up @@ -87,15 +110,20 @@ public void Configure(IApplicationBuilder app, IWebHostEnvironment env)

app.UseRouting();

app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());

app.UseAuthentication();

app.UseAuthorization();

app.UseCors(x => x.AllowAnyOrigin().AllowAnyMethod().AllowAnyHeader());

app.UseDefaultFiles(); //it'll look for index.html or a default file that a server expect

app.UseStaticFiles(); //this will able to run local host 5000

app.UseEndpoints(endpoints =>
{
endpoints.MapControllers();
endpoints.MapFallbackToController("Index", "Fallback");
});
}
}
Expand Down
3 changes: 3 additions & 0 deletions DatingApp.API/appsettings.Development.json
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
{
"ConnectionStrings" : {
"DefaultConnection": "Data Source=datingapp.db"
},
"Logging": {
"LogLevel": {
"Default": "Information",
Expand Down
2 changes: 1 addition & 1 deletion DatingApp.API/appsettings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
"Token": "super secret key"
},
"ConnectionStrings" : {
"DefaultConnection": "Data Source=datingapp.db"
"DefaultConnection": "Server=localhost; Database=datingapp; Uid=appuser; Pwd=password"
},
"Logging": {
"LogLevel": {
Expand Down
Loading

0 comments on commit 8c3bbee

Please sign in to comment.