Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Move websocket event to publish by subscriber
- Loading branch information
Showing
9 changed files
with
102 additions
and
34 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,18 @@ | ||
package subscriber | ||
|
||
type DatabaseChange[T any] struct { | ||
Before *T | ||
After *T | ||
} | ||
|
||
func (c *DatabaseChange[T]) Created() bool { | ||
return c.Before == nil && c.After != nil | ||
} | ||
|
||
func (c *DatabaseChange[T]) Updated() bool { | ||
return c.Before != nil && c.After != nil | ||
} | ||
|
||
func (c *DatabaseChange[T]) Deleted() bool { | ||
return c.Before != nil && c.After == nil | ||
} |
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
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,41 @@ | ||
package usecase | ||
|
||
import ( | ||
"context" | ||
|
||
"github.com/elct9620/wvs/pkg/event" | ||
) | ||
|
||
type NotifyJoinMatchCommandInput struct { | ||
MatchId string | ||
PlayerId string | ||
} | ||
|
||
type NotifyJoinMatchCommandOutput struct { | ||
} | ||
|
||
var _ Command[*NotifyJoinMatchCommandInput, *NotifyJoinMatchCommandOutput] = &NotifyJoinMatchCommand{} | ||
|
||
type NotifyJoinMatchCommand struct { | ||
streams StreamRepository | ||
} | ||
|
||
func NewNotifyJoinMatchCommand(streams StreamRepository) *NotifyJoinMatchCommand { | ||
return &NotifyJoinMatchCommand{ | ||
streams: streams, | ||
} | ||
} | ||
|
||
func (c *NotifyJoinMatchCommand) Execute(ctx context.Context, input *NotifyJoinMatchCommandInput) (*NotifyJoinMatchCommandOutput, error) { | ||
stream, err := c.streams.Find(ctx, input.PlayerId) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
event := event.NewJoinMatchEvent(input.MatchId, input.PlayerId) | ||
if err := stream.Publish(event); err != nil { | ||
return nil, err | ||
} | ||
|
||
return &NotifyJoinMatchCommandOutput{}, nil | ||
} |
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.