Skip to content

Commit

Permalink
fixes package imports
Browse files Browse the repository at this point in the history
  • Loading branch information
MartinGallauner committed Jul 1, 2024
1 parent 2a3643d commit 9654722
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 12 deletions.
14 changes: 7 additions & 7 deletions internal/client/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,29 +34,29 @@ const (
)

// Fetches a single book by it's ISBN from the OpenLibraryAPI
func (c *Client) FetchBook(isbn string) (Book, error) {
func (c *Client) FetchBook(isbn string) (internal.Book, error) {
url := baseURL + "books?jscmd=data&format=json&bibkeys=ISBN:" + isbn

req, err := http.NewRequest("GET", url, nil)
if err != nil {
return Book{}, err
return internal.Book{}, err
}

resp, err := c.httpClient.Do(req)
if err != nil {
return Book{}, err
return internal.Book{}, err
}
defer resp.Body.Close()

dat, err := io.ReadAll(resp.Body)
if err != nil {
return Book{}, err
return internal.Book{}, err
}

var response map[string]map[string]interface{}
err = json.Unmarshal(dat, &response)
if err != nil {
return Book{}, err
return internal.Book{}, err
}

book, err := mapBookResponse(response)
Expand All @@ -69,8 +69,8 @@ func (c *Client) FetchBook(isbn string) (Book, error) {

// mapBookResponse reads the ugly response from the OpenLibraryAPI and maps it to a simple book entity.
// TODO: clean that crap up
func mapBookResponse(response map[string]map[string]interface{}) (Book, error) {
var book Book
func mapBookResponse(response map[string]map[string]interface{}) (internal.Book, error) {
var book internal.Book
for isbn, bookData := range response {
book.URL = bookData["url"].(string)
book.ISBN = strings.TrimPrefix(isbn, "ISBN:")
Expand Down
4 changes: 2 additions & 2 deletions internal/server/collection_service.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ package server

import (
"github.com/martingallauner/bookclub/internal"
"github.com/martingallauner/bookclub/internal/client"
//"github.com/martingallauner/bookclub/internal/client"

)

Expand Down Expand Up @@ -67,4 +67,4 @@ func (cfg *BookclubServer) SearchBookInNetwork(userId uint, isbn string) ([]inte
type SearchRequest struct {
UserId uint `json:"user_id"`
ISBN string `json:"isbn"`
}
}
6 changes: 3 additions & 3 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ import (
"github.com/martingallauner/bookclub/internal/auth"
. "github.com/martingallauner/bookclub/internal/client"
repository "github.com/martingallauner/bookclub/internal/repository"
server "github.com/martingallauner/bookclub/internal/server"
bcServer "github.com/martingallauner/bookclub/internal/server"
"log"
"os"
"time"
Expand Down Expand Up @@ -34,14 +34,14 @@ func main() {
}
client := NewClient(5 * time.Second)

server := server.NewBookclubServer(
server := bcServer.NewBookclubServer(
client,
&repository.PostgresBookRepository{Database: db},
&repository.PostgresUserRepository{Database: db},
&repository.PostgresLinkRepository{Database: db},
&internal.GothicAuthService{},
&internal.JwtServiceImpl{})
err = server.StartServer(server)
err = bcServer.StartServer(server)
if err != nil {
log.Fatal(err)
}
Expand Down

0 comments on commit 9654722

Please sign in to comment.