feature/dotnet #3

Merged
jackhadrill merged 5 commits from feature/dotnet into master 2020-09-21 23:43:41 +01:00
10 changed files with 66 additions and 45 deletions
Showing only changes of commit 238e42f28c - Show all commits

View File

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

View File

@ -26,41 +26,42 @@ namespace VCinemaApi.Hubs
public override async Task OnDisconnectedAsync(Exception exception) public override async Task OnDisconnectedAsync(Exception exception)
{ {
_watcherRepository.DeleteWatcher(Context.ConnectionId); _watcherRepository.DeleteWatcherByConnectionId(Context.ConnectionId);
await base.OnDisconnectedAsync(exception); 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) public void DeleteScreen(int screenId)
{ {
throw new NotImplementedException(); _screenRepository.DeleteScreenById(screenId);
} }
public Screen WatchScreen(int screenId) public Screen WatchScreen(int screenId)
{ {
throw new NotImplementedException(); var watcher = _watcherRepository.SetWatcherScreenByConnectionId(Context.ConnectionId, screenId);
return watcher.Screen;
} }
public void LeaveScreen() 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(); throw new NotImplementedException();
} }
public void SetPlayState(bool playing) public Screen SetPlayState(bool playing, int playOffset)
{
throw new NotImplementedException();
}
public void SetPlayState(bool playing, int playOffset)
{ {
throw new NotImplementedException(); throw new NotImplementedException();
} }

View File

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

View File

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

View File

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

View File

@ -9,8 +9,9 @@ namespace VCinemaApi.Repositories
IEnumerable<Watcher> GetWatchersByScreenId(int screenId); IEnumerable<Watcher> GetWatchersByScreenId(int screenId);
Watcher GetWatcherByConnectionId(string connectionId); Watcher GetWatcherByConnectionId(string connectionId);
Watcher AddWatcher(string connectionId); Watcher AddWatcher(string connectionId);
Watcher AddWatcher(string connectionId, int screenId); Watcher SetWatcherNameByConnectionId(string connectionId, string name);
Watcher SetWatcherName(string connectionId, string name); Watcher SetWatcherScreenByConnectionId(string connectionId, int screenId);
void DeleteWatcher(string connectionId); 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 return new Screen
{ {
ScreenId = 1, ScreenId = id,
Name = "Kirby's screen", Name = "Kirby's screen",
Source = "https://vcinema.b-cdn.net/shrek.mp4", Source = "https://vcinema.b-cdn.net/shrek.mp4",
PlayStateUpdated = DateTime.UtcNow, 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 return new Screen
{ {
ScreenId = 1, ScreenId = 1,
Name = "Kirby's screen", Name = name,
Source = "https://vcinema.b-cdn.net/shrek.mp4", Source = source,
PlayStateUpdated = DateTime.UtcNow, PlayStateUpdated = DateTime.UtcNow,
PlayState = true, PlayState = true,
PlayOffset = 1337 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 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 return new Watcher
{ {

View File

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

View File

@ -36,9 +36,19 @@ namespace VCinemaApi.Repositories
return watcher; 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); var screen = _context.Screens.Find(screenId);
watcher.Screen = screen; watcher.Screen = screen;
@ -47,17 +57,17 @@ namespace VCinemaApi.Repositories
return watcher; 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(); _context.SaveChanges();
return watcher; return watcher;
} }
public void DeleteWatcher(string connectionId) public void DeleteWatcherByConnectionId(string connectionId)
{ {
var watcher = GetWatcherByConnectionId(connectionId); var watcher = GetWatcherByConnectionId(connectionId);
_context.Watchers.Remove(watcher); _context.Watchers.Remove(watcher);