-
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Seperated Workspace server methods to own class
- Loading branch information
Showing
5 changed files
with
151 additions
and
90 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using System.Collections.Immutable; | ||
using Somfic.Common; | ||
using Vla.Server.Messages; | ||
using Vla.Server.Messages.Requests; | ||
using Vla.Server.Messages.Response; | ||
using Vla.Workspace; | ||
using WatsonWebsocket; | ||
|
||
namespace Vla.Server.Methods; | ||
|
||
public class Workspaces : IServerMethods | ||
{ | ||
private readonly WorkspaceService _workspaces; | ||
|
||
public Workspaces(WorkspaceService workspaces) | ||
{ | ||
_workspaces = workspaces; | ||
} | ||
|
||
[Request("workspaces-list-recent")] | ||
private async Task<ISocketResponse> OnWorkspacesListRecent(ClientMetadata client) | ||
{ | ||
var workspaces = await _workspaces.ListRecentAsync(); | ||
|
||
return workspaces | ||
.Map<ISocketResponse, ImmutableArray<Abstractions.Workspace>>( | ||
w => new WorkspacesResponse(w), | ||
e => new ExceptionResponse(e)); | ||
} | ||
|
||
[Request("workspace-create")] | ||
private async Task<ISocketResponse> OnWorkspaceCreate(ClientMetadata client, CreateWorkspaceRequest request) | ||
{ | ||
var workspace = await _workspaces.CreateOrLoadAsync(request.Name, request.Path); | ||
|
||
return workspace | ||
.Map<ISocketResponse, Abstractions.Workspace>( | ||
w => new WorkspaceResponse(w), | ||
e => new ExceptionResponse(e)); | ||
} | ||
|
||
[Request("workspace-save")] | ||
private async Task OnWorkspaceSave(ClientMetadata client, WorkspaceRequest request) | ||
{ | ||
await _workspaces.SaveAsync(request.Workspace); | ||
} | ||
} | ||
|
||
public interface IServerMethods | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
namespace Vla.Server; | ||
|
||
[AttributeUsage(AttributeTargets.Method)] | ||
public class RequestAttribute(string id) : Attribute | ||
{ | ||
public string Id { get; } = id; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters