[Task]: Comment \models
This commit is contained in:
parent
591695c0b6
commit
1259f9cfe3
|
@ -1,3 +1,4 @@
|
|||
// Package with the mostly static content (models) of this microservice
|
||||
package models
|
||||
|
||||
import (
|
||||
|
@ -9,9 +10,9 @@ import (
|
|||
"github.com/genofire/hs_master-kss-monolith/lib/log"
|
||||
)
|
||||
|
||||
//config file of this daemon (for more the config_example.conf in git repository)
|
||||
// Config file for this daemon (mor information at the config_example.conf in this git repository)
|
||||
type Config struct {
|
||||
// address on which the api and static content webserver runs
|
||||
// address under which the api and static content of the webserver runs
|
||||
WebserverBind string `toml:"webserver_bind"`
|
||||
|
||||
// path to deliver static content
|
||||
|
@ -21,33 +22,33 @@ type Config struct {
|
|||
GoodRelease GoodReleaseConfig `toml:"good_release"`
|
||||
CacheClean CacheWorkerConfig `toml:"cache_clean"`
|
||||
|
||||
// path to the svg image templaes to show availablity of a given good
|
||||
// path to the svg image templaes to show availablity of a given good with a traffic light food labeling system
|
||||
GoodAvailablityTemplate string `toml:"good_availablity_template"`
|
||||
|
||||
// URLs to other microservices
|
||||
// URLs to other microservices that this services uses
|
||||
MicroserviceDependencies struct {
|
||||
Product string `toml:"product"`
|
||||
Permission string `toml:"permission"`
|
||||
} `toml:"microservice_dependencies"`
|
||||
}
|
||||
|
||||
//config of worker to clean caches from values of other microservice
|
||||
// Configuration of the Worker to clean the cache from values of other microservice
|
||||
type CacheWorkerConfig struct {
|
||||
// run worker every ...
|
||||
// Run Worker every Duration
|
||||
Every Duration
|
||||
// remove cache which is not used since ..
|
||||
// Remove cache, which is not used since Duration
|
||||
After Duration
|
||||
}
|
||||
|
||||
//config of worker to release looked goods after a time
|
||||
// Configuration of the Worker to release locked goods after a time period
|
||||
type GoodReleaseConfig struct {
|
||||
// run worker every ...
|
||||
// Run worker every Duration
|
||||
Every Duration `toml:"every"`
|
||||
// unlock which is not used since ..
|
||||
// unlock which is not used since Duration
|
||||
After Duration `toml:"after"`
|
||||
}
|
||||
|
||||
//reads a config model from path of a yml file
|
||||
// Function that reads a config model from a given path of a yml file
|
||||
func ReadConfigFile(path string) *Config {
|
||||
config := &Config{}
|
||||
file, err := ioutil.ReadFile(path)
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// Package with the mostly static content (models) of this microservice
|
||||
package models
|
||||
|
||||
import (
|
||||
|
@ -6,6 +7,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// Function to test the configuration of the microservice
|
||||
func TestReadConfig(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// Package with the mostly static content (models) of this microservice
|
||||
package models
|
||||
|
||||
import (
|
||||
|
@ -7,15 +8,13 @@ import (
|
|||
)
|
||||
|
||||
// Duration is a TOML datatype
|
||||
// A duration string is a possibly signed sequence of
|
||||
// decimal numbers and a unit suffix,
|
||||
// such as "300s", "1.5h" or "5d".
|
||||
// Valid time units are "s", "m", "h", "d", "w".
|
||||
// A duration string is a possibly signed sequence of decimal numbers and a unit suffix,
|
||||
// such as "300s", "1.5h" or "5d". Valid time units are "s", "m", "h", "d", "w".
|
||||
type Duration struct {
|
||||
time.Duration
|
||||
}
|
||||
|
||||
// UnmarshalTOML parses a duration string.
|
||||
// Function UnmarshalTOML parses a duration string
|
||||
func (d *Duration) UnmarshalTOML(dataInterface interface{}) error {
|
||||
var data string
|
||||
switch dataInterface.(type) {
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// Package with the mostly static content (models) of this microservice
|
||||
package models
|
||||
|
||||
import (
|
||||
|
@ -7,6 +8,8 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
|
||||
// Function to test UnmarshalTOML()
|
||||
func TestDuration(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// Package with the mostly static content (models) of this microservice
|
||||
package models
|
||||
|
||||
import (
|
||||
|
@ -9,7 +10,7 @@ import (
|
|||
"github.com/genofire/hs_master-kss-monolith/lib/database"
|
||||
)
|
||||
|
||||
// this stock microservice manage goods
|
||||
// Goods managemd in this stock microservice
|
||||
type Good struct {
|
||||
ID int64
|
||||
ProductID int64
|
||||
|
@ -26,24 +27,24 @@ type Good struct {
|
|||
Sended bool
|
||||
}
|
||||
|
||||
// generate database select which filtered locked goods
|
||||
// Function to enerate a database and select locked goods with a filter
|
||||
func (g *Good) FilterAvailable(db *gorm.DB) *gorm.DB {
|
||||
return db.Model(g).Where("locked_secret == '' OR locked_secret is NULL")
|
||||
}
|
||||
|
||||
// lock the good, on a way, that it could not be used by other users
|
||||
// Function to lock a good, so that it cannot be locked or bought by other users
|
||||
func (g *Good) Lock(secret string) {
|
||||
now := time.Now()
|
||||
g.LockedSecret = secret
|
||||
g.LockedAt = &now
|
||||
}
|
||||
|
||||
// is this good locked?
|
||||
// Function to check if a good is locked
|
||||
func (g *Good) IsLock() bool {
|
||||
return len(g.LockedSecret) > 0
|
||||
}
|
||||
|
||||
// unlock the good, that it could be usered again
|
||||
// Function to unlock a good
|
||||
func (g *Good) Unlock(secret string) error {
|
||||
if g.LockedSecret == secret {
|
||||
g.LockedSecret = ""
|
||||
|
@ -53,6 +54,7 @@ func (g *Good) Unlock(secret string) error {
|
|||
return errors.New("wrong secret")
|
||||
}
|
||||
|
||||
// Function to initialize the database
|
||||
func init() {
|
||||
database.AddModel(&Good{})
|
||||
}
|
||||
|
|
|
@ -1,3 +1,4 @@
|
|||
// Package with the mostly static content (models) of this microservice
|
||||
package models
|
||||
|
||||
import (
|
||||
|
@ -7,6 +8,7 @@ import (
|
|||
"github.com/stretchr/testify/assert"
|
||||
)
|
||||
|
||||
// Function to test the locking and unlocking of a good
|
||||
func TestGood(t *testing.T) {
|
||||
assert := assert.New(t)
|
||||
|
||||
|
|
|
@ -1,2 +0,0 @@
|
|||
// a package to store all the struct
|
||||
package models
|
|
@ -0,0 +1,4 @@
|
|||
// Package with the mostly static content (models) of this microservice
|
||||
package models
|
||||
|
||||
// Store all the structs
|
Reference in New Issue