-
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.
- Loading branch information
kubegu
committed
Jan 31, 2024
1 parent
2d6a173
commit 0209750
Showing
9 changed files
with
85 additions
and
983 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 was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
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,3 @@ | ||
{{ range .Games }} | ||
<li class="list-group-item">{{ .Title }}</li> | ||
{{ end }} |
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,31 @@ | ||
<html> | ||
<head> | ||
<script src="https://unpkg.com/[email protected]" integrity="sha384-D1Kt99CQMDuVetoL1lrYwg5t+9QdHe7NLX/SoJYkXDFfX37iInKRy5xLSi8nO7UC" crossorigin="anonymous"></script> | ||
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"> | ||
</head> | ||
<body> | ||
<div class="mb-3"> | ||
<form hx-post="/game-index/" hx-target="#display-games"> | ||
<div class="mb-3"> | ||
<select name="branch" class="form-select"> | ||
<option>Stadtbibliothek</option> | ||
<option>Gohlis</option> | ||
</select> | ||
</div> | ||
<div class="mb-3"> | ||
<button type="submit" class="btn btn-primary">Los</button> | ||
</div> | ||
</form> | ||
<div class="card"> | ||
<div class="card-header"> | ||
Ausleihbare Spiele | ||
</div> | ||
<ul id="display-games" class="list-group list-group-flush"> | ||
|
||
</ul> | ||
</div> | ||
|
||
</div> | ||
|
||
</body> | ||
</html> |
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,46 @@ | ||
package main | ||
|
||
import ( | ||
"log" | ||
"net/http" | ||
"strings" | ||
"text/template" | ||
|
||
"github.com/gunni1/leipzig-library-game-stock-api/domain" | ||
libClient "github.com/gunni1/leipzig-library-game-stock-api/library-le" | ||
) | ||
|
||
const ( | ||
PLATFORM = "switch" | ||
) | ||
|
||
func indexHandler(respWriter http.ResponseWriter, request *http.Request) { | ||
templ := template.Must(template.ParseFiles("cmd/web/index.html")) | ||
|
||
templ.Execute(respWriter, nil) | ||
} | ||
|
||
func gameIndexHandler(respWriter http.ResponseWriter, request *http.Request) { | ||
log.Print("received htmx game-index") | ||
branch := strings.ToLower(request.PostFormValue("branch")) | ||
branchCode, exists := libClient.GetBranchCode(branch) | ||
if !exists { | ||
log.Printf("Requested branch: %s does not exists.", branch) | ||
return | ||
} | ||
client := libClient.Client{} | ||
games := client.FindAvailabelGames(branchCode, PLATFORM) | ||
data := map[string][]domain.Game{ | ||
"Games": games, | ||
} | ||
templ := template.Must(template.ParseFiles("cmd/web/games.html")) | ||
templ.Execute(respWriter, data) | ||
} | ||
|
||
func main() { | ||
mux := http.NewServeMux() | ||
|
||
mux.HandleFunc("/", indexHandler) | ||
mux.HandleFunc("/game-index/", gameIndexHandler) | ||
log.Fatal(http.ListenAndServe(":3000", mux)) | ||
} |
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.