adding user & watcher details, skeleton for controllers

This commit is contained in:
andy 2021-10-24 22:40:15 +01:00
parent bbfe663797
commit 1f94b624d2
9 changed files with 130 additions and 36 deletions

View File

@ -67,11 +67,6 @@ namespace Selector.CLI
#nullable disable #nullable disable
} }
enum WatcherType
{
Player, Playlist
}
enum Consumers enum Consumers
{ {
AudioFeatures AudioFeatures

View File

@ -27,6 +27,11 @@ namespace Selector.Model
protected override void OnModelCreating(ModelBuilder modelBuilder) protected override void OnModelCreating(ModelBuilder modelBuilder)
{ {
base.OnModelCreating(modelBuilder); base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Watcher>()
.HasOne(w => w.User)
.WithMany(u => u.Watchers)
.HasForeignKey(w => w.UserId);
} }
} }

View File

@ -1,9 +1,22 @@
using System; using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Identity; using Microsoft.AspNetCore.Identity;
using Microsoft.EntityFrameworkCore;
namespace Selector.Model namespace Selector.Model
{ {
public class ApplicationUser : IdentityUser public class ApplicationUser : IdentityUser
{ {
[Required]
public bool SpotifyIsLinked { get; set; }
public DateTime SpotifyLastRefresh { get; set; }
public int SpotifyTokenExpiry { get; set; }
public string SpotifyAccessToken { get; set; }
public string SpotifyRefreshToken { get; set; }
public string LastFmUsername { get; set; }
public List<Watcher> Watchers { get; set; }
} }
} }

View File

@ -7,5 +7,10 @@ namespace Selector.Model
public class Watcher public class Watcher
{ {
public int Id { get; set; } public int Id { get; set; }
public string UserId { get; set; }
public ApplicationUser User { get; set; }
public WatcherType Type { get; set; }
} }
} }

View File

@ -1,30 +0,0 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Selector.Model;
namespace Selector.Web.Controller {
[ApiController]
[Route("api/[controller]")]
public class TestController {
private readonly ApplicationDbContext db;
public TestController(ApplicationDbContext context)
{
db = context;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<ApplicationUser>>> Get()
{
// var watchers = ;
return await db.Users.ToListAsync();
}
}
}

View File

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Selector.Model;
namespace Selector.Web.Controller {
[ApiController]
[Route("api/[controller]")]
public class UsersController {
private readonly ApplicationDbContext db;
public UsersController(ApplicationDbContext context)
{
db = context;
}
[HttpGet()]
public async Task<ActionResult<IEnumerable<ApplicationUser>>> Get(string username)
{
// TODO: Authorise
return await db.Users.ToListAsync();
}
}
[ApiController]
[Route("api/[controller]")]
public class UserController {
private readonly ApplicationDbContext db;
public UserController(ApplicationDbContext context)
{
db = context;
}
[HttpGet("{username}")]
public async Task<ActionResult<ApplicationUser>> Get(string username)
{
// TODO: Implement
return await db.Users.SingleAsync();
}
}
}

View File

@ -0,0 +1,49 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.AspNetCore.Identity;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore;
using Selector.Model;
namespace Selector.Web.Controller {
[ApiController]
[Route("api/[controller]")]
public class WatchersController {
private readonly ApplicationDbContext db;
public WatchersController(ApplicationDbContext context)
{
db = context;
}
[HttpGet]
public async Task<ActionResult<IEnumerable<Watcher>>> Get()
{
// TODO: Authorise
return await db.Watcher.ToListAsync();
}
}
[ApiController]
[Route("api/[controller]")]
public class WatcherController {
private readonly ApplicationDbContext db;
public WatcherController(ApplicationDbContext context)
{
db = context;
}
[HttpGet("{id}")]
public async Task<ActionResult<Watcher>> Get(int id)
{
// TODO: Implement
return await db.Watcher.FirstAsync();
}
}
}

7
Selector/Enums.cs Normal file
View File

@ -0,0 +1,7 @@
namespace Selector
{
public enum WatcherType
{
Player, Playlist
}
}

View File

@ -9,6 +9,7 @@
<ItemGroup> <ItemGroup>
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" /> <PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
<PackageReference Include="SpotifyAPI.Web" Version="6.2.2" /> <PackageReference Include="SpotifyAPI.Web" Version="6.2.2" />
<PackageReference Include="Inflatable.Lastfm" Version="1.2.0" />
</ItemGroup> </ItemGroup>
</Project> </Project>