From 25acc8dc3ea9643c84df3c36aee609d064364a77 Mon Sep 17 00:00:00 2001 From: Naoki Kishi Date: Thu, 6 Aug 2020 23:48:57 +0900 Subject: [PATCH 1/2] =?UTF-8?q?=E6=9B=B2=E5=86=8D=E7=94=9F=E6=99=82?= =?UTF-8?q?=E3=81=AB=E6=98=8E=E7=A4=BA=E7=9A=84=E3=81=AB=E7=A7=92=E6=95=B0?= =?UTF-8?q?=E3=82=92=E6=8C=87=E5=AE=9A=E3=81=99=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- domain/mock_spotify/player.go | 28 ---------------------------- domain/spotify/player.go | 2 -- usecase/session_state.go | 3 ++- web/handler/session_state_test.go | 2 +- 4 files changed, 3 insertions(+), 32 deletions(-) diff --git a/domain/mock_spotify/player.go b/domain/mock_spotify/player.go index c6ec8eec..ab13cb2b 100644 --- a/domain/mock_spotify/player.go +++ b/domain/mock_spotify/player.go @@ -50,34 +50,6 @@ func (mr *MockPlayerMockRecorder) CurrentlyPlaying(ctx interface{}) *gomock.Call return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "CurrentlyPlaying", reflect.TypeOf((*MockPlayer)(nil).CurrentlyPlaying), ctx) } -// Play mocks base method -func (m *MockPlayer) Play(ctx context.Context, deviceID string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "Play", ctx, deviceID) - ret0, _ := ret[0].(error) - return ret0 -} - -// Play indicates an expected call of Play -func (mr *MockPlayerMockRecorder) Play(ctx, deviceID interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "Play", reflect.TypeOf((*MockPlayer)(nil).Play), ctx, deviceID) -} - -// PlayWithTracks mocks base method -func (m *MockPlayer) PlayWithTracks(ctx context.Context, deviceID string, trackURIs []string) error { - m.ctrl.T.Helper() - ret := m.ctrl.Call(m, "PlayWithTracks", ctx, deviceID, trackURIs) - ret0, _ := ret[0].(error) - return ret0 -} - -// PlayWithTracks indicates an expected call of PlayWithTracks -func (mr *MockPlayerMockRecorder) PlayWithTracks(ctx, deviceID, trackURIs interface{}) *gomock.Call { - mr.mock.ctrl.T.Helper() - return mr.mock.ctrl.RecordCallWithMethodType(mr.mock, "PlayWithTracks", reflect.TypeOf((*MockPlayer)(nil).PlayWithTracks), ctx, deviceID, trackURIs) -} - // PlayWithTracksAndPosition mocks base method func (m *MockPlayer) PlayWithTracksAndPosition(ctx context.Context, deviceID string, trackURIs []string, position time.Duration) error { m.ctrl.T.Helper() diff --git a/domain/spotify/player.go b/domain/spotify/player.go index 6e2175d8..ca54947e 100644 --- a/domain/spotify/player.go +++ b/domain/spotify/player.go @@ -12,8 +12,6 @@ import ( // Player はSpotifyの曲の操作に関連するAPIを呼び出すためのインターフェースです。 type Player interface { CurrentlyPlaying(ctx context.Context) (*entity.CurrentPlayingInfo, error) - Play(ctx context.Context, deviceID string) error - PlayWithTracks(ctx context.Context, deviceID string, trackURIs []string) error PlayWithTracksAndPosition(ctx context.Context, deviceID string, trackURIs []string, position time.Duration) error Pause(ctx context.Context, deviceID string) error Enqueue(ctx context.Context, trackURI string, deviceID string) error diff --git a/usecase/session_state.go b/usecase/session_state.go index 1fb929df..d407d917 100644 --- a/usecase/session_state.go +++ b/usecase/session_state.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "time" "github.com/camphor-/relaym-server/domain/entity" "github.com/camphor-/relaym-server/domain/event" @@ -230,7 +231,7 @@ func (s *SessionStateUseCase) stopToPlay(ctx context.Context, sess *entity.Sessi } for i := 0; i < len(trackURIs); i++ { if i == 0 { - if err := s.playerCli.PlayWithTracks(ctx, sess.DeviceID, trackURIs[:1]); err != nil { + if err := s.playerCli.PlayWithTracksAndPosition(ctx, sess.DeviceID, trackURIs[:1], 0*time.Second); err != nil { return fmt.Errorf("call play api with tracks %v: %w", trackURIs[:1], err) } continue diff --git a/web/handler/session_state_test.go b/web/handler/session_state_test.go index 87d79109..359112f1 100644 --- a/web/handler/session_state_test.go +++ b/web/handler/session_state_test.go @@ -242,7 +242,7 @@ func TestSessionHandler_State_PLAY(t *testing.T) { m.EXPECT().SetRepeatMode(gomock.Any(), false, "device_id").Return(nil) m.EXPECT().SetShuffleMode(gomock.Any(), false, "device_id").Return(nil) m.EXPECT().DeleteAllTracksInQueue(gomock.Any(), "device_id", "spotify:track:5uQ0vKy2973Y9IUCd1wMEF").Return(nil) - m.EXPECT().PlayWithTracks(gomock.Any(), "device_id", []string{"spotify:track:5uQ0vKy2973Y9IUCd1wMEF"}).Return(nil) + m.EXPECT().PlayWithTracksAndPosition(gomock.Any(), "device_id", []string{"spotify:track:5uQ0vKy2973Y9IUCd1wMEF"}, 0*time.Second).Return(nil) m.EXPECT().Enqueue(gomock.Any(), "spotify:track:49BRCNV7E94s7Q2FUhhT3w", "device_id").Return(nil) m.EXPECT().Enqueue(gomock.Any(), "spotify:track:3", "device_id").Return(nil) }, From ce1867fa1d00097fe29ef863c0263896e5095dc8 Mon Sep 17 00:00:00 2001 From: Naoki Kishi Date: Fri, 7 Aug 2020 00:40:12 +0900 Subject: [PATCH 2/2] =?UTF-8?q?=E5=86=8D=E7=94=9F=E9=96=8B=E5=A7=8B?= =?UTF-8?q?=E6=99=82=E3=81=AEProgress=E3=82=92500ms=E3=81=AB=E3=81=99?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- usecase/session_state.go | 2 +- web/handler/session_state_test.go | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/usecase/session_state.go b/usecase/session_state.go index d407d917..38d2e85c 100644 --- a/usecase/session_state.go +++ b/usecase/session_state.go @@ -231,7 +231,7 @@ func (s *SessionStateUseCase) stopToPlay(ctx context.Context, sess *entity.Sessi } for i := 0; i < len(trackURIs); i++ { if i == 0 { - if err := s.playerCli.PlayWithTracksAndPosition(ctx, sess.DeviceID, trackURIs[:1], 0*time.Second); err != nil { + if err := s.playerCli.PlayWithTracksAndPosition(ctx, sess.DeviceID, trackURIs[:1], 500*time.Millisecond); err != nil { return fmt.Errorf("call play api with tracks %v: %w", trackURIs[:1], err) } continue diff --git a/web/handler/session_state_test.go b/web/handler/session_state_test.go index 359112f1..7330f0dd 100644 --- a/web/handler/session_state_test.go +++ b/web/handler/session_state_test.go @@ -242,7 +242,7 @@ func TestSessionHandler_State_PLAY(t *testing.T) { m.EXPECT().SetRepeatMode(gomock.Any(), false, "device_id").Return(nil) m.EXPECT().SetShuffleMode(gomock.Any(), false, "device_id").Return(nil) m.EXPECT().DeleteAllTracksInQueue(gomock.Any(), "device_id", "spotify:track:5uQ0vKy2973Y9IUCd1wMEF").Return(nil) - m.EXPECT().PlayWithTracksAndPosition(gomock.Any(), "device_id", []string{"spotify:track:5uQ0vKy2973Y9IUCd1wMEF"}, 0*time.Second).Return(nil) + m.EXPECT().PlayWithTracksAndPosition(gomock.Any(), "device_id", []string{"spotify:track:5uQ0vKy2973Y9IUCd1wMEF"}, 500*time.Millisecond).Return(nil) m.EXPECT().Enqueue(gomock.Any(), "spotify:track:49BRCNV7E94s7Q2FUhhT3w", "device_id").Return(nil) m.EXPECT().Enqueue(gomock.Any(), "spotify:track:3", "device_id").Return(nil) },