refactors data access layer to use pop ORM for eager loading, adds book titles rented to renters in response body

This commit is contained in:
David Lick
2020-05-31 00:40:32 -04:00
parent a06b4d70ab
commit 28e52a4e08
29 changed files with 732 additions and 287 deletions
+19
View File
@@ -0,0 +1,19 @@
package models
import (
"time"
"github.com/gobuffalo/nulls"
"github.com/gobuffalo/uuid"
)
type Rental struct {
ID uuid.UUID `db:"id"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
BookTitle string `db:"book_title"`
RenterID uuid.UUID `db:"renter_id"`
RentalDate time.Time `db:"rental_date"`
ReturnDate nulls.Time `db:"return_date"`
Renter *Renter `belongs_to:"renter"`
}
+18
View File
@@ -0,0 +1,18 @@
package models
import (
"time"
"github.com/gobuffalo/uuid"
)
type Renter struct {
ID uuid.UUID `json:"id" db:"id"`
CreatedAt time.Time `json:"-" db:"created_at"`
UpdatedAt time.Time `json:"-" db:"updated_at"`
Name string `json:"name" db:"name"`
Address string `json:"address" db:"address"`
Email string `json:"email" db:"email"`
PhoneNumber string `json:"phoneNumber" db:"phone_number"`
Rentals []Rental `json:"rentals" has_many:"rentals"`
}