Skip to content

Commit

Permalink
Determ return date (#12)
Browse files Browse the repository at this point in the history
#11 Determine return date for not available movies
  • Loading branch information
gunni1 authored Oct 4, 2024
1 parent 1eb89f4 commit 0e6e1c8
Show file tree
Hide file tree
Showing 16 changed files with 351 additions and 63 deletions.
6 changes: 0 additions & 6 deletions domain/game.go

This file was deleted.

23 changes: 21 additions & 2 deletions domain/media.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,26 @@
package domain

type Media struct {
const MOVIE string = "movie"
const GAME string = "game"

type Movie struct {
Title string `json:"title"`
Branch string `json:"branch"`
IsAvailable string `json:"isAvailable"`
}

//Platform als DVD/Bluray verwenden? -> Gleich zu behandeln, ggf vorteile bei geneuer Suche

type Game struct {
Title string `json:"title"`
Branch string `json:"branch"`
IsAvailable bool `json:"isAvailable"`
Platform string `json:"platform"`
IsAvailable string `json:"isAvailable"`
}

type Media struct {
Title string
Branch string
Platform string
IsAvailable bool
}
7 changes: 0 additions & 7 deletions domain/movie.go

This file was deleted.

1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ go 1.22

require (
github.com/PuerkitoBio/goquery v1.9.1
github.com/pkg/errors v0.9.1
github.com/stretchr/testify v1.9.0
)

Expand Down
2 changes: 2 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ github.com/andybalholm/cascadia v1.3.2 h1:3Xi6Dw5lHF15JtdcmAHD3i1+T8plmv7BQ/nsVi
github.com/andybalholm/cascadia v1.3.2/go.mod h1:7gtRlve5FxPPgIgX36uWBX58OdBsSS6lUvCFb+h7KvU=
github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c=
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/stretchr/testify v1.9.0 h1:HtqpIVDClZ4nwg75+f6Lvsy/wHu+3BoSGCbBAcpTsTg=
Expand Down
6 changes: 6 additions & 0 deletions library-le/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,12 @@ type webOpacSession struct {
userSessionId string
}

func NewClientWithSession() Client {
client := Client{}
client.openSession()
return client
}

func (client *Client) openSession() error {
resp, err := http.Get(LIB_BASE_URL + "/webOPACClient")
if err != nil {
Expand Down
54 changes: 44 additions & 10 deletions library-le/request.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,19 @@ func createRequest(libSession webOpacSession, path string) *http.Request {
return request
}

func NewMovieSearchRequest(searchString string, libSession webOpacSession) *http.Request {
func NewReturnDateRequest(title string, platform string, branchCode int, libSession webOpacSession) *http.Request {
request := createRequest(libSession, "/webOPACClient/search.do")
request.URL.RawQuery = createMovieSearchQuery(*request, searchString, libSession.userSessionId)
if platform == "dvd" || platform == "bluray" {
request.URL.RawQuery = createSinglePlatformMovieSearchQuery(*request, title, platform, branchCode, libSession.userSessionId)
} else {
request.URL.RawQuery = createGameSearchQuery(*request, title, platform, branchCode, libSession.userSessionId)
}
return request
}

func NewMovieSearchRequest(title string, branchCode int, libSession webOpacSession) *http.Request {
request := createRequest(libSession, "/webOPACClient/search.do")
request.URL.RawQuery = createMovieSearchQuery(*request, title, branchCode, libSession.userSessionId)
return request
}

Expand All @@ -32,13 +42,13 @@ func NewGameIndexRequest(branchCode int, platform string, libSession webOpacSess
return request
}

func NewGameSearchRequest(title string, platform string, libSession webOpacSession) *http.Request {
func NewGameSearchRequest(title string, platform string, branchCode int, libSession webOpacSession) *http.Request {
request := createRequest(libSession, "/webOPACClient/search.do")
request.URL.RawQuery = createGameSearchQuery(*request, title, platform, libSession.userSessionId)
request.URL.RawQuery = createGameSearchQuery(*request, title, platform, branchCode, libSession.userSessionId)
return request
}

func createGameSearchQuery(request http.Request, title string, platform string, userSessionId string) string {
func createGameSearchQuery(request http.Request, title string, platform string, branchCode int, userSessionId string) string {
query := request.URL.Query()
query.Add("methodToCall", "submit")
query.Add("methodToCallParameter", "submitSearch")
Expand All @@ -47,8 +57,8 @@ func createGameSearchQuery(request http.Request, title string, platform string,
query.Add("numberOfHits", "500")
query.Add("timeOut", "20")
query.Add("CSId", userSessionId)
//Search for Stadtbibliothek, collect actual branch information un further requests
query.Add("selectedViewBranchlib", strconv.FormatInt(int64(0), 10))
query.Add("selectedSearchBranchlib", strconv.FormatInt(int64(branchCode), 10))
query.Add("selectedViewBranchlib", strconv.FormatInt(int64(branchCode), 10))
//Search for category title
query.Add("searchString[0]", title)
query.Add("searchCategories[0]", "331")
Expand All @@ -61,7 +71,30 @@ func createGameSearchQuery(request http.Request, title string, platform string,
return query.Encode()
}

func createMovieSearchQuery(request http.Request, searchString string, userSessionId string) string {
func createSinglePlatformMovieSearchQuery(request http.Request, title string, platform string, branchCode int, userSessionId string) string {
query := request.URL.Query()
query.Add("methodToCall", "submit")
query.Add("methodToCallParameter", "submitSearch")
query.Add("submitSearch", "Suchen")
query.Add("callingPage", "searchPreferences")
query.Add("numberOfHits", "500")
query.Add("timeOut", "20")
query.Add("CSId", userSessionId)
query.Add("selectedSearchBranchlib", strconv.FormatInt(int64(branchCode), 10))
query.Add("selectedViewBranchlib", strconv.FormatInt(int64(branchCode), 10))
//Search for category title
query.Add("searchString[0]", title)
query.Add("searchCategories[0]", "331")
//Search for one specific mediatype dvd or bluray
query.Add("searchString[1]", platform)
query.Add("searchCategories[1]", "800")
//Restrict search to dvd/bluray
query.Add("searchRestrictionID[2]", "3")
query.Add("searchRestrictionValue1[2]", "29")
return query.Encode()
}

func createMovieSearchQuery(request http.Request, title string, branchCode int, userSessionId string) string {
query := request.URL.Query()
query.Add("methodToCall", "submit")
query.Add("methodToCallParameter", "submitSearch")
Expand All @@ -71,8 +104,9 @@ func createMovieSearchQuery(request http.Request, searchString string, userSessi
query.Add("numberOfHits", "500")
query.Add("timeOut", "20")
query.Add("CSId", userSessionId)
query.Add("searchString[0]", searchString)
query.Add("selectedViewBranchlib", strconv.FormatInt(int64(0), 10))
query.Add("searchString[0]", title)
query.Add("selectedSearchBranchlib", strconv.FormatInt(int64(branchCode), 10))
query.Add("selectedViewBranchlib", strconv.FormatInt(int64(branchCode), 10))
//Search for category title
query.Add("searchCategories[0]", "331")
//Restrict search to dvd/bluray
Expand Down
24 changes: 21 additions & 3 deletions library-le/request_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,18 +8,36 @@ import (

func TestMovieSearchRequestHasCookiesSet(t *testing.T) {
session := webOpacSession{jSessionId: jSessionId, userSessionId: userSessionId}
request := NewMovieSearchRequest("Terminator", session)
request := NewMovieSearchRequest("Terminator", 0, session)
assertSessionCookiesExists(request, t)
}

func TestMovieSearchRequestHasQueryParamsSet(t *testing.T) {
session := webOpacSession{jSessionId: jSessionId, userSessionId: userSessionId}
request := NewMovieSearchRequest("Terminator", session)
request := NewMovieSearchRequest("Terminator", 0, session)
Equal(t, "submit", request.URL.Query().Get("methodToCall"))
Equal(t, "331", request.URL.Query().Get("searchCategories[0]"))
Equal(t, "500", request.URL.Query().Get("numberOfHits"))
Equal(t, "3", request.URL.Query().Get("searchRestrictionID[2]"))
Equal(t, "29", request.URL.Query().Get("searchRestrictionValue1[2]"))
Equal(t, "0", request.URL.Query().Get("selectedViewBranchlib"))
Empty(t, request.URL.Query().Get("selectedSearchBranchlib"))
Equal(t, "0", request.URL.Query().Get("selectedSearchBranchlib"))
}

func TestMovieReturnDateRequest(t *testing.T) {
session := webOpacSession{jSessionId: jSessionId, userSessionId: userSessionId}
request := NewReturnDateRequest("Terminator", "dvd", 41, session)
//Expect results to be restricted to dvd/bluray
Equal(t, "29", request.URL.Query().Get("searchRestrictionValue1[2]"))
Equal(t, "dvd", request.URL.Query().Get("searchString[1]"))
Equal(t, "800", request.URL.Query().Get("searchCategories[1]"))
}

func TestGameReturnDateRequest(t *testing.T) {
session := webOpacSession{jSessionId: jSessionId, userSessionId: userSessionId}
request := NewReturnDateRequest("Mario", "switch", 41, session)
//Expect results to be restricted to games
Equal(t, "27", request.URL.Query().Get("searchRestrictionValue1[2]"))
Equal(t, "switch", request.URL.Query().Get("searchString[1]"))
Equal(t, "902", request.URL.Query().Get("searchCategories[1]"))
}
Loading

0 comments on commit 0e6e1c8

Please sign in to comment.