Moved "Publisher" to "PublisherID" and "PublisherFull" to "Publisher"
This commit is contained in:
parent
3aabf3b086
commit
82800240a2
|
@ -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
|
||||
}
|
||||
}
|
||||
},
|
||||
|
|
|
@ -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
|
||||
}
|
||||
|
|
|
@ -31,7 +31,7 @@
|
|||
<label v-lang.books.gridColumns.publisher></label>
|
||||
<a class="ui green icon button add-publisher-btn" @click="toggleAddPublisher()"><i class="plus icon"></i></a>
|
||||
<multiselect
|
||||
v-model="book.PublisherFull"
|
||||
v-model="book.Publisher"
|
||||
track-by="ID"
|
||||
label="Name"
|
||||
:placeholder="langGeneral.selectOne"
|
||||
|
@ -44,7 +44,7 @@
|
|||
<div class="field" v-if="addPublisherForm">
|
||||
<label v-lang.publishers.newPublisher></label>
|
||||
<a class="ui green icon button add-publisher-btn" @click="toggleAddPublisher()"><i class="list icon"></i></a>
|
||||
<input name="name" :placeholder="langPublishers.newPublisher" type="text" v-model="book.PublisherFull.Name" class="add-publisher">
|
||||
<input name="name" :placeholder="langPublishers.newPublisher" type="text" v-model="book.Publisher.Name" class="add-publisher">
|
||||
</div>
|
||||
|
||||
<div class="field">
|
||||
|
@ -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({
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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)
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue