Skip to content

Commit 80d43c6

Browse files
Release v0.1.6
2 parents e4f53f5 + d469ed6 commit 80d43c6

21 files changed

+256
-87
lines changed

.github/workflows/build.yml

Lines changed: 25 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,34 @@ on:
55
pull_request:
66

77
jobs:
8-
98
build:
109
runs-on: ubuntu-latest
10+
1111
steps:
12-
- uses: actions/checkout@v2
12+
- name: Checkout code
13+
uses: actions/checkout@v2
14+
15+
- name: Set up Go
16+
uses: actions/setup-go@v2
17+
with:
18+
go-version: 1.16
19+
20+
- name: Fix go.sum for dependabot branches
21+
if: ${{ startsWith(github.ref, 'refs/heads/dependabot/go_modules/') }}
22+
run: go get ./...
23+
24+
- name: Commit & push updated go.sum for dependabot branches
25+
if: ${{ startsWith(github.ref, 'refs/heads/dependabot/go_modules/') }}
26+
uses: stefanzweifel/git-auto-commit-action@v4
27+
with:
28+
commit_message: Update go.sum
29+
file_pattern: go.sum
1330

14-
- name: Set up Go
15-
uses: actions/setup-go@v2
16-
with:
17-
go-version: 1.16
31+
- name: Build
32+
run: go build -v ./...
1833

19-
- name: Build
20-
run: go build -v ./...
34+
- name: Test
35+
run: go test -v ./...
2136

22-
- name: Test
23-
run: go test -v ./...
24-
25-
- name: Check formatting
26-
run: go fmt ./... && git diff --exit-code
37+
- name: Check formatting
38+
run: go fmt ./... && git diff --exit-code

.idea/vcs.xml

Lines changed: 7 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

authentication/session.go

Lines changed: 32 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,11 @@
11
package authentication
22

33
import (
4+
"crypto/rand"
45
"github.com/47-11/spotifete/database"
56
"github.com/47-11/spotifete/database/model"
6-
"math/rand"
7+
. "github.com/47-11/spotifete/shared"
8+
"math/big"
79
)
810

911
var letterRunes = []rune("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789")
@@ -19,33 +21,53 @@ func GetSession(sessionId string) *model.LoginSession {
1921
}
2022
}
2123

22-
func NewSession(callbackRedirectUrl string) (newSession model.LoginSession, spotifyAuthUrl string) {
24+
func NewSession(callbackRedirectUrl string) (newSession model.LoginSession, spotifyAuthUrl string, error *SpotifeteError) {
25+
sessionId, spotifeteError := newSessionId()
26+
if spotifeteError != nil {
27+
return model.LoginSession{}, "", spotifeteError
28+
}
29+
2330
newSession = model.LoginSession{
2431
BaseModel: model.BaseModel{},
25-
SessionId: newSessionId(),
32+
SessionId: sessionId,
2633
UserId: nil,
2734
Active: true,
2835
CallbackRedirect: callbackRedirectUrl,
2936
}
3037

3138
database.GetConnection().Create(&newSession)
32-
return newSession, authUrlForSession(newSession)
39+
return newSession, authUrlForSession(newSession), nil
3340
}
3441

35-
func newSessionId() string {
42+
func newSessionId() (string, *SpotifeteError) {
3643
for {
37-
b := make([]rune, 256)
38-
for i := range b {
39-
b[i] = letterRunes[rand.Intn(len(letterRunes))]
44+
newSessionId, spotifeteError := randomSessionId()
45+
if spotifeteError != nil {
46+
return "", spotifeteError
4047
}
41-
newSessionId := string(b)
4248

4349
if !sessionIdExists(newSessionId) {
44-
return newSessionId
50+
return newSessionId, nil
4551
}
4652
}
4753
}
4854

55+
func randomSessionId() (string, *SpotifeteError) {
56+
maxRandValue := big.NewInt(int64(len(letterRunes)))
57+
58+
b := make([]rune, 256)
59+
for i := range b {
60+
randInt, err := rand.Int(rand.Reader, maxRandValue)
61+
if err != nil {
62+
return "", NewInternalError("Could not generate random int", err)
63+
}
64+
65+
b[i] = letterRunes[randInt.Uint64()]
66+
}
67+
68+
return string(b), nil
69+
}
70+
4971
func sessionIdExists(sessionId string) bool {
5072
var count int64
5173

database/migration.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ import (
88
"gorm.io/gorm"
99
)
1010

11-
const targetDatabaseVersion = 31
11+
const targetDatabaseVersion = 32
1212

1313
func migrateIfNecessary(db *gorm.DB) {
1414
logger.Info("Connection acquired. Checking database version")

database/model/listeningSession.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ type SimpleListeningSession struct {
44
BaseModel
55
Active bool `json:"active"`
66
OwnerId uint `json:"owner_id"`
7-
JoinId *string `json:"join_id"`
7+
JoinId string `json:"join_id"`
88
QueuePlaylistId string `gorm:"column:queue_playlist" json:"queue_playlist_id"`
99
Title string `json:"title"`
1010
FallbackPlaylistId *string `gorm:"column:fallback_playlist" json:"fallback_playlist_id"`
@@ -17,7 +17,7 @@ func (SimpleListeningSession) TableName() string {
1717
type FullListeningSession struct {
1818
SimpleListeningSession
1919
Owner SimpleUser `gorm:"foreignKey:owner_id" json:"owner"`
20-
FallbackPlaylistMetadata *PlaylistMetadata `gorm:"foreignKey:fallback_playlist" json:"fallback_playlist_metadata"`
20+
FallbackPlaylistMetadata *PlaylistMetadata `gorm:"foreignKey:fallback_playlist;references:spotify_playlist_id" json:"fallback_playlist_metadata"`
2121
}
2222

2323
func (FullListeningSession) TableName() string {

database/model/songRequest.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ type SongRequest struct {
55
SessionId uint `json:"session_id"`
66
UserId *uint `json:"user_id"`
77
SpotifyTrackId string `json:"spotify_track_id"`
8-
TrackMetadata TrackMetadata `gorm:"foreignKey:spotify_track_id" json:"track_metadata"`
8+
TrackMetadata TrackMetadata `gorm:"foreignKey:spotify_track_id;references:spotify_track_id" json:"track_metadata"`
99
Status SongRequestStatus `json:"status"`
1010
}
1111

go.mod

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,15 @@ require (
2525
github.com/spf13/pflag v1.0.5 // indirect
2626
github.com/spf13/viper v1.7.1
2727
github.com/ugorji/go v1.2.4 // indirect
28-
github.com/zmb3/spotify v1.1.0
28+
github.com/zmb3/spotify v1.1.1
2929
golang.org/x/crypto v0.0.0-20210220033148-5ea612d1eb83 // indirect
30-
golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d // indirect
30+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 // indirect
3131
golang.org/x/oauth2 v0.0.0-20210220000619-9bb904979d93
32-
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43 // indirect
32+
golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b // indirect
3333
golang.org/x/text v0.3.5 // indirect
3434
google.golang.org/appengine v1.6.7 // indirect
3535
gopkg.in/ini.v1 v1.62.0 // indirect
3636
gopkg.in/yaml.v2 v2.4.0 // indirect
3737
gorm.io/driver/postgres v1.0.8
38-
gorm.io/gorm v1.20.12
38+
gorm.io/gorm v1.21.2
3939
)

go.sum

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,6 @@ github.com/gorilla/context v1.1.1/go.mod h1:kBGZzfjB9CEq2AlWe17Uuf7NDRt0dE0s8S51
244244
github.com/gorilla/handlers v1.4.2/go.mod h1:Qkdc/uu4tH4g6mTK6auzZ766c4CA0Ng8+o/OAirnOIQ=
245245
github.com/gorilla/mux v1.6.2/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
246246
github.com/gorilla/mux v1.7.3/go.mod h1:1lud6UwP+6orDFRuTfBEV8e9/aOM/c4fVVCaMa2zaAs=
247-
github.com/gorilla/mux v1.7.4 h1:VuZ8uybHlWmqV03+zRzdwKL4tUnIp1MAQtp1mIFE1bc=
248247
github.com/gorilla/mux v1.7.4/go.mod h1:DVbg23sWSpFRCP0SfiEN6jmj59UnW/n46BH5rLB71So=
249248
github.com/gorilla/websocket v1.4.1/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
250249
github.com/gorilla/websocket v1.4.2/go.mod h1:YR8l580nyteQvAITg2hZ9XVh4b55+EU/adAjf1fMHhE=
@@ -541,8 +540,9 @@ github.com/stretchr/testify v1.2.2/go.mod h1:a8OnRcib4nhh0OaRAV+Yts87kKdq0PP7pXf
541540
github.com/stretchr/testify v1.3.0/go.mod h1:M5WIy9Dh21IEIfnGCwXGc5bZfKNJtfHm1UVUgZn+9EI=
542541
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
543542
github.com/stretchr/testify v1.5.1/go.mod h1:5W2xD1RspED5o8YsWQXVCued0rvSQ+mT+I5cxcmMvtA=
544-
github.com/stretchr/testify v1.6.1 h1:hDPOHmpOpP40lSULcqw7IrRb/u7w6RpDC9399XyoNd0=
545543
github.com/stretchr/testify v1.6.1/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
544+
github.com/stretchr/testify v1.7.0 h1:nwc3DEeHmmLAfoZucVR881uASk0Mfjw8xYJ99tb5CcY=
545+
github.com/stretchr/testify v1.7.0/go.mod h1:6Fq8oRcR53rry900zMqJjRRixrwX3KX962/h/Wwjteg=
546546
github.com/subosito/gotenv v1.2.0 h1:Slr1R9HxAlEKefgq5jn9U+DnETlIUa6HfgEzj0g5d7s=
547547
github.com/subosito/gotenv v1.2.0/go.mod h1:N0PQaV/YGNqwC0u51sEeR/aUtSLEXKX9iv69rRypqCw=
548548
github.com/tidwall/pretty v0.0.0-20180105212114-65a9db5fad51/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
@@ -576,8 +576,8 @@ github.com/yuin/goldmark v1.1.25/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9de
576576
github.com/yuin/goldmark v1.1.27/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
577577
github.com/yuin/goldmark v1.1.32/go.mod h1:3hX8gzYuyVAZsxl0MRgGTJEmQBFcNTphYh9decYSb74=
578578
github.com/zenazn/goji v0.9.0/go.mod h1:7S9M489iMyHBNxwZnk9/EHS098H4/F6TATF2mIxtB1Q=
579-
github.com/zmb3/spotify v1.1.0 h1:bFn7yV3eSvJcwnDiI+iDcMdEVE+Fncl9/eHOkClzvGg=
580-
github.com/zmb3/spotify v1.1.0/go.mod h1:CYu0Uo+YYMlUX39zUTsCU9j3SpK3l1eB8oLykXF7R7w=
579+
github.com/zmb3/spotify v1.1.1 h1:3v2IxmzMrvl/1mieDINOI4JAXCJYWP/NQ4o2A1Ni35k=
580+
github.com/zmb3/spotify v1.1.1/go.mod h1:GD7AAEMUJVYc2Z7p2a2S0E3/5f/KxM/vOnErNr4j+Tw=
581581
gitlab.com/nyarla/go-crypt v0.0.0-20160106005555-d9a5dc2b789b/go.mod h1:T3BPAOm2cqquPa0MKWeNkmOM5RQsRhkrwMWonFMN7fE=
582582
go.etcd.io/bbolt v1.3.2/go.mod h1:IbVyRI1SCnLcuJnV2u8VeU0CEYM7e686BmAb1XKL+uU=
583583
go.mongodb.org/mongo-driver v1.1.0/go.mod h1:u7ryQJ+DOzQmeO7zB6MHyr8jkEQvC8vH7qLUO4lqsUM=
@@ -683,8 +683,8 @@ golang.org/x/net v0.0.0-20200813134508-3edf25e44fcc/go.mod h1:/O7V0waA8r7cgGh81R
683683
golang.org/x/net v0.0.0-20200822124328-c89045814202/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
684684
golang.org/x/net v0.0.0-20200904194848-62affa334b73/go.mod h1:/O7V0waA8r7cgGh81Ro3o1hOxt32SMVPicZroKQ2sZA=
685685
golang.org/x/net v0.0.0-20201029221708-28c70e62bb1d/go.mod h1:sp8m0HH+o8qH0wwXwYZr8TS3Oi6o0r6Gce1SSxlDquU=
686-
golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d h1:1aflnvSoWWLI2k/dMUAl5lvU1YO4Mb4hz0gh+1rjcxU=
687-
golang.org/x/net v0.0.0-20210220033124-5f55cee0dc0d/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
686+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110 h1:qWPm9rbaAMKs8Bq/9LRpbMqxWRVUAQwMI9fVrssnTfw=
687+
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg=
688688
golang.org/x/oauth2 v0.0.0-20180227000427-d7d64896b5ff/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
689689
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
690690
golang.org/x/oauth2 v0.0.0-20181106182150-f42d05182288/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
@@ -750,8 +750,8 @@ golang.org/x/sys v0.0.0-20200826173525-f9321e4c35a6/go.mod h1:h1NjWce9XRLGQEsW7w
750750
golang.org/x/sys v0.0.0-20200930185726-fdedc70b468f/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
751751
golang.org/x/sys v0.0.0-20201029080932-201ba4db2418/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
752752
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
753-
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43 h1:SgQ6LNaYJU0JIuEHv9+s6EbhSCwYeAf5Yvj6lpYlqAE=
754-
golang.org/x/sys v0.0.0-20210220050731-9a76102bfb43/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
753+
golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b h1:ggRgirZABFolTmi3sn6Ivd9SipZwLedQ5wR0aAKnFxU=
754+
golang.org/x/sys v0.0.0-20210305230114-8fe3ee5dd75b/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs=
755755
golang.org/x/term v0.0.0-20201117132131-f5c789dd3221/go.mod h1:Nr5EML6q2oocZ2LXRh80K7BxOlk5/8JxuGnuhpl+muw=
756756
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo=
757757
golang.org/x/text v0.0.0-20170915032832-14c0d48ead0c/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
@@ -764,7 +764,6 @@ golang.org/x/text v0.3.5/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ=
764764
golang.org/x/time v0.0.0-20181108054448-85acf8d2951c/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
765765
golang.org/x/time v0.0.0-20190308202827-9d24e82272b4/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
766766
golang.org/x/time v0.0.0-20191024005414-555d28b269f0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
767-
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e h1:EHBhcS0mlXEAVwNyO2dLfjToGsyY4j24pTs2ScHnX7s=
768767
golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ=
769768
golang.org/x/tools v0.0.0-20180221164845-07fd8470d635/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
770769
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
@@ -944,9 +943,9 @@ gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c h1:dUUwHk2QECo/6vqA44rthZ8ie
944943
gopkg.in/yaml.v3 v3.0.0-20200313102051-9f266ea9e77c/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM=
945944
gorm.io/driver/postgres v1.0.8 h1:PAgM+PaHOSAeroTjHkCHCBIHHoBIf9RgPWGo8dF2DA8=
946945
gorm.io/driver/postgres v1.0.8/go.mod h1:4eOzrI1MUfm6ObJU/UcmbXyiHSs8jSwH95G5P5dxcAg=
947-
gorm.io/gorm v1.20.12 h1:ebZ5KrSHzet+sqOCVdH9mTjW91L298nX3v5lVxAzSUY=
948946
gorm.io/gorm v1.20.12/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
949-
gotest.tools v2.2.0+incompatible h1:VsBPFP1AI068pPrMxtb/S8Zkgf9xEmTLJjfM+P5UIEo=
947+
gorm.io/gorm v1.21.2 h1:E9FgSzS9qZneyf5MlXTJBYEZ2ZZKrB993s2v+XBu7vo=
948+
gorm.io/gorm v1.21.2/go.mod h1:0HFTzE/SqkGTzK6TlDPPQbAYCluiVvhzoA1+aVyzenw=
950949
gotest.tools v2.2.0+incompatible/go.mod h1:DsYFclhRJ6vuDpmuTbkuFWG+y2sxOXAzmJt81HFBacw=
951950
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
952951
honnef.co/go/tools v0.0.0-20190106161140-3f1c8253044a/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=

listeningSession/listeningSession.go

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"math/rand"
1111
"net/http"
1212
"strings"
13+
"time"
1314
)
1415

1516
var numberRunes = []rune("0123456789")
@@ -29,9 +30,13 @@ func GetActiveSessionCount() uint {
2930
func FindSimpleListeningSession(filter model.SimpleListeningSession) *model.SimpleListeningSession {
3031
listeningSessions := FindSimpleListeningSessions(filter)
3132

32-
if len(listeningSessions) == 1 {
33+
resultCount := len(listeningSessions)
34+
if resultCount == 1 {
3335
return &listeningSessions[0]
36+
} else if resultCount == 0 {
37+
return nil
3438
} else {
39+
NewInternalError(fmt.Sprintf("Got more than one result for filter %v", filter), nil)
3540
return nil
3641
}
3742
}
@@ -45,9 +50,13 @@ func FindSimpleListeningSessions(filter model.SimpleListeningSession) []model.Si
4550
func FindFullListeningSession(filter model.SimpleListeningSession) *model.FullListeningSession {
4651
listeningSessions := FindFullListeningSessions(filter)
4752

48-
if len(listeningSessions) == 1 {
53+
resultCount := len(listeningSessions)
54+
if resultCount == 1 {
4955
return &listeningSessions[0]
56+
} else if resultCount == 0 {
57+
return nil
5058
} else {
59+
NewInternalError(fmt.Sprintf("Got more than one result for filter %v", filter), nil)
5160
return nil
5261
}
5362
}
@@ -88,7 +97,7 @@ func NewSession(user model.SimpleUser, title string) (*model.SimpleListeningSess
8897
BaseModel: model.BaseModel{},
8998
Active: true,
9099
OwnerId: user.ID,
91-
JoinId: &joinId,
100+
JoinId: joinId,
92101
QueuePlaylistId: playlist.ID.String(),
93102
Title: title,
94103
}
@@ -99,6 +108,8 @@ func NewSession(user model.SimpleUser, title string) (*model.SimpleListeningSess
99108
}
100109

101110
func newJoinId() string {
111+
rand.Seed(time.Now().UnixNano())
112+
102113
for {
103114
b := make([]rune, 8)
104115
for i := range b {
@@ -114,15 +125,17 @@ func newJoinId() string {
114125

115126
func joinIdFree(joinId string) bool {
116127
existingListeningSession := FindSimpleListeningSession(model.SimpleListeningSession{
117-
JoinId: &joinId,
128+
JoinId: joinId,
129+
Active: true,
118130
})
119131

120132
return existingListeningSession == nil
121133
}
122134

123135
func CloseSession(user model.SimpleUser, joinId string) *SpotifeteError {
124136
session := FindSimpleListeningSession(model.SimpleListeningSession{
125-
JoinId: &joinId,
137+
JoinId: joinId,
138+
Active: true,
126139
})
127140
if session == nil {
128141
return NewUserError("Unknown listening session.")
@@ -133,7 +146,6 @@ func CloseSession(user model.SimpleUser, joinId string) *SpotifeteError {
133146
}
134147

135148
session.Active = false
136-
session.JoinId = nil
137149
database.GetConnection().Save(&session)
138150
// TODO: Use a transaction here
139151

listeningSession/songRequest.go

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,10 @@
11
package listeningSession
22

33
import (
4+
"fmt"
45
"github.com/47-11/spotifete/database"
56
"github.com/47-11/spotifete/database/model"
6-
"github.com/47-11/spotifete/shared"
7+
. "github.com/47-11/spotifete/shared"
78
"github.com/zmb3/spotify"
89
"sort"
910
"time"
@@ -12,9 +13,13 @@ import (
1213
func FindSongRequest(filter model.SongRequest) *model.SongRequest {
1314
songRequests := FindSongRequests(filter)
1415

15-
if len(songRequests) == 1 {
16+
resultCount := len(songRequests)
17+
if resultCount == 1 {
1618
return &songRequests[0]
19+
} else if resultCount == 0 {
20+
return nil
1721
} else {
22+
NewInternalError(fmt.Sprintf("Got more than one result for filter %v", filter), nil)
1823
return nil
1924
}
2025
}
@@ -89,17 +94,17 @@ func GetDistinctRequestedTracks(session model.SimpleListeningSession) (trackIds
8994
return
9095
}
9196

92-
func DeleteRequestFromQueue(session model.SimpleListeningSession, spotifyTrackId string) *shared.SpotifeteError {
97+
func DeleteRequestFromQueue(session model.SimpleListeningSession, spotifyTrackId string) *SpotifeteError {
9398
requestToDelete := FindSongRequest(model.SongRequest{
9499
SessionId: session.ID,
95100
SpotifyTrackId: spotifyTrackId,
96101
})
97102
if requestToDelete == nil {
98-
return shared.NewUserError("Request not found in queue.")
103+
return NewUserError("Request not found in queue.")
99104
}
100105

101106
if requestToDelete.Status != model.StatusInQueue {
102-
return shared.NewUserError("The request must be in the queue to be deleted.")
107+
return NewUserError("The request must be in the queue to be deleted.")
103108
}
104109

105110
database.GetConnection().Delete(requestToDelete)

0 commit comments

Comments
 (0)