Skip to content

Commit 09f8145

Browse files
committed
Fix mobile delivery polling and human KITN rewards
1 parent 7925c86 commit 09f8145

File tree

3 files changed

+50
-0
lines changed

3 files changed

+50
-0
lines changed

platform_blueprint/deploy/prod/nginx_conf_d/apicleanapp.conf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ server {
1313
location = /update_or_create_user { proxy_pass http://127.0.0.1:8079; proxy_set_header Host $host; proxy_read_timeout 60; proxy_redirect http:// https://; }
1414
location = /report { proxy_pass http://127.0.0.1:8079; proxy_set_header Host $host; proxy_read_timeout 60; proxy_redirect http:// https://; }
1515
location = /read_report { proxy_pass http://127.0.0.1:8079; proxy_set_header Host $host; proxy_read_timeout 60; proxy_redirect http:// https://; }
16+
location = /read_report_email_status { proxy_pass http://127.0.0.1:8079; proxy_set_header Host $host; proxy_read_timeout 60; proxy_redirect http:// https://; }
1617
location = /get_map { proxy_pass http://127.0.0.1:8079; proxy_set_header Host $host; proxy_read_timeout 60; proxy_redirect http:// https://; }
1718
location = /get_stats { proxy_pass http://127.0.0.1:8079; proxy_set_header Host $host; proxy_read_timeout 60; proxy_redirect http:// https://; }
1819
location = /get_teams { proxy_pass http://127.0.0.1:8079; proxy_set_header Host $host; proxy_read_timeout 60; proxy_redirect http:// https://; }
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
package database
2+
3+
import (
4+
"context"
5+
"fmt"
6+
"strings"
7+
)
8+
9+
// IncrementReporterDailyKITNs preserves the legacy mobile reward behavior for
10+
// wallet-backed human submissions that now enter through the canonical ingest path.
11+
func (d *Database) IncrementReporterDailyKITNs(ctx context.Context, reporterID string) error {
12+
reporterID = strings.TrimSpace(reporterID)
13+
if reporterID == "" {
14+
return nil
15+
}
16+
17+
tx, err := d.db.BeginTx(ctx, nil)
18+
if err != nil {
19+
return fmt.Errorf("begin reward tx: %w", err)
20+
}
21+
defer tx.Rollback()
22+
23+
if _, err := tx.ExecContext(ctx, `
24+
UPDATE users
25+
SET kitns_daily = kitns_daily + 1
26+
WHERE id = ?
27+
`, reporterID); err != nil {
28+
return fmt.Errorf("increment users.kitns_daily: %w", err)
29+
}
30+
31+
if _, err := tx.ExecContext(ctx, `
32+
UPDATE users_shadow
33+
SET kitns_daily = kitns_daily + 1
34+
WHERE id = ?
35+
`, reporterID); err != nil {
36+
return fmt.Errorf("increment users_shadow.kitns_daily: %w", err)
37+
}
38+
39+
if err := tx.Commit(); err != nil {
40+
return fmt.Errorf("commit reward tx: %w", err)
41+
}
42+
return nil
43+
}

report-listener/handlers/human_ingest.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"encoding/hex"
99
"encoding/json"
1010
"fmt"
11+
"log"
1112
"net/http"
1213
"strings"
1314
"time"
@@ -309,6 +310,11 @@ func (h *Handlers) SubmitHumanReportV1(c *gin.Context) {
309310
return
310311
}
311312
}
313+
if receipt.ReportID > 0 && !receipt.IdempotencyReplay && strings.TrimSpace(req.ReporterID) != "" {
314+
if err := h.db.IncrementReporterDailyKITNs(c.Request.Context(), req.ReporterID); err != nil {
315+
log.Printf("warn: failed to increment KITNs for human report %d (%s): %v", receipt.ReportID, req.ReporterID, err)
316+
}
317+
}
312318
c.JSON(statusCode, h.humanReceiptResponseFromWire(c.Request.Context(), receipt))
313319
}
314320

0 commit comments

Comments
 (0)