forked from patryk-zielinski93/sdj-api
-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Remove in memory queue observable. Move more info about the queue to the db. Add queue as an observable only in the ws layer, based on the db and events.
- Loading branch information
1 parent
7492c70
commit 654c800
Showing
53 changed files
with
236 additions
and
427 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
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
5 changes: 1 addition & 4 deletions
5
.../application-services/src/lib/commands/delete-queued-track/delete-queued-track.handler.ts
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 |
---|---|---|
@@ -1,21 +1,18 @@ | ||
import { CommandHandler, ICommandHandler } from '@nestjs/cqrs'; | ||
import { QueuedTrackRepositoryInterface } from '@sdj/backend/radio/core/domain'; | ||
import { Store } from '../../ports/store.port'; | ||
import { DeleteQueuedTrackCommand } from './delete-queued-track.command'; | ||
|
||
@CommandHandler(DeleteQueuedTrackCommand) | ||
export class DeleteQueuedTrackHandler | ||
implements ICommandHandler<DeleteQueuedTrackCommand> { | ||
constructor( | ||
private readonly queuedTrackRepository: QueuedTrackRepositoryInterface, | ||
private readonly storageService: Store | ||
private readonly queuedTrackRepository: QueuedTrackRepositoryInterface | ||
) {} | ||
|
||
async execute(command: DeleteQueuedTrackCommand): Promise<void> { | ||
const queuedTrack = await this.queuedTrackRepository.findOneOrFail( | ||
command.queuedTrackId | ||
); | ||
await this.storageService.removeFromQueue(queuedTrack); | ||
await this.queuedTrackRepository.remove(queuedTrack); | ||
} | ||
} |
2 changes: 1 addition & 1 deletion
2
...core/application-services/src/lib/commands/download-and-play/download-and-play.handler.ts
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
2 changes: 1 addition & 1 deletion
2
...core/application-services/src/lib/commands/skip-queued-track/skip-queued-track.handler.ts
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
2 changes: 1 addition & 1 deletion
2
...backend/radio/core/application-services/src/lib/commands/thumb-down/thumb-down.handler.ts
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
36 changes: 14 additions & 22 deletions
36
...o/core/application-services/src/lib/events/play-queued-track/play-queued-track.handler.ts
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 |
---|---|---|
@@ -1,38 +1,30 @@ | ||
import { EventsHandler, IEventHandler } from '@nestjs/cqrs'; | ||
import { EventPublisher, EventsHandler, IEventHandler } from '@nestjs/cqrs'; | ||
import { | ||
QueuedTrack, | ||
ChannelRepositoryInterface, | ||
PlayQueuedTrackEvent, | ||
QueuedTrackRepositoryInterface, | ||
} from '@sdj/backend/radio/core/domain'; | ||
import { Store } from '../../ports/store.port'; | ||
import { PlayQueuedTrackEvent } from './play-queued-track.event'; | ||
|
||
@EventsHandler(PlayQueuedTrackEvent) | ||
export class PlayQueuedTrackHandler | ||
implements IEventHandler<PlayQueuedTrackEvent> { | ||
constructor( | ||
private readonly storageService: Store, | ||
private queuedTrackRepository: QueuedTrackRepositoryInterface | ||
private queuedTrackRepository: QueuedTrackRepositoryInterface, | ||
private channelRepository: ChannelRepositoryInterface, | ||
private publisher: EventPublisher | ||
) {} | ||
|
||
async handle(event: PlayQueuedTrackEvent): Promise<unknown> { | ||
async handle(event: PlayQueuedTrackEvent): Promise<void> { | ||
const queuedTrack = await this.queuedTrackRepository.findOneOrFail( | ||
event.queuedTrackId | ||
); | ||
const channelId = queuedTrack.playedIn.id; | ||
const prevTrack = await this.storageService.getCurrentTrack(channelId); | ||
if (prevTrack) { | ||
await this.storageService.removeFromQueue(prevTrack); | ||
} | ||
await this.storageService.setCurrentTrack(channelId, queuedTrack); | ||
await this.updateQueuedTrackPlayedAt(queuedTrack); | ||
return this.storageService.setSilenceCount(channelId, 0); | ||
} | ||
|
||
updateQueuedTrackPlayedAt( | ||
queuedTrack: QueuedTrack, | ||
playedAt?: Date | ||
): Promise<QueuedTrack> { | ||
queuedTrack.playedAt = playedAt || new Date(); | ||
return this.queuedTrackRepository.save(queuedTrack); | ||
const channel = this.publisher.mergeObjectContext( | ||
await this.channelRepository.findOrFail(channelId) | ||
); | ||
channel.play(queuedTrack); | ||
await this.channelRepository.save(channel); | ||
await this.queuedTrackRepository.save(queuedTrack); | ||
channel.commit(); | ||
} | ||
} |
20 changes: 0 additions & 20 deletions
20
...ckend/radio/core/application-services/src/lib/events/play-silence/play-silence.handler.ts
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.