Update transactions to match design

This commit is contained in:
Jack Hadrill 2020-09-21 23:42:17 +01:00
parent cc639c04b5
commit 238e42f28c
10 changed files with 66 additions and 45 deletions

View File

@ -4,12 +4,12 @@ namespace VCinemaApi.Hubs
{
public interface IVCinemaHub
{
public Screen CreateScreen(string name);
public Screen CreateScreen(string name, string source);
public void DeleteScreen(int screenId);
public Screen WatchScreen(int screenId);
public void LeaveScreen();
public void SetWatcherName(string name);
public void SetPlayState(bool playing);
public Watcher SetWatcherName(string name);
public Screen SetPlayState(bool playing);
public void SetPlayState(bool playing, int playOffset);
}
}

View File

@ -26,41 +26,42 @@ namespace VCinemaApi.Hubs
public override async Task OnDisconnectedAsync(Exception exception)
{
_watcherRepository.DeleteWatcher(Context.ConnectionId);
_watcherRepository.DeleteWatcherByConnectionId(Context.ConnectionId);
await base.OnDisconnectedAsync(exception);
}
public Screen CreateScreen(string name)
public Screen CreateScreen(string name, string source)
{
throw new NotImplementedException();
return _screenRepository.AddScreen(name, source);
}
public void DeleteScreen(int screenId)
{
throw new NotImplementedException();
_screenRepository.DeleteScreenById(screenId);
}
public Screen WatchScreen(int screenId)
{
throw new NotImplementedException();
var watcher = _watcherRepository.SetWatcherScreenByConnectionId(Context.ConnectionId, screenId);
return watcher.Screen;
}
public void LeaveScreen()
{
throw new NotImplementedException();
_watcherRepository.UnsetWatcherScreenByConnectionId(Context.ConnectionId);
}
public void SetWatcherName(string name)
public Watcher SetWatcherName(string name)
{
return _watcherRepository.SetWatcherNameByConnectionId(Context.ConnectionId, name);
}
public Screen SetPlayState(bool playing)
{
throw new NotImplementedException();
}
public void SetPlayState(bool playing)
{
throw new NotImplementedException();
}
public void SetPlayState(bool playing, int playOffset)
public Screen SetPlayState(bool playing, int playOffset)
{
throw new NotImplementedException();
}

View File

@ -1,7 +1,6 @@
using System;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
namespace VCinemaApi.Models
{

View File

@ -1,6 +1,4 @@
using System;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.ComponentModel.DataAnnotations;
namespace VCinemaApi.Models
{

View File

@ -7,8 +7,8 @@ namespace VCinemaApi.Repositories
public interface IScreenRepository
{
IEnumerable<Screen> GetScreens();
Screen GetScreenById(int screenId);
Screen AddScreen(string screenName);
void DeleteScreen(int screenId);
Screen GetScreenById(int id);
Screen AddScreen(string name, string source);
void DeleteScreenById(int id);
}
}

View File

@ -9,8 +9,9 @@ namespace VCinemaApi.Repositories
IEnumerable<Watcher> GetWatchersByScreenId(int screenId);
Watcher GetWatcherByConnectionId(string connectionId);
Watcher AddWatcher(string connectionId);
Watcher AddWatcher(string connectionId, int screenId);
Watcher SetWatcherName(string connectionId, string name);
void DeleteWatcher(string connectionId);
Watcher SetWatcherNameByConnectionId(string connectionId, string name);
Watcher SetWatcherScreenByConnectionId(string connectionId, int screenId);
Watcher UnsetWatcherScreenByConnectionId(string connectionId);
void DeleteWatcherByConnectionId(string connectionId);
}
}

View File

@ -30,11 +30,11 @@ namespace VCinemaApi.Repositories
};
}
public Screen GetScreenById(int screenId)
public Screen GetScreenById(int id)
{
return new Screen
{
ScreenId = 1,
ScreenId = id,
Name = "Kirby's screen",
Source = "https://vcinema.b-cdn.net/shrek.mp4",
PlayStateUpdated = DateTime.UtcNow,
@ -43,20 +43,20 @@ namespace VCinemaApi.Repositories
};
}
public Screen AddScreen(string screenName)
public Screen AddScreen(string name, string source)
{
return new Screen
{
ScreenId = 1,
Name = "Kirby's screen",
Source = "https://vcinema.b-cdn.net/shrek.mp4",
Name = name,
Source = source,
PlayStateUpdated = DateTime.UtcNow,
PlayState = true,
PlayOffset = 1337
};
}
public void DeleteScreen(int screenId)
public void DeleteScreenById(int screenId)
{
}

View File

@ -60,7 +60,18 @@ namespace VCinemaApi.Repositories
};
}
public Watcher AddWatcher(string connectionId, int screenId)
public Watcher SetWatcherName(string connectionId, string name)
{
return new Watcher
{
WatcherId = 1,
ConnectionId = connectionId,
Name = "Kirby",
Screen = null
};
}
public Watcher SetWatcherScreen(string connectionId, int screenId)
{
return new Watcher
{
@ -79,7 +90,7 @@ namespace VCinemaApi.Repositories
};
}
public Watcher SetWatcherName(string connectionId, string name)
public Watcher UnsetWatcherScreen(string connectionId)
{
return new Watcher
{

View File

@ -18,16 +18,17 @@ namespace VCinemaApi.Repositories
return _context.Screens.ToList();
}
public Screen GetScreenById(int screenId)
public Screen GetScreenById(int id)
{
return _context.Screens.Find(screenId);
return _context.Screens.Find(id);
}
public Screen AddScreen(string screenName)
public Screen AddScreen(string name, string source)
{
var screen = new Screen
{
Name = screenName
Name = name,
Source = source
};
_context.Screens.Add(screen);
@ -36,7 +37,7 @@ namespace VCinemaApi.Repositories
return screen;
}
public void DeleteScreen(int screenId)
public void DeleteScreenById(int screenId)
{
var screen = GetScreenById(screenId);
_context.Screens.Remove(screen);

View File

@ -36,9 +36,19 @@ namespace VCinemaApi.Repositories
return watcher;
}
public Watcher AddWatcher(string connectionId, int screenId)
public Watcher SetWatcherNameByConnectionId(string connectionId, string name)
{
var watcher = _context.Watchers.SingleOrDefault(watcher => watcher.ConnectionId == connectionId);
var watcher = GetWatcherByConnectionId(connectionId);
watcher.Name = name;
_context.SaveChanges();
return watcher;
}
public Watcher SetWatcherScreenByConnectionId(string connectionId, int screenId)
{
var watcher = GetWatcherByConnectionId(connectionId);
var screen = _context.Screens.Find(screenId);
watcher.Screen = screen;
@ -47,17 +57,17 @@ namespace VCinemaApi.Repositories
return watcher;
}
public Watcher SetWatcherName(string connectionId, string name)
public Watcher UnsetWatcherScreenByConnectionId(string connectionId)
{
var watcher = _context.Watchers.SingleOrDefault(watcher => watcher.ConnectionId == connectionId);
var watcher = GetWatcherByConnectionId(connectionId);
watcher.Name = name;
watcher.Screen = null;
_context.SaveChanges();
return watcher;
}
public void DeleteWatcher(string connectionId)
public void DeleteWatcherByConnectionId(string connectionId)
{
var watcher = GetWatcherByConnectionId(connectionId);
_context.Watchers.Remove(watcher);