Skip to content

Commit

Permalink
Add /switch command to query branches by name
Browse files Browse the repository at this point in the history
  • Loading branch information
kubegu committed Nov 25, 2023
1 parent 5cc4bbc commit 8afa145
Show file tree
Hide file tree
Showing 5 changed files with 68 additions and 2 deletions.
17 changes: 17 additions & 0 deletions bot/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package command

import (
"errors"
"fmt"
"strconv"
"strings"

Expand All @@ -15,6 +16,22 @@ type BotCommand struct {
Description string
}

// Listet alle verfügbaren Switch-Spiele in einer bestimmten Zweigstelle.
func ListSwitchCommand(ctx tele.Context) error {
client := libClient.Client{}
if len(ctx.Args()) < 1 {
return ctx.Reply("Bitte Zweigstelle angeben.")
}
branchArg := ctx.Args()[0]
branchCode, pres := libClient.GetBranchCode(branchArg)
if !pres {
return ctx.Reply(fmt.Sprintf("Zweigstelle %s existiert nicht.", branchArg))
}
games := client.FindAvailabelGames(branchCode, "switch")
reply := formatReply(games)
return ctx.Send(reply)
}

// Listet alle Videospiele einer bestimmten Platform die aktuell in einer Zweigstelle Ausleihbar sind.
func ListBranchPlattformCommand(ctx tele.Context) error {
client := libClient.Client{}
Expand Down
1 change: 1 addition & 0 deletions cmd/bot/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ func main() {

bot.Handle("/start", command.WelcomeCommand)
bot.Handle("/list", command.ListBranchPlattformCommand)
bot.Handle("/switch", command.ListSwitchCommand)

go setupHealthEndpoint()
log.Println("Bot Ready.")
Expand Down
28 changes: 28 additions & 0 deletions library-le/branches.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package libraryle

import "strings"

var branchNames = map[string]int{
"stadtbibliothek": 0,
"plagwitz": 20,
"wiederitzsch": 21,
"böhlitz": 22,
"lützschena": 23,
"holzhausen": 25,
"südvorstadt": 30,
"gholis": 41,
"volkmarsdorf": 50,
"schönefeld": 51,
"paunsdorf": 60,
"reudnitz": 61,
"mockau": 70,
"grünau-mitte": 82,
"grünau-nord": 83,
"grünau-süd": 84,
}

// Liefert den den BranchCode sofern existent.
func GetBranchCode(branchNameQuery string) (int, bool) {
branchCode, present := branchNames[strings.ToLower(branchNameQuery)]
return branchCode, present
}
20 changes: 20 additions & 0 deletions library-le/branches_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package libraryle

import (
"testing"

. "github.com/stretchr/testify/assert"
)

func TestGetBranchCodeSuccess(t *testing.T) {
branchNameQuery := "gholis"
result, present := GetBranchCode(branchNameQuery)
True(t, present)
Equal(t, result, 41)
}

func TestGetBranchCodeUnknown(t *testing.T) {
branchNameQuery := "blubb"
_, present := GetBranchCode(branchNameQuery)
False(t, present)
}
4 changes: 2 additions & 2 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ Weitere Parameter:
|- |- | - |
|CSId | USERSESSIONID | 1991N87S0583b9ce8380deec85603fd2da7803777dc9d087 |
|searchString | Schlüsselwort für die Suche | Nintendo+Switch |
|selectedViewBranchlib | Bibliothekszweigstelle für ??? | 0 (Stadtbibliothek) |
|selectedSearchBranchlib | Bibliothekszweigstelle für Abholung | 41 (Gohlis) |
|selectedViewBranchlib | Bibliothekszweigstelle für Suche | 41 |
|selectedSearchBranchlib | Bibliothekszweigstelle für Abholung | 41 |
|timeOut | Timeout der Suchanfrage in Sekunden | 20 |
|numberOfHits | Anzahl der Ergebnisse je Seite | 100 |

Expand Down

0 comments on commit 8afa145

Please sign in to comment.