-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
13 changed files
with
275 additions
and
131 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
package api | ||
|
||
import ( | ||
"encoding/json" | ||
"net/http" | ||
) | ||
|
||
type header struct { | ||
Key string | ||
Value string | ||
} | ||
|
||
var jsonHeader = header{ | ||
"Accept", | ||
"application/json", | ||
} | ||
|
||
func makeGetRequest[T any](url string, headers []header, response *T) error { | ||
req, err := http.NewRequest("GET", url, nil) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
for _, header := range headers { | ||
req.Header.Set(header.Key, header.Value) | ||
} | ||
|
||
client := &http.Client{} | ||
resp, err := client.Do(req) | ||
if err != nil { | ||
return err | ||
} | ||
defer resp.Body.Close() | ||
|
||
if err := json.NewDecoder(resp.Body).Decode(response); err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,42 @@ | ||
package api | ||
|
||
import ( | ||
"log" | ||
"scc/config" | ||
"scc/screen" | ||
"slices" | ||
"time" | ||
) | ||
|
||
type zessResponse struct { | ||
Scans []screen.ZessScan `json:"scans"` | ||
} | ||
|
||
var ( | ||
zessURL = config.GetConfig().Zess.URL | ||
zessLastOrderTimestamp = time.Time{} | ||
) | ||
|
||
func zessRunRequests(app *screen.ScreenApp) { | ||
headers := []header{jsonHeader} | ||
|
||
for { | ||
recentScans := &zessResponse{} | ||
if err := makeGetRequest(zessURL, headers, recentScans); err != nil { | ||
log.Printf("Error: Unable to get recent scans: %s\n", err) | ||
} | ||
|
||
slices.SortStableFunc(recentScans.Scans, func(a, b screen.ZessScan) int { | ||
return a.ScanTime.Compare(b.ScanTime) | ||
}) | ||
|
||
for _, order := range recentScans.Scans { | ||
if order.ScanTime.After(zessLastOrderTimestamp) { | ||
app.Zess.Update(&order) | ||
zessLastOrderTimestamp = order.ScanTime | ||
} | ||
} | ||
|
||
time.Sleep(1 * time.Minute) | ||
} | ||
} |
This file contains 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
This file contains 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
This file contains 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
This file was deleted.
Oops, something went wrong.
This file contains 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
Oops, something went wrong.