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 (
account_id integer NOT NULL,
ticket_id character varying(16) NOT NULL,
title_id character varying(16) NOT NULL,
version integer
);

32
ecs.go
View File

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