diff --git a/main.go b/main.go index ee44798..518159f 100644 --- a/main.go +++ b/main.go @@ -1,13 +1,13 @@ package main import ( - "git.mowie.cc/konrad/Library/routes" "git.mowie.cc/konrad/Library/models" + "git.mowie.cc/konrad/Library/routes" "fmt" ) -func main(){ +func main() { // Set Engine err := models.SetEngine() diff --git a/models/author.go b/models/author.go index 35c6088..20eb023 100644 --- a/models/author.go +++ b/models/author.go @@ -1,11 +1,11 @@ package models type Author struct { - ID int64 `xorm:"int(11) autoincr not null unique pk"` + ID int64 `xorm:"int(11) autoincr not null unique pk"` Forename string `xorm:"varchar(250)"` Lastname string `xorm:"varchar(250) not null"` - Created int64 `xorm:"created"` - Updated int64 `xorm:"updated"` + Created int64 `xorm:"created"` + Updated int64 `xorm:"updated"` } func (Author) TableName() string { @@ -13,9 +13,9 @@ func (Author) TableName() string { } type AuthorBook struct { - ID int64 `xorm:"int(11) autoincr not null unique pk"` + ID int64 `xorm:"int(11) autoincr not null unique pk"` AuthorID int64 `xorm:"int(11)"` - BookID int64 `xorm:"int(11)"` + BookID int64 `xorm:"int(11)"` Created int64 `xorm:"created"` Updated int64 `xorm:"updated"` @@ -29,4 +29,4 @@ func GetAuthorByID(id int64) (author Author, exists bool, err error) { has, err := x.Id(id).Get(&author) return author, has, err -} \ No newline at end of file +} diff --git a/models/authors_add.go b/models/authors_add.go index 2330196..821c4ea 100644 --- a/models/authors_add.go +++ b/models/authors_add.go @@ -1,6 +1,6 @@ package models -func AddAuthor(author Author) (newAuthor Author, err error){ +func AddAuthor(author Author) (newAuthor Author, err error) { _, err = x.Insert(&author) if err != nil { @@ -11,4 +11,4 @@ func AddAuthor(author Author) (newAuthor Author, err error){ newAuthor, _, err = GetAuthorByID(author.ID) return newAuthor, err -} \ No newline at end of file +} diff --git a/models/authors_delete.go b/models/authors_delete.go index 8b35d7f..f111632 100644 --- a/models/authors_delete.go +++ b/models/authors_delete.go @@ -1,6 +1,6 @@ package models -func DeleteAuthorByID(id int64) error { +func DeleteAuthorByID(id int64) error { // Delete the author _, err := x.Id(id).Delete(&Author{}) @@ -9,7 +9,7 @@ func DeleteAuthorByID(id int64) error { } // Delete all book relations associated with that author - _, err = x.Delete(&AuthorBook{AuthorID:id}) + _, err = x.Delete(&AuthorBook{AuthorID: id}) return err -} \ No newline at end of file +} diff --git a/models/authors_list.go b/models/authors_list.go index 8d8ef85..135a409 100644 --- a/models/authors_list.go +++ b/models/authors_list.go @@ -1,13 +1,12 @@ package models - func ListAuthors(searchterm string) (authors []Author, err error) { if searchterm == "" { err = x.Find(&authors) } else { err = x. - Where("forename LIKE ?", "%"+searchterm+"%"). + Where("forename LIKE ?", "%"+searchterm+"%"). Or("lastname LIKE ?", "%"+searchterm+"%"). Find(&authors) } @@ -16,4 +15,4 @@ func ListAuthors(searchterm string) (authors []Author, err error) { } return authors, nil -} \ No newline at end of file +} diff --git a/models/authors_update.go b/models/authors_update.go index 3679e5f..bb88e95 100644 --- a/models/authors_update.go +++ b/models/authors_update.go @@ -1,6 +1,6 @@ package models -func UpdateAuthor(author Author, id int64) (newAuthor Author, err error){ +func UpdateAuthor(author Author, id int64) (newAuthor Author, err error) { _, err = x.Where("id = ?", id).Update(&author) if err != nil { @@ -11,4 +11,4 @@ func UpdateAuthor(author Author, id int64) (newAuthor Author, err error){ newAuthor, _, err = GetAuthorByID(id) return newAuthor, err -} \ No newline at end of file +} diff --git a/models/book.go b/models/book.go index 5efff10..f4e7402 100644 --- a/models/book.go +++ b/models/book.go @@ -3,25 +3,25 @@ package models import "fmt" 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)"` + Publisher int64 `xorm:"int(11)"` + Created int64 `xorm:"created"` + Updated int64 `xorm:"updated"` PublisherFull Publisher `xorm:"-"` - Authors []Author `xorm:"-"` + Authors []Author `xorm:"-"` } -func (Book) TableName() string{ +func (Book) TableName() string { return "books" } -func GetBookById(ID int64) (book Book, exists bool, err error) { +func GetBookById(ID int64) (book Book, exists bool, err error) { // Get the Book has, err := x.ID(ID).Get(&book) @@ -36,7 +36,7 @@ func GetBookById(ID int64) (book Book, exists bool, err error) { // Get all authors var authors []Author err = x. - Table("authors_books"). + Table("authors_books"). Select("authors.*"). Join("INNER", "authors", "authors_books.author_id = authors.id"). Where("book_id = ?", book.ID). @@ -49,4 +49,4 @@ func GetBookById(ID int64) (book Book, exists bool, err error) { book.Authors = authors return book, has, err -} \ No newline at end of file +} diff --git a/models/books_add.go b/models/books_add.go index 081911c..6841760 100644 --- a/models/books_add.go +++ b/models/books_add.go @@ -13,7 +13,7 @@ die Datenbank eingetragen und mit dem Buch verknüpft. Bei den Autoren wirdebenfalls überprüft, ob sie bereits existieren, wenn dem nicht so ist werden sie in die Datenbank eingetragen und mit dem Buch verknüpft. - */ +*/ func AddBook(book Book) (newBook Book, err error) { diff --git a/models/books_delete.go b/models/books_delete.go index 3f437bd..bcd2636 100644 --- a/models/books_delete.go +++ b/models/books_delete.go @@ -1,6 +1,6 @@ package models -func DeleteBookByID(id int64) error { +func DeleteBookByID(id int64) error { // Delete the book _, err := x.Id(id).Delete(&Book{}) @@ -9,7 +9,7 @@ func DeleteBookByID(id int64) error { } // Delete all authors associated with that book - _, err = x.Delete(&AuthorBook{BookID:id}) + _, err = x.Delete(&AuthorBook{BookID: id}) return err -} \ No newline at end of file +} diff --git a/models/books_list.go b/models/books_list.go index cf4522d..93c8ac4 100644 --- a/models/books_list.go +++ b/models/books_list.go @@ -3,7 +3,7 @@ package models import "fmt" type BookPublisher struct { - Book `xorm:"extends"` + Book `xorm:"extends"` Publisher `xorm:"extends"` } @@ -11,19 +11,18 @@ func ListBooks(searchterm string) (books []*Book, err error) { if searchterm == "" { err = x.Table("books"). - //Join("INNER", "publishers", "books.publisher = publishers.id"). + //Join("INNER", "publishers", "books.publisher = publishers.id"). Find(&books) if err != nil { fmt.Println("Error getting Books", err) } } else { - err = x.Where("title LIKE ?", "%" + searchterm + "%").Find(&books) + err = x.Where("title LIKE ?", "%"+searchterm+"%").Find(&books) if err != nil { fmt.Println("Error getting Books", err) } } - // Get all authors and publishers for i, book := range books { @@ -38,7 +37,7 @@ func ListBooks(searchterm string) (books []*Book, err error) { // Get all authors var authors []Author err = x. - Table("authors_books"). + Table("authors_books"). Join("INNER", "authors", "authors_books.author_id = authors.id"). Where("book_id = ?", book.ID). Find(&authors) diff --git a/models/config.go b/models/config.go index bedbab4..cb04ee7 100644 --- a/models/config.go +++ b/models/config.go @@ -5,10 +5,10 @@ import ( "os" ) -var Config struct{ - Database struct{ - Host string - User string +var Config struct { + Database struct { + Host string + User string Password string Database string } @@ -16,7 +16,7 @@ var Config struct{ JWTLoginSecret []byte } -func SetConfig() error{ +func SetConfig() error { // File Checks if _, err := os.Stat("config.ini"); os.IsNotExist(err) { @@ -35,4 +35,4 @@ func SetConfig() error{ Config.JWTLoginSecret = []byte(cfg.Section("General").Key("JWTSecret").String()) return nil -} \ No newline at end of file +} diff --git a/models/message.go b/models/message.go index 978258f..19d028e 100644 --- a/models/message.go +++ b/models/message.go @@ -1,5 +1,5 @@ package models -type Message struct{ +type Message struct { Message string -} \ No newline at end of file +} diff --git a/models/models.go b/models/models.go index 8a0dcaa..6e74a0f 100644 --- a/models/models.go +++ b/models/models.go @@ -1,21 +1,20 @@ package models import ( - "github.com/go-xorm/core" - _ "github.com/go-sql-driver/mysql" - "github.com/go-xorm/xorm" "fmt" + _ "github.com/go-sql-driver/mysql" + "github.com/go-xorm/core" + "github.com/go-xorm/xorm" ) var x *xorm.Engine -func getEngine() (*xorm.Engine, error){ +func getEngine() (*xorm.Engine, error) { connStr := fmt.Sprintf("%s:%s@tcp(%s)/%s?charset=utf8&parseTime=true", "root", "jup2000", "127.0.0.1", "library2") return xorm.NewEngine("mysql", connStr) } - // SetEngine sets the xorm.Engine func SetEngine() (err error) { x, err = getEngine() diff --git a/models/publisher.go b/models/publisher.go index a385f38..d294b39 100644 --- a/models/publisher.go +++ b/models/publisher.go @@ -1,10 +1,10 @@ package models type Publisher struct { - ID int64 `xorm:"int(11) autoincr not null unique pk"` - Name string `xorm:"varchar(250) not null"` - Created int64 `xorm:"created"` - Updated int64 `xorm:"updated"` + ID int64 `xorm:"int(11) autoincr not null unique pk"` + Name string `xorm:"varchar(250) not null"` + Created int64 `xorm:"created"` + Updated int64 `xorm:"updated"` } func (Publisher) TableName() string { @@ -15,4 +15,4 @@ func GetPublisherByID(id int64) (publisher Publisher, exists bool, err error) { has, err := x.Id(id).Get(&publisher) return publisher, has, err -} \ No newline at end of file +} diff --git a/models/publishers_add.go b/models/publishers_add.go index dcf54de..1a5f263 100644 --- a/models/publishers_add.go +++ b/models/publishers_add.go @@ -1,6 +1,6 @@ package models -func AddPublisher(publisher Publisher) (newPublisher Publisher, err error){ +func AddPublisher(publisher Publisher) (newPublisher Publisher, err error) { _, err = x.Insert(&publisher) if err != nil { @@ -10,4 +10,4 @@ func AddPublisher(publisher Publisher) (newPublisher Publisher, err error){ newPublisher, _, err = GetPublisherByID(publisher.ID) return newPublisher, err -} \ No newline at end of file +} diff --git a/models/publishers_delete.go b/models/publishers_delete.go index 3e027a1..e0859ea 100644 --- a/models/publishers_delete.go +++ b/models/publishers_delete.go @@ -1,6 +1,6 @@ package models -func DeletePublisherByID(id int64) error { +func DeletePublisherByID(id int64) error { // Delete the publisher _, err := x.Id(id).Delete(&Publisher{}) @@ -12,8 +12,7 @@ func DeletePublisherByID(id int64) error { //book := Book{Publisher:0} //book.Publisher = 0 //_, err = x.Where("publisher = ?", id).Update(book) - _, err = x.Table("books").Where("publisher = ?", id).Update(map[string]interface{}{"publisher":0}) - + _, err = x.Table("books").Where("publisher = ?", id).Update(map[string]interface{}{"publisher": 0}) return err -} \ No newline at end of file +} diff --git a/models/publishers_list.go b/models/publishers_list.go index 77f6197..f67ce41 100644 --- a/models/publishers_list.go +++ b/models/publishers_list.go @@ -6,7 +6,7 @@ func ListPublishers(searchterm string) (publishers []Publisher, err error) { err = x.Find(&publishers) } else { err = x. - Where("name LIKE ?", "%" + searchterm + "%"). + Where("name LIKE ?", "%"+searchterm+"%"). Find(&publishers) } @@ -15,4 +15,4 @@ func ListPublishers(searchterm string) (publishers []Publisher, err error) { } return publishers, nil -} \ No newline at end of file +} diff --git a/models/publishers_update.go b/models/publishers_update.go index fd5fb7f..d3e94cc 100644 --- a/models/publishers_update.go +++ b/models/publishers_update.go @@ -1,6 +1,6 @@ package models -func UpdatePublisher(publisher Publisher, id int64) (newPublisher Publisher, err error){ +func UpdatePublisher(publisher Publisher, id int64) (newPublisher Publisher, err error) { _, err = x.Where("id = ?", id).Update(&publisher) if err != nil { @@ -11,4 +11,4 @@ func UpdatePublisher(publisher Publisher, id int64) (newPublisher Publisher, err newPublisher, _, err = GetPublisherByID(id) return newPublisher, err -} \ No newline at end of file +} diff --git a/models/user.go b/models/user.go index 19dcff0..fe93c0a 100644 --- a/models/user.go +++ b/models/user.go @@ -1,18 +1,18 @@ package models import ( - "golang.org/x/crypto/bcrypt" "fmt" + "golang.org/x/crypto/bcrypt" ) type User struct { - ID int64 `xorm:"int(11) autoincr not null unique pk"` - Name string `xorm:"varchar(250)"` + ID int64 `xorm:"int(11) autoincr not null unique pk"` + Name string `xorm:"varchar(250)"` Username string `xorm:"varchar(250) not null"` Password string `xorm:"varchar(250) not null"` - Email string `xorm:"varchar(250) not null"` - Created int64 `xorm:"created"` - Updated int64 `xorm:"updated"` + Email string `xorm:"varchar(250) not null"` + Created int64 `xorm:"created"` + Updated int64 `xorm:"updated"` } func (User) TableName() string { @@ -26,10 +26,10 @@ func HashPassword(password string) (string, error) { } // Check user credentials -func CheckUserCredentials (username, password string) (User, error) { +func CheckUserCredentials(username, password string) (User, error) { // Check if the user exists - var user = User{Username:username} + var user = User{Username: username} exists, err := x.Get(&user) if err != nil { return User{}, err @@ -47,4 +47,4 @@ func CheckUserCredentials (username, password string) (User, error) { } return user, nil -} \ No newline at end of file +} diff --git a/routes/api/v1/author_delete.go b/routes/api/v1/author_delete.go index 2e9b633..cc19c1b 100644 --- a/routes/api/v1/author_delete.go +++ b/routes/api/v1/author_delete.go @@ -1,10 +1,10 @@ package v1 import ( - "github.com/labstack/echo" - "strconv" - "net/http" "git.mowie.cc/konrad/Library/models" + "github.com/labstack/echo" + "net/http" + "strconv" ) func AuthorDelete(c echo.Context) error { @@ -37,4 +37,4 @@ func AuthorDelete(c echo.Context) error { } return c.JSON(http.StatusOK, models.Message{"success"}) -} \ No newline at end of file +} diff --git a/routes/api/v1/author_show.go b/routes/api/v1/author_show.go index 96cfb75..52ab13e 100644 --- a/routes/api/v1/author_show.go +++ b/routes/api/v1/author_show.go @@ -1,9 +1,9 @@ package v1 import ( + "git.mowie.cc/konrad/Library/models" "github.com/labstack/echo" "net/http" - "git.mowie.cc/konrad/Library/models" "strconv" ) diff --git a/routes/api/v1/authors_add.go b/routes/api/v1/authors_add.go index ef709f6..dc60a80 100644 --- a/routes/api/v1/authors_add.go +++ b/routes/api/v1/authors_add.go @@ -1,10 +1,10 @@ package v1 import ( + "encoding/json" + "git.mowie.cc/konrad/Library/models" "github.com/labstack/echo" "net/http" - "git.mowie.cc/konrad/Library/models" - "encoding/json" "strings" ) diff --git a/routes/api/v1/authors_list.go b/routes/api/v1/authors_list.go index 46f5755..e3b7248 100644 --- a/routes/api/v1/authors_list.go +++ b/routes/api/v1/authors_list.go @@ -1,18 +1,18 @@ package v1 import ( + "git.mowie.cc/konrad/Library/models" "github.com/labstack/echo" "net/http" - "git.mowie.cc/konrad/Library/models" ) func AuthorsList(c echo.Context) error { list, err := models.ListAuthors("") - if err != nil{ + if err != nil { return c.JSON(http.StatusInternalServerError, models.Message{"Error getting authors"}) } return c.JSON(http.StatusOK, list) -} \ No newline at end of file +} diff --git a/routes/api/v1/authors_search.go b/routes/api/v1/authors_search.go index 1aacf1b..a558ecb 100644 --- a/routes/api/v1/authors_search.go +++ b/routes/api/v1/authors_search.go @@ -19,14 +19,14 @@ func AuthorSearch(c echo.Context) error { // Get the Authors list, err := models.ListAuthors(search) - if err != nil{ + if err != nil { return c.JSON(http.StatusInternalServerError, models.Message{"Error getting authors"}) } // Check if we have any results - if len(list) == 0{ + if len(list) == 0 { return c.JSON(http.StatusNotFound, models.Message{"Couldn't find any authors matching your search term"}) } return c.JSON(http.StatusOK, list) -} \ No newline at end of file +} diff --git a/routes/api/v1/authors_update.go b/routes/api/v1/authors_update.go index dacfae1..d00c4d4 100644 --- a/routes/api/v1/authors_update.go +++ b/routes/api/v1/authors_update.go @@ -1,12 +1,12 @@ package v1 import ( + "encoding/json" + "git.mowie.cc/konrad/Library/models" "github.com/labstack/echo" "net/http" - "git.mowie.cc/konrad/Library/models" - "encoding/json" - "strings" "strconv" + "strings" ) func AuthorUpdate(c echo.Context) error { diff --git a/routes/api/v1/book_delete.go b/routes/api/v1/book_delete.go index cfd7a69..c3239e7 100644 --- a/routes/api/v1/book_delete.go +++ b/routes/api/v1/book_delete.go @@ -1,10 +1,10 @@ package v1 import ( - "github.com/labstack/echo" - "strconv" - "net/http" "git.mowie.cc/konrad/Library/models" + "github.com/labstack/echo" + "net/http" + "strconv" ) func BookDelete(c echo.Context) error { @@ -37,4 +37,4 @@ func BookDelete(c echo.Context) error { } return c.JSON(http.StatusOK, models.Message{"success"}) -} \ No newline at end of file +} diff --git a/routes/api/v1/book_show.go b/routes/api/v1/book_show.go index 9c16fc9..8efaced 100644 --- a/routes/api/v1/book_show.go +++ b/routes/api/v1/book_show.go @@ -1,9 +1,9 @@ package v1 import ( + "git.mowie.cc/konrad/Library/models" "github.com/labstack/echo" "net/http" - "git.mowie.cc/konrad/Library/models" "strconv" ) @@ -30,4 +30,4 @@ func BookShow(c echo.Context) error { } return c.JSON(http.StatusOK, bookInfo) -} \ No newline at end of file +} diff --git a/routes/api/v1/books_add.go b/routes/api/v1/books_add.go index c75ba09..5f55e44 100644 --- a/routes/api/v1/books_add.go +++ b/routes/api/v1/books_add.go @@ -1,10 +1,10 @@ package v1 import ( + "encoding/json" + "git.mowie.cc/konrad/Library/models" "github.com/labstack/echo" "net/http" - "git.mowie.cc/konrad/Library/models" - "encoding/json" "strings" ) diff --git a/routes/api/v1/books_list.go b/routes/api/v1/books_list.go index 93419e2..48a2d7c 100644 --- a/routes/api/v1/books_list.go +++ b/routes/api/v1/books_list.go @@ -11,9 +11,9 @@ func BookList(c echo.Context) error { list, err := models.ListBooks("") - if err != nil{ + if err != nil { return c.JSON(http.StatusInternalServerError, models.Message{"Error getting books"}) } return c.JSON(http.StatusOK, list) -} \ No newline at end of file +} diff --git a/routes/api/v1/books_search.go b/routes/api/v1/books_search.go index c588203..8309265 100644 --- a/routes/api/v1/books_search.go +++ b/routes/api/v1/books_search.go @@ -19,14 +19,14 @@ func BookSearch(c echo.Context) error { // Get the Books list, err := models.ListBooks(search) - if err != nil{ + if err != nil { return c.JSON(http.StatusInternalServerError, models.Message{"Error getting books"}) } // Check if we have any results - if len(list) == 0{ + if len(list) == 0 { return c.JSON(http.StatusNotFound, models.Message{"Couldn't find any books matching your search term"}) } return c.JSON(http.StatusOK, list) -} \ No newline at end of file +} diff --git a/routes/api/v1/publisher_show.go b/routes/api/v1/publisher_show.go index 53175d0..896fe56 100644 --- a/routes/api/v1/publisher_show.go +++ b/routes/api/v1/publisher_show.go @@ -1,9 +1,9 @@ package v1 import ( + "git.mowie.cc/konrad/Library/models" "github.com/labstack/echo" "net/http" - "git.mowie.cc/konrad/Library/models" "strconv" ) diff --git a/routes/api/v1/publishers_add.go b/routes/api/v1/publishers_add.go index 6f73d07..b18eb04 100644 --- a/routes/api/v1/publishers_add.go +++ b/routes/api/v1/publishers_add.go @@ -1,10 +1,10 @@ package v1 import ( + "encoding/json" + "git.mowie.cc/konrad/Library/models" "github.com/labstack/echo" "net/http" - "git.mowie.cc/konrad/Library/models" - "encoding/json" "strings" ) diff --git a/routes/api/v1/publishers_delete.go b/routes/api/v1/publishers_delete.go index 3e370a8..ee846a8 100644 --- a/routes/api/v1/publishers_delete.go +++ b/routes/api/v1/publishers_delete.go @@ -1,10 +1,10 @@ package v1 import ( - "github.com/labstack/echo" - "strconv" - "net/http" "git.mowie.cc/konrad/Library/models" + "github.com/labstack/echo" + "net/http" + "strconv" ) func PublisherDelete(c echo.Context) error { @@ -37,4 +37,4 @@ func PublisherDelete(c echo.Context) error { } return c.JSON(http.StatusOK, models.Message{"success"}) -} \ No newline at end of file +} diff --git a/routes/api/v1/publishers_list.go b/routes/api/v1/publishers_list.go index 60dc668..382885c 100644 --- a/routes/api/v1/publishers_list.go +++ b/routes/api/v1/publishers_list.go @@ -1,18 +1,18 @@ package v1 import ( + "git.mowie.cc/konrad/Library/models" "github.com/labstack/echo" "net/http" - "git.mowie.cc/konrad/Library/models" ) func PublishersList(c echo.Context) error { list, err := models.ListPublishers("") - if err != nil{ + if err != nil { return c.JSON(http.StatusInternalServerError, models.Message{"Error getting publishers"}) } return c.JSON(http.StatusOK, list) -} \ No newline at end of file +} diff --git a/routes/api/v1/publishers_search.go b/routes/api/v1/publishers_search.go index 1398e90..cbffe36 100644 --- a/routes/api/v1/publishers_search.go +++ b/routes/api/v1/publishers_search.go @@ -19,14 +19,14 @@ func PublisherSearch(c echo.Context) error { // Get the Publishers list, err := models.ListPublishers(search) - if err != nil{ + if err != nil { return c.JSON(http.StatusInternalServerError, models.Message{"Error getting publisher"}) } // Check if we have any results - if len(list) == 0{ + if len(list) == 0 { return c.JSON(http.StatusNotFound, models.Message{"Couldn't find any publisher matching your search term"}) } return c.JSON(http.StatusOK, list) -} \ No newline at end of file +} diff --git a/routes/api/v1/publishers_update.go b/routes/api/v1/publishers_update.go index f65c0cc..12d69f2 100644 --- a/routes/api/v1/publishers_update.go +++ b/routes/api/v1/publishers_update.go @@ -1,12 +1,12 @@ package v1 import ( + "encoding/json" + "git.mowie.cc/konrad/Library/models" "github.com/labstack/echo" "net/http" - "git.mowie.cc/konrad/Library/models" - "encoding/json" - "strings" "strconv" + "strings" ) func PublisherUpdate(c echo.Context) error { diff --git a/routes/api/v1/token_check.go b/routes/api/v1/token_check.go index 36abc30..909f2b5 100644 --- a/routes/api/v1/token_check.go +++ b/routes/api/v1/token_check.go @@ -1,16 +1,16 @@ package v1 import ( - "github.com/labstack/echo" - "github.com/dgrijalva/jwt-go" "fmt" + "github.com/dgrijalva/jwt-go" + "github.com/labstack/echo" ) func CheckToken(c echo.Context) error { - user := c.Get("user").(*jwt.Token) + user := c.Get("user").(*jwt.Token) fmt.Println(user.Valid) return nil -} \ No newline at end of file +} diff --git a/routes/login.go b/routes/login.go index 4dd30a7..a88e98b 100644 --- a/routes/login.go +++ b/routes/login.go @@ -1,11 +1,11 @@ package routes import ( - "github.com/labstack/echo" - "github.com/dgrijalva/jwt-go" - "time" - "net/http" "git.mowie.cc/konrad/Library/models" + "github.com/dgrijalva/jwt-go" + "github.com/labstack/echo" + "net/http" + "time" ) func Login(c echo.Context) error { diff --git a/routes/routes.go b/routes/routes.go index 07bf244..2d2e099 100644 --- a/routes/routes.go +++ b/routes/routes.go @@ -1,9 +1,9 @@ package routes import ( + apiv1 "git.mowie.cc/konrad/Library/routes/api/v1" "github.com/labstack/echo" "github.com/labstack/echo/middleware" - apiv1 "git.mowie.cc/konrad/Library/routes/api/v1" "git.mowie.cc/konrad/Library/models" ) @@ -44,7 +44,6 @@ func RegisterRoutes(e *echo.Echo) { // Login Route e.POST("/login", Login) - // ===== Routes with Authetification ===== // Authetification a.Use(middleware.JWT(models.Config.JWTLoginSecret)) @@ -67,41 +66,41 @@ func RegisterRoutes(e *echo.Echo) { // Manage Users /* - Alles nur mit Api machen, davor dann einen onepager mit vue.js. + Alles nur mit Api machen, davor dann einen onepager mit vue.js. - (Alles mit | benötigt Authentifizierung) + (Alles mit | benötigt Authentifizierung) - Routes: - GET / - entweder übersicht anzeigen (wenn der nutzer eingeloggt ist) oder auf /login weiterleiten - POST /login - ✔ Einloggen - POST /logout - ausloggen + Routes: + GET / - entweder übersicht anzeigen (wenn der nutzer eingeloggt ist) oder auf /login weiterleiten + POST /login - ✔ Einloggen + POST /logout - ausloggen - GET /books/:id - ✔ Buch anzeigen - POST /books/:id - |Buch bearbeiten (inkl mengen) - DELETE /books/:id - ✔ |Buch löschen (+alle einträge in authors_books löschen dessen Bush dazu gehört) - GET /books/search?s=se - ✔ Suchen - GET /books/list - ✔ Auflisten - PUT /books/add - ✔ |Hinzufügen + GET /books/:id - ✔ Buch anzeigen + POST /books/:id - |Buch bearbeiten (inkl mengen) + DELETE /books/:id - ✔ |Buch löschen (+alle einträge in authors_books löschen dessen Bush dazu gehört) + GET /books/search?s=se - ✔ Suchen + GET /books/list - ✔ Auflisten + PUT /books/add - ✔ |Hinzufügen - GET /authors/:id - ✔ Autor anzeigen - POST /authors/:id - ✔ |Autor bearbeiten - DELETE /authors/:id - ✔ |Autor löschen (auch mit allem in books_author) - GET /authors/list - ✔ Autoren auflisten - GET /authors/search?s=d - ✔ Autoren suchen - PUT /authors/add - ✔ |Hinzufügen + GET /authors/:id - ✔ Autor anzeigen + POST /authors/:id - ✔ |Autor bearbeiten + DELETE /authors/:id - ✔ |Autor löschen (auch mit allem in books_author) + GET /authors/list - ✔ Autoren auflisten + GET /authors/search?s=d - ✔ Autoren suchen + PUT /authors/add - ✔ |Hinzufügen - GET /publishers/:id - ✔ Verlag anzeigen - POST /publishers/:id - ✔ |Verlag bearbeiten - DELETE /publishers/:id - ✔ |Verlag löschen (bei büchern Verlag auf 0 setzen) - GET /publishers/list - ✔ Verlage auflisten - GET /publishers/search?s= - ✔ Verlage suchen - PUT /publishers/add - ✔ |Hinzufügen + GET /publishers/:id - ✔ Verlag anzeigen + POST /publishers/:id - ✔ |Verlag bearbeiten + DELETE /publishers/:id - ✔ |Verlag löschen (bei büchern Verlag auf 0 setzen) + GET /publishers/list - ✔ Verlage auflisten + GET /publishers/search?s= - ✔ Verlage suchen + PUT /publishers/add - ✔ |Hinzufügen - GET /settings - |Nutzereinstellungen (Passwort, name etc) - POST /settings - |Nutzereinstellungen (Passwort, name etc) - GET /user - Nutzer anzeigen - PUT /user - |neue Nutzer anlegen - DELETE /user/:id - |nutzer löschen - POST /user/:id - |nutzer bearbeiten + GET /settings - |Nutzereinstellungen (Passwort, name etc) + POST /settings - |Nutzereinstellungen (Passwort, name etc) + GET /user - Nutzer anzeigen + PUT /user - |neue Nutzer anlegen + DELETE /user/:id - |nutzer löschen + POST /user/:id - |nutzer bearbeiten */ }