truckstop/broker/job.go

68 lines
1.2 KiB
Go

package broker
import (
"fmt"
"local/truckstop/config"
"log"
"strings"
"time"
)
type Job struct {
ID string
Pickup JobLocation
Dropoff JobLocation
Weight int
Miles int
Meta string
}
type JobLocation struct {
Date time.Time
City string
State string
}
func (j Job) String() string {
return fmt.Sprintf(
`%s => %s (%d miles), Weight:%d, Notes:%s`,
j.Pickup.String(),
j.Dropoff.String(),
j.Miles,
j.Weight,
j.Meta,
)
}
func (j JobLocation) String() string {
return fmt.Sprintf("%s, %s @ %s", j.City, j.State, j.Date.Format("Monday Jan 02"))
}
func (j Job) FormatMultilineText() string {
foo := func(client string) string {
return fmt.Sprintf(
"--- %s: %s => %s ---\nPickup: %s\nDropoff: %s\nNotes: %d lbs, %d miles, %s",
client,
j.Pickup.State,
j.Dropoff.State,
j.Pickup.String(),
j.Dropoff.String(),
j.Weight,
j.Miles,
j.Meta,
)
}
out := ""
clients := config.Get().Clients
for k := range clients {
log.Printf("job multiline: %+v contains %s then use %v", clients[k].States, j.Pickup.State, k)
if strings.Contains(fmt.Sprint(clients[k].States), j.Pickup.State) {
if len(out) > 0 {
out += "\n\n"
}
out += foo(k)
}
}
return out
}