Skip to content

Commit

Permalink
more progress
Browse files Browse the repository at this point in the history
  • Loading branch information
Tyler-Lentz committed Jun 24, 2024
1 parent 54f1169 commit 55c9ade
Show file tree
Hide file tree
Showing 4 changed files with 69 additions and 6 deletions.
23 changes: 20 additions & 3 deletions houston/src/pages/Report.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -124,7 +124,8 @@ function BottleImage({item, matchedItems} : BottleProps) {
}
return (
<div className="image-container" style={backgroundColor}>
<p className="image-data"><b>Bottle Letter:</b> {bottleDropIndexToJSON(item.Index)}</p>
<p className="image-data"><b>Bottle Letter:</b> {item.Index}</p>
{/* not using function to parse item.Index cause that is being passed down as a string not the bespoke enum */}
<p className="image-data"><b>Alphanumeric:</b> {oDLCColorToJSON(item.AlphanumericColor)} {item.Alphanumeric}</p>
<p className="image-data"><b>Shape:</b> {oDLCColorToJSON(item.ShapeColor)} {oDLCShapeToJSON(item.Shape)}</p>
<p className="image-data"><b>Is Mannikin:</b> {item.IsMannikin ? "Yes" : "No"}</p>
Expand Down Expand Up @@ -214,10 +215,26 @@ function Report() {
setfoundItemArray([...foundItemArray]);
}

const lat = 1.39;
const lng = 103.8;
const lat = 38.31442311312976;
const lng = -76.54522971451763;
return (
<main className="report-page">
<div className="button-container">
<button onClick={() => {
fetch('/api/targets/validate', {
method: "POST"
})
.then(() => alert("good"))
.catch(() => alert("bad"))
}}>Validate</button>
<button onClick={() => {
fetch('/api/targets/reject', {
method: "POST"
})
.then(() => alert("good"))
.catch(() => alert("bad"))
}}>Reject</button>
</div>
<div className="checkbox-container">
<div className="checkbox">
<p className="checkbox-text" style={unmatchedStyle} onClick={handleUnmatched}>Unmatched Targets</p>
Expand Down
23 changes: 21 additions & 2 deletions houston/src/utilities/pull_targets.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,30 @@ import { BottleDropIndex, IdentifiedTarget, ManualTargetMatch, MatchedTarget } f
*/
export async function pull_targets(setFoundItemArray: React.Dispatch<React.SetStateAction<IdentifiedTarget[]>>, setMatchedItemArray: React.Dispatch<React.SetStateAction<MatchedTarget[]>>) {
const response = await fetch('/api/targets/all')
const data = await response.json();
const data = await response.json() as IdentifiedTarget[];
data.forEach( d => {
if (!('id' in d)) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(d as any).id = 0; // stupid hack because protobuf doesn't serialize 0 values
console.log("fix id 0 in list of all targets");
}
});
setFoundItemArray([...data]);

const response1 = await fetch('/api/targets/matched')
const data1 = await response1.json();
const data1 = await response1.json() as MatchedTarget[];
data1.forEach( d => {
if (d.Target == undefined) {
return;
}

if (!('id' in d.Target)) {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
(d.Target as any).id = 0; // stupid hack because protobuf doesn't serialize 0 values
console.log("fix id 0 in list of matched targets");
}
});
setFoundItemArray([...data]);
setMatchedItemArray([...data1]);
}

Expand Down
10 changes: 10 additions & 0 deletions internal/obc/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -258,3 +258,13 @@ func (client *Client) DoCameraCapture() ([]byte, int) {
body, httpErr := client.httpClient.Get("/camera/capture")
return body, httpErr.Status
}

func (client *Client) ValidateTargets() ([]byte, int) {

Check warning on line 262 in internal/obc/client.go

View workflow job for this annotation

GitHub Actions / Lint Backend

exported: exported method Client.ValidateTargets should have comment or be unexported (revive)
body, httpErr := client.httpClient.Post("/targets/validate", nil)
return body, httpErr.Status
}

func (client *Client) RejectTargets() ([]byte, int) {

Check warning on line 267 in internal/obc/client.go

View workflow job for this annotation

GitHub Actions / Lint Backend

exported: exported method Client.RejectTargets should have comment or be unexported (revive)
body, httpErr := client.httpClient.Post("/targets/reject", nil)
return body, httpErr.Status
}
19 changes: 18 additions & 1 deletion internal/server/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,9 @@ func (server *Server) initBackend(router *gin.Engine) {
targets.POST("/matched", server.postMatchedTargets())

targets.POST("/locations", server.postAirdropTargets())

targets.POST("/validate", server.validateTargets())
targets.POST("/reject", server.rejectTargets())
}
}
}
Expand Down Expand Up @@ -565,7 +568,7 @@ func (server *Server) getMatchedTargets() gin.HandlerFunc {

func (server *Server) postMatchedTargets() gin.HandlerFunc {
return func(c *gin.Context) {
var matchedTargets []*protos.MatchedTarget
var matchedTargets *protos.ManualTargetMatch
err := c.BindJSON(&matchedTargets)
if err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": "invalid request body"})
Expand Down Expand Up @@ -620,3 +623,17 @@ func (server *Server) doCameraCapture() gin.HandlerFunc {
c.Data(status, "application/json", body)
}
}

func (server *Server) validateTargets() gin.HandlerFunc {
return func(c *gin.Context) {
body, status := server.obcClient.ValidateTargets()
c.Data(status, "application/json", body)
}
}

func (server *Server) rejectTargets() gin.HandlerFunc {
return func(c *gin.Context) {
body, status := server.obcClient.RejectTargets()
c.Data(status, "application/json", body)
}
}

0 comments on commit 55c9ade

Please sign in to comment.