adding user & watcher details, skeleton for controllers
This commit is contained in:
parent
bbfe663797
commit
1f94b624d2
@ -67,11 +67,6 @@ namespace Selector.CLI
|
||||
#nullable disable
|
||||
}
|
||||
|
||||
enum WatcherType
|
||||
{
|
||||
Player, Playlist
|
||||
}
|
||||
|
||||
enum Consumers
|
||||
{
|
||||
AudioFeatures
|
||||
|
@ -21,12 +21,17 @@ namespace Selector.Model
|
||||
|
||||
protected override void OnConfiguring(DbContextOptionsBuilder optionsBuilder)
|
||||
{
|
||||
|
||||
|
||||
}
|
||||
|
||||
protected override void OnModelCreating(ModelBuilder modelBuilder)
|
||||
{
|
||||
base.OnModelCreating(modelBuilder);
|
||||
|
||||
modelBuilder.Entity<Watcher>()
|
||||
.HasOne(w => w.User)
|
||||
.WithMany(u => u.Watchers)
|
||||
.HasForeignKey(w => w.UserId);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -1,9 +1,22 @@
|
||||
using System;
|
||||
using System.Collections.Generic;
|
||||
using System.ComponentModel.DataAnnotations;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
|
||||
namespace Selector.Model
|
||||
{
|
||||
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; }
|
||||
}
|
||||
}
|
@ -7,5 +7,10 @@ namespace Selector.Model
|
||||
public class Watcher
|
||||
{
|
||||
public int Id { get; set; }
|
||||
|
||||
public string UserId { get; set; }
|
||||
public ApplicationUser User { get; set; }
|
||||
|
||||
public WatcherType Type { get; set; }
|
||||
}
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
}
|
49
Selector.Web/Controller/UserController.cs
Normal file
49
Selector.Web/Controller/UserController.cs
Normal 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();
|
||||
}
|
||||
}
|
||||
}
|
49
Selector.Web/Controller/WatcherController.cs
Normal file
49
Selector.Web/Controller/WatcherController.cs
Normal 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
7
Selector/Enums.cs
Normal file
@ -0,0 +1,7 @@
|
||||
namespace Selector
|
||||
{
|
||||
public enum WatcherType
|
||||
{
|
||||
Player, Playlist
|
||||
}
|
||||
}
|
@ -9,6 +9,7 @@
|
||||
<ItemGroup>
|
||||
<PackageReference Include="Microsoft.Extensions.Logging" Version="5.0.0" />
|
||||
<PackageReference Include="SpotifyAPI.Web" Version="6.2.2" />
|
||||
<PackageReference Include="Inflatable.Lastfm" Version="1.2.0" />
|
||||
</ItemGroup>
|
||||
|
||||
</Project>
|
||||
|
Loading…
Reference in New Issue
Block a user