-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor(app.domain.song): refine structure
- Loading branch information
Showing
10 changed files
with
146 additions
and
172 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 |
---|---|---|
@@ -1,2 +1,2 @@ | ||
github.com/linden-honey/linden-honey-sdk-go v0.1.0 h1:lE4AQK+LnMTW4s0B/LAsxwlridjpUvB0NG9vemBPOmY= | ||
github.com/linden-honey/linden-honey-sdk-go v0.1.0/go.mod h1:Of0QNaySkZignSgTMuIgKAM3OjffUsyoL8oekHKAw10= | ||
github.com/linden-honey/linden-honey-sdk-go v0.1.4 h1:W8OY56kRQ+Itakm8VH65p7RLh4/wCy4/Dq7i6sCAAkI= | ||
github.com/linden-honey/linden-honey-sdk-go v0.1.4/go.mod h1:Id4XBwvUN6dbbnkDmfRBTntkG6nYMT+z+eM6w2Sl+4Y= |
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 +1,5 @@ | ||
package song | ||
|
||
type GetQuoteResponse struct { | ||
Quote Quote `json:"quote"` | ||
} |
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 +1,13 @@ | ||
package song | ||
|
||
import ( | ||
sdkerrors "github.com/linden-honey/linden-honey-sdk-go/errors" | ||
) | ||
|
||
func (dto GetQuoteResponse) Validate() error { | ||
if err := dto.Quote.Validate(); err != nil { | ||
return sdkerrors.NewInvalidValueError("Quote", err) | ||
} | ||
|
||
return 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package song | ||
|
||
import ( | ||
"testing" | ||
) | ||
|
||
func TestGetQuoteResponse_Validate(t *testing.T) { | ||
type fields struct { | ||
Quote Quote | ||
} | ||
tests := []struct { | ||
name string | ||
fields fields | ||
wantErr bool | ||
}{ | ||
{ | ||
name: "ok", | ||
fields: fields{ | ||
Quote: "some quote", | ||
}, | ||
}, | ||
{ | ||
name: "err invalid quote", | ||
fields: fields{ | ||
Quote: "", | ||
}, | ||
wantErr: true, | ||
}, | ||
} | ||
for _, tt := range tests { | ||
t.Run(tt.name, func(t *testing.T) { | ||
dto := GetQuoteResponse{ | ||
Quote: tt.fields.Quote, | ||
} | ||
if err := dto.Validate(); (err != nil) != tt.wantErr { | ||
t.Errorf("GetQuoteResponse.Validate() error = %v, wantErr %v", err, tt.wantErr) | ||
} | ||
}) | ||
} | ||
} |
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,37 @@ | ||
package song | ||
|
||
import ( | ||
"errors" | ||
"math/rand" | ||
) | ||
|
||
// GetRandomVerse returns a random verse from lyrics or an error if there are no verses. | ||
func (l Lyrics) GetRandomVerse() (Verse, error) { | ||
versesCount := len(l) | ||
if versesCount == 0 { | ||
return nil, errors.New("no verses") | ||
} | ||
|
||
return l[rand.Intn(versesCount)], nil | ||
} | ||
|
||
// GetRandomQuote returns a random quote from lyrics or an error if there are no quotes. | ||
func (l Lyrics) GetRandomQuote() (Quote, error) { | ||
quotes := l.GetQuotes() | ||
quotesCount := len(quotes) | ||
if quotesCount == 0 { | ||
return "", errors.New("no quotes") | ||
} | ||
|
||
return quotes[rand.Intn(quotesCount)], nil | ||
} | ||
|
||
// GetQuotes returns all quotes from the song. | ||
func (l Lyrics) GetQuotes() []Quote { | ||
quotes := make([]Quote, 0) | ||
for _, v := range l { | ||
quotes = append(quotes, v...) | ||
} | ||
|
||
return quotes | ||
} |
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
Oops, something went wrong.