Added new many to many migration for libraries and users. Add Library now works and you can get Library (entity) objects from a user. LibraryDto project is upcoming.
This commit is contained in:
parent
d5eed4e85d
commit
b6e0e05205
9 changed files with 308 additions and 31 deletions
|
@ -9,11 +9,13 @@ using API.Entities;
|
|||
using API.Extensions;
|
||||
using API.Interfaces;
|
||||
using AutoMapper;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace API.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
public class LibraryController : BaseApiController
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
|
|
|
@ -7,11 +7,13 @@ using API.DTOs;
|
|||
using API.Entities;
|
||||
using API.Extensions;
|
||||
using API.Interfaces;
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.Extensions.Logging;
|
||||
|
||||
namespace API.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
public class UsersController : BaseApiController
|
||||
{
|
||||
private readonly DataContext _context;
|
||||
|
@ -36,6 +38,8 @@ namespace API.Controllers
|
|||
{
|
||||
//_logger.Log(LogLevel.Debug, "Creating a new " + createLibraryDto.Type + " library");
|
||||
var user = await _userRepository.GetUserByUsernameAsync(User.GetUsername());
|
||||
|
||||
if (user == null) return BadRequest("Could not validate user");
|
||||
|
||||
|
||||
if (await _libraryRepository.LibraryExists(createLibraryDto.Name))
|
||||
|
@ -44,26 +48,24 @@ namespace API.Controllers
|
|||
}
|
||||
|
||||
// TODO: We probably need to clean the folders before we insert
|
||||
var library = new Library()
|
||||
var library = new Library
|
||||
{
|
||||
Name = createLibraryDto.Name,
|
||||
Type = createLibraryDto.Type,
|
||||
//Folders = createLibraryDto.Folders
|
||||
AppUsers = new List<AppUser>() { user }
|
||||
};
|
||||
|
||||
|
||||
user.Libraries ??= new List<Library>(); // If user is null, then set it
|
||||
|
||||
user.Libraries.Add(library);
|
||||
_userRepository.Update(user);
|
||||
//_userRepository.Update(user);
|
||||
|
||||
if (await _userRepository.SaveAllAsync())
|
||||
{
|
||||
return Ok();
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
return BadRequest("Not implemented");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue