Utilize new schema for ListETickets

This commit is contained in:
Spotlight 2022-01-08 16:38:39 -06:00
parent 461b40d6bd
commit d7af36a6c8
No known key found for this signature in database
GPG Key ID: 874AA355B3209BDC
2 changed files with 17 additions and 16 deletions

View File

@ -26,7 +26,6 @@ SET default_table_access_method = heap;
CREATE TABLE public.owned_titles ( CREATE TABLE public.owned_titles (
account_id integer NOT NULL, account_id integer NOT NULL,
ticket_id character varying(16) NOT NULL,
title_id character varying(16) NOT NULL, title_id character varying(16) NOT NULL,
version integer version integer
); );

32
ecs.go
View File

@ -18,14 +18,16 @@
package main package main
import ( import (
"errors"
"fmt" "fmt"
"log"
) )
const ( const (
QueryOwnedTitles = `SELECT o.ticket_id, o.title_id, s.version, o.revocation_date QueryOwnedTitles = `SELECT owned_titles.title_id, tickets.version
FROM owned_titles o FROM owned_titles, tickets
JOIN shop_titles s on s.title_id = o.title_id WHERE owned_titles.title_id = tickets.title_id
AND o.account_id = $1` AND owned_titles.account_id = $1`
) )
func checkDeviceStatus(e *Envelope) { func checkDeviceStatus(e *Envelope) {
@ -45,36 +47,36 @@ func notifyETicketsSynced(e *Envelope) {
func listETickets(e *Envelope) { func listETickets(e *Envelope) {
accountId, err := e.AccountId() accountId, err := e.AccountId()
if err != nil { if err != nil {
e.Error(2, "that's all you've got for me? ;3", err) e.Error(2, "missing account ID", err)
return return
} }
rows, err := pool.Query(ctx, QueryOwnedTitles, accountId) rows, err := pool.Query(ctx, QueryOwnedTitles, accountId)
if err != nil { if err != nil {
e.Error(2, "that's all you've got for me? ;3", err) log.Printf("error executing statement: %v\n", err)
e.Error(2, "database error", errors.New("failed to execute db operation"))
return return
} }
// Add all available titles for this account. // Add all available titles for this account.
defer rows.Close() defer rows.Close()
for rows.Next() { for rows.Next() {
var ticketId string
var titleId string var titleId string
var version int var version int
var revocationDate int err = rows.Scan(&titleId, &version)
err = rows.Scan(&ticketId, &titleId, &version, &revocationDate)
if err != nil { if err != nil {
e.Error(2, "that's all you've got for me? ;3", err) log.Printf("error executing statement: %v\n", err)
e.Error(2, "database error", errors.New("failed to execute db operation"))
return return
} }
e.AddCustomType(Tickets{ e.AddCustomType(Tickets{
TicketId: ticketId, TitleId: titleId,
TitleId: titleId, Version: version,
Version: version,
RevokeDate: revocationDate,
// We do not support migration. // We do not support migration, ticket IDs, or revocation.
TicketId: "0",
RevokeDate: 0,
MigrateCount: 0, MigrateCount: 0,
MigrateLimit: 0, MigrateLimit: 0,
}) })