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,
|
header: this.translate('books').gridColumns.publisher,
|
||||||
content: this.book.PublisherFull.Name,
|
content: this.book.Publisher.Name,
|
||||||
link: {
|
link: {
|
||||||
name: 'publisher-show',
|
name: 'publisher-show',
|
||||||
params: {
|
params: {
|
||||||
id: this.book.PublisherFull.ID
|
id: this.book.Publisher.ID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|
|
@ -176,7 +176,7 @@ export default {
|
||||||
Year: bs[b].Year,
|
Year: bs[b].Year,
|
||||||
Price: bs[b].Price + '€',
|
Price: bs[b].Price + '€',
|
||||||
Author: '',
|
Author: '',
|
||||||
Publisher: bs[b].PublisherFull.Name,
|
Publisher: bs[b].Publisher.Name,
|
||||||
Quantity: bs[b].Quantity,
|
Quantity: bs[b].Quantity,
|
||||||
Status: bs[b].Status
|
Status: bs[b].Status
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,7 +31,7 @@
|
||||||
<label v-lang.books.gridColumns.publisher></label>
|
<label v-lang.books.gridColumns.publisher></label>
|
||||||
<a class="ui green icon button add-publisher-btn" @click="toggleAddPublisher()"><i class="plus icon"></i></a>
|
<a class="ui green icon button add-publisher-btn" @click="toggleAddPublisher()"><i class="plus icon"></i></a>
|
||||||
<multiselect
|
<multiselect
|
||||||
v-model="book.PublisherFull"
|
v-model="book.Publisher"
|
||||||
track-by="ID"
|
track-by="ID"
|
||||||
label="Name"
|
label="Name"
|
||||||
:placeholder="langGeneral.selectOne"
|
:placeholder="langGeneral.selectOne"
|
||||||
|
@ -44,7 +44,7 @@
|
||||||
<div class="field" v-if="addPublisherForm">
|
<div class="field" v-if="addPublisherForm">
|
||||||
<label v-lang.publishers.newPublisher></label>
|
<label v-lang.publishers.newPublisher></label>
|
||||||
<a class="ui green icon button add-publisher-btn" @click="toggleAddPublisher()"><i class="list icon"></i></a>
|
<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>
|
||||||
|
|
||||||
<div class="field">
|
<div class="field">
|
||||||
|
@ -106,7 +106,7 @@
|
||||||
Price: 0,
|
Price: 0,
|
||||||
Status: 0,
|
Status: 0,
|
||||||
Quantity: 0,
|
Quantity: 0,
|
||||||
PublisherFull: {
|
Publisher: {
|
||||||
ID: 0,
|
ID: 0,
|
||||||
Name: ''
|
Name: ''
|
||||||
},
|
},
|
||||||
|
@ -212,7 +212,7 @@
|
||||||
},
|
},
|
||||||
toggleAddPublisher: function () {
|
toggleAddPublisher: function () {
|
||||||
this.addPublisherForm = !this.addPublisherForm
|
this.addPublisherForm = !this.addPublisherForm
|
||||||
this.book.PublisherFull = {ID: 0, Name: ''}
|
this.book.Publisher = {ID: 0, Name: ''}
|
||||||
},
|
},
|
||||||
addAddAuthor: function () {
|
addAddAuthor: function () {
|
||||||
this.addAuthorForm.push({
|
this.addAuthorForm.push({
|
||||||
|
|
|
@ -6,19 +6,19 @@ import (
|
||||||
|
|
||||||
// Book holds a book
|
// Book holds a book
|
||||||
type Book struct {
|
type Book struct {
|
||||||
ID int64 `xorm:"int(11) autoincr not null unique pk"`
|
ID int64 `xorm:"int(11) autoincr not null unique pk"`
|
||||||
Title string `xorm:"varchar(250) not null"`
|
Title string `xorm:"varchar(250) not null"`
|
||||||
Isbn string `xorm:"varchar(30)"`
|
Isbn string `xorm:"varchar(30)"`
|
||||||
Year int64 `xorm:"int(11)"`
|
Year int64 `xorm:"int(11)"`
|
||||||
Price float64 `xorm:"double"`
|
Price float64 `xorm:"double"`
|
||||||
Status int64 `xorm:"int(11)"`
|
Status int64 `xorm:"int(11)"`
|
||||||
Publisher int64 `xorm:"int(11)"`
|
PublisherID int64 `xorm:"int(11)"`
|
||||||
Created int64 `xorm:"created"`
|
Created int64 `xorm:"created"`
|
||||||
Updated int64 `xorm:"updated"`
|
Updated int64 `xorm:"updated"`
|
||||||
|
|
||||||
Quantity int64 `xorm:"-"`
|
Quantity int64 `xorm:"-"`
|
||||||
PublisherFull Publisher `xorm:"-"`
|
Publisher Publisher `xorm:"-"`
|
||||||
Authors []Author `xorm:"-"`
|
Authors []Author `xorm:"-"`
|
||||||
}
|
}
|
||||||
|
|
||||||
// TableName returns the name for the books table
|
// 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
|
// 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 {
|
if err != nil {
|
||||||
fmt.Println("Error getting publisher:", err)
|
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
|
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
|
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.
|
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
|
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
|
// Take Publisher, check if it exists. If not, insert it
|
||||||
exists := false
|
exists := false
|
||||||
publisherid := book.Publisher
|
publisherid := book.PublisherID
|
||||||
|
|
||||||
if publisherid == 0 {
|
if publisherid == 0 {
|
||||||
if book.PublisherFull.ID != 0 {
|
if book.Publisher.ID != 0 {
|
||||||
publisherid = book.PublisherFull.ID
|
publisherid = book.Publisher.ID
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -41,12 +41,12 @@ func AddOrUpdateBook(book Book) (newBook Book, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
if !exists {
|
if !exists {
|
||||||
newPublisher, err := AddOrUpdatePublisher(Publisher{Name: book.PublisherFull.Name})
|
newPublisher, err := AddOrUpdatePublisher(Publisher{Name: book.Publisher.Name})
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return Book{}, err
|
return Book{}, err
|
||||||
}
|
}
|
||||||
|
|
||||||
book.Publisher = newPublisher.ID
|
book.PublisherID = newPublisher.ID
|
||||||
}
|
}
|
||||||
|
|
||||||
// Save the quantity for later use
|
// Save the quantity for later use
|
||||||
|
|
|
@ -35,7 +35,7 @@ func ListBooks(searchterm string) (books []*Book, err error) {
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get publisher
|
// Get publisher
|
||||||
books[i].PublisherFull, _, err = GetPublisherByID(book.Publisher)
|
books[i].Publisher, _, err = GetPublisherByID(book.PublisherID)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
fmt.Println("Error getting publisher:", err)
|
fmt.Println("Error getting publisher:", err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue