This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package service | |
import ( | |
"bookstore/database" | |
"bookstore/model" | |
) | |
func CreateBook(book model.Book) (model.Book, error) { | |
result := database.DB.Create(&book) | |
if result.Error != nil { |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package service | |
import ( | |
"bookstore/model" | |
"testing" | |
) | |
func TestCreateBook(t *testing.T) { | |
// Arrange | |
book := model.Book{ |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package service | |
import "bookstore/model" | |
func CreateBook(book model.Book) (model.Book, error) { | |
return book, nil | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package service | |
import ( | |
"bookstore/config" | |
"bookstore/database" | |
"context" | |
"log" | |
"os" | |
"testing" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
import ( | |
"bookstore/database" | |
"fmt" | |
) | |
func main() { | |
fmt.Println("Hello, World!") | |
database.InitializeDB() // add this |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package database | |
import ( | |
"bookstore/config" | |
"bookstore/model" | |
"fmt" | |
"log" | |
"gorm.io/driver/mysql" | |
"gorm.io/gorm" |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package model | |
import "time" | |
type Order struct { | |
ID int `json:"id" gorm:"primaryKey,autoIncrement"` | |
Total float64 `json:"total"` | |
Items []OrderItem `json:"items" gorm:"-"` | |
CreatedAt time.Time `json:"created_at" gorm:"autoCreateTime,precision:6"` | |
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package model | |
import "time" | |
type Book struct { | |
ID int `json:"id" gorm:"primaryKey"` | |
Title string `json:"title"` | |
Author string `json:"author"` | |
Genre string `json:"genre"` | |
Price float64 `json:"price"` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DB_HOST=some-id.some-region.svc.singlestore.com | |
DB_PORT=3306 | |
DB_USERNAME=admin | |
DB_PASSWORD=SomeSuperSecurePassword | |
DB_DATABASE=bookstore |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package config | |
import "os" | |
var Port = "8080" | |
var Database = struct { | |
Host string | |
Port string | |
Username string |