From 82800240a22a16271c0ff76660507c6dc6e82043 Mon Sep 17 00:00:00 2001 From: kolaente Date: Tue, 28 Nov 2017 10:43:23 +0100 Subject: [PATCH] Moved "Publisher" to "PublisherID" and "PublisherFull" to "Publisher" --- frontend/src/components/BookOverview.vue | 4 ++-- frontend/src/components/Books.vue | 2 +- frontend/src/components/BooksAddEdit.vue | 8 ++++---- models/book.go | 26 ++++++++++++------------ models/books_add_update.go | 12 +++++------ models/books_list.go | 2 +- 6 files changed, 27 insertions(+), 27 deletions(-) diff --git a/frontend/src/components/BookOverview.vue b/frontend/src/components/BookOverview.vue index ff6c82f..196e75a 100644 --- a/frontend/src/components/BookOverview.vue +++ b/frontend/src/components/BookOverview.vue @@ -104,11 +104,11 @@ }, { header: this.translate('books').gridColumns.publisher, - content: this.book.PublisherFull.Name, + content: this.book.Publisher.Name, link: { name: 'publisher-show', params: { - id: this.book.PublisherFull.ID + id: this.book.Publisher.ID } } }, diff --git a/frontend/src/components/Books.vue b/frontend/src/components/Books.vue index 1a4f9e4..e6d7066 100644 --- a/frontend/src/components/Books.vue +++ b/frontend/src/components/Books.vue @@ -176,7 +176,7 @@ export default { Year: bs[b].Year, Price: bs[b].Price + '€', Author: '', - Publisher: bs[b].PublisherFull.Name, + Publisher: bs[b].Publisher.Name, Quantity: bs[b].Quantity, Status: bs[b].Status } diff --git a/frontend/src/components/BooksAddEdit.vue b/frontend/src/components/BooksAddEdit.vue index c704caf..d3c8612 100644 --- a/frontend/src/components/BooksAddEdit.vue +++ b/frontend/src/components/BooksAddEdit.vue @@ -31,7 +31,7 @@ - +
@@ -106,7 +106,7 @@ Price: 0, Status: 0, Quantity: 0, - PublisherFull: { + Publisher: { ID: 0, Name: '' }, @@ -212,7 +212,7 @@ }, toggleAddPublisher: function () { this.addPublisherForm = !this.addPublisherForm - this.book.PublisherFull = {ID: 0, Name: ''} + this.book.Publisher = {ID: 0, Name: ''} }, addAddAuthor: function () { this.addAuthorForm.push({ diff --git a/models/book.go b/models/book.go index 62a48dc..4790e6a 100644 --- a/models/book.go +++ b/models/book.go @@ -6,19 +6,19 @@ import ( // Book holds a book type Book struct { - ID int64 `xorm:"int(11) autoincr not null unique pk"` - Title string `xorm:"varchar(250) not null"` - Isbn string `xorm:"varchar(30)"` - Year int64 `xorm:"int(11)"` - Price float64 `xorm:"double"` - Status int64 `xorm:"int(11)"` - Publisher int64 `xorm:"int(11)"` - Created int64 `xorm:"created"` - Updated int64 `xorm:"updated"` + ID int64 `xorm:"int(11) autoincr not null unique pk"` + Title string `xorm:"varchar(250) not null"` + Isbn string `xorm:"varchar(30)"` + Year int64 `xorm:"int(11)"` + Price float64 `xorm:"double"` + Status int64 `xorm:"int(11)"` + PublisherID int64 `xorm:"int(11)"` + Created int64 `xorm:"created"` + Updated int64 `xorm:"updated"` - Quantity int64 `xorm:"-"` - PublisherFull Publisher `xorm:"-"` - Authors []Author `xorm:"-"` + Quantity int64 `xorm:"-"` + Publisher Publisher `xorm:"-"` + Authors []Author `xorm:"-"` } // TableName returns the name for the books table @@ -74,7 +74,7 @@ func GetBookByID(ID int64) (book Book, exists bool, err error) { } // Get publisher. We can't join it because xorm ignores the PublisherID option in struct - book.PublisherFull, _, err = GetPublisherByID(book.Publisher) + book.Publisher, _, err = GetPublisherByID(book.PublisherID) if err != nil { fmt.Println("Error getting publisher:", err) } diff --git a/models/books_add_update.go b/models/books_add_update.go index df797ff..0f70c5e 100644 --- a/models/books_add_update.go +++ b/models/books_add_update.go @@ -9,7 +9,7 @@ Erwatet ein Struct mit einem Buch. Wenn dieses Struct einen Publisher in Book.Publisher enthält und dieser existiert, wird diese ID verwendet. Wenn die ID nicht existiert oder 0 ist, wird geguckt, ob der Publisher unter -Book.PublisherFull bereits existtiert (über die ID), ist das nicht der Fall, wird er in +Book.Publisher bereits existtiert (über die ID), ist das nicht der Fall, wird er in die Datenbank eingetragen und mit dem Buch verknüpft. Bei den Autoren wird ebenfalls überprüft, ob sie bereits existieren, wenn dem nicht so ist werden @@ -27,11 +27,11 @@ func AddOrUpdateBook(book Book) (newBook Book, err error) { // Take Publisher, check if it exists. If not, insert it exists := false - publisherid := book.Publisher + publisherid := book.PublisherID if publisherid == 0 { - if book.PublisherFull.ID != 0 { - publisherid = book.PublisherFull.ID + if book.Publisher.ID != 0 { + publisherid = book.Publisher.ID } } @@ -41,12 +41,12 @@ func AddOrUpdateBook(book Book) (newBook Book, err error) { } if !exists { - newPublisher, err := AddOrUpdatePublisher(Publisher{Name: book.PublisherFull.Name}) + newPublisher, err := AddOrUpdatePublisher(Publisher{Name: book.Publisher.Name}) if err != nil { return Book{}, err } - book.Publisher = newPublisher.ID + book.PublisherID = newPublisher.ID } // Save the quantity for later use diff --git a/models/books_list.go b/models/books_list.go index 77c2714..9c4ab4b 100644 --- a/models/books_list.go +++ b/models/books_list.go @@ -35,7 +35,7 @@ func ListBooks(searchterm string) (books []*Book, err error) { } // Get publisher - books[i].PublisherFull, _, err = GetPublisherByID(book.Publisher) + books[i].Publisher, _, err = GetPublisherByID(book.PublisherID) if err != nil { fmt.Println("Error getting publisher:", err) }