Skip to content

Commit

Permalink
[PSL-1190] implement get registration details API for cascade multi-v…
Browse files Browse the repository at this point in the history
…olume
  • Loading branch information
j-rafique committed Jun 11, 2024
1 parent 98a0ecf commit 41c196c
Show file tree
Hide file tree
Showing 29 changed files with 61,313 additions and 22,865 deletions.
33 changes: 33 additions & 0 deletions common/storage/ticketstore/activation_attempts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
type ActivationAttemptsQueries interface {
UpsertActivationAttempt(attempt types.ActivationAttempt) error
GetActivationAttemptByID(id string) (*types.ActivationAttempt, error)
GetActivationAttemptsByFileID(fileID string) ([]*types.ActivationAttempt, error)
}

// UpsertActivationAttempt upsert a new activation attempt into the activation_attempts table
Expand Down Expand Up @@ -51,3 +52,35 @@ func (s *TicketStore) GetActivationAttemptByID(id string) (*types.ActivationAtte

return &attempt, nil
}

// GetActivationAttemptsByFileID retrieves activation attempts by file_id from the activation_attempts table
func (s *TicketStore) GetActivationAttemptsByFileID(fileID string) ([]*types.ActivationAttempt, error) {
const selectQuery = `
SELECT id, file_id, activation_attempt_at, is_successful, error_message
FROM activation_attempts
WHERE file_id = ?;`

rows, err := s.db.Query(selectQuery, fileID)
if err != nil {
return nil, err
}
defer rows.Close()

var attempts []*types.ActivationAttempt
for rows.Next() {
var attempt types.ActivationAttempt
err := rows.Scan(
&attempt.ID, &attempt.FileID, &attempt.ActivationAttemptAt,
&attempt.IsSuccessful, &attempt.ErrorMessage)
if err != nil {
return nil, err
}
attempts = append(attempts, &attempt)
}

if err = rows.Err(); err != nil {
return nil, err
}

return attempts, nil
}
50 changes: 46 additions & 4 deletions common/storage/ticketstore/files.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
type FilesQueries interface {
UpsertFile(file types.File) error
GetFileByID(fileID string) (*types.File, error)
GetFilesByBaseFileID(baseFileID string) ([]*types.File, error)
}

// UpsertFile inserts a new file into the files table
Expand All @@ -24,7 +25,7 @@ func (s *TicketStore) UpsertFile(file types.File) error {
DO UPDATE SET
upload_timestamp = excluded.upload_timestamp,
path = excluded.path,
index = excluded.index,
file_index = excluded.index,
base_file_id = excluded.base_file_id,
task_id = excluded.task_id,
reg_txid = excluded.reg_txid,
Expand All @@ -43,7 +44,7 @@ func (s *TicketStore) UpsertFile(file types.File) error {
done_block = excluded.done_block;`

_, err := s.db.Exec(upsertQuery,
file.FileID, file.UploadTimestamp, file.Path, file.Index, file.BaseFileID, file.TaskID,
file.FileID, file.UploadTimestamp, file.Path, file.FileIndex, file.BaseFileID, file.TaskID,
file.RegTxid, file.ActivationTxid, file.ReqBurnTxnAmount, file.BurnTxnID,
file.ReqAmount, file.IsConcluded, file.CascadeMetadataTicketID, file.UUIDKey,
file.HashOfOriginalBigFile, file.NameOfOriginalBigFileWithExt,
Expand All @@ -59,7 +60,7 @@ func (s *TicketStore) UpsertFile(file types.File) error {
// GetFileByID retrieves a file by its ID from the files table
func (s *TicketStore) GetFileByID(fileID string) (*types.File, error) {
const selectQuery = `
SELECT file_id, upload_timestamp, path, index, base_file_id, task_id,
SELECT file_id, upload_timestamp, path, file_index, base_file_id, task_id,
reg_txid, activation_txid, req_burn_txn_amount, burn_txn_id,
req_amount, is_concluded, cascade_metadata_ticket_id, uuid_key,
hash_of_original_big_file, name_of_original_big_file_with_ext,
Expand All @@ -72,7 +73,7 @@ func (s *TicketStore) GetFileByID(fileID string) (*types.File, error) {

var file types.File
err := row.Scan(
&file.FileID, &file.UploadTimestamp, &file.Path, &file.Index, &file.BaseFileID, &file.TaskID,
&file.FileID, &file.UploadTimestamp, &file.Path, &file.FileIndex, &file.BaseFileID, &file.TaskID,
&file.RegTxid, &file.ActivationTxid, &file.ReqBurnTxnAmount, &file.BurnTxnID,
&file.ReqAmount, &file.IsConcluded, &file.CascadeMetadataTicketID, &file.UUIDKey,
&file.HashOfOriginalBigFile, &file.NameOfOriginalBigFileWithExt,
Expand All @@ -84,3 +85,44 @@ func (s *TicketStore) GetFileByID(fileID string) (*types.File, error) {

return &file, nil
}

// GetFilesByBaseFileID retrieves files by base_file_id from the files table
func (s *TicketStore) GetFilesByBaseFileID(baseFileID string) ([]*types.File, error) {
const selectQuery = `
SELECT file_id, upload_timestamp, path, file_index, base_file_id, task_id,
reg_txid, activation_txid, req_burn_txn_amount, burn_txn_id,
req_amount, is_concluded, cascade_metadata_ticket_id, uuid_key,
hash_of_original_big_file, name_of_original_big_file_with_ext,
size_of_original_big_file, data_type_of_original_big_file,
start_block, done_block
FROM files
WHERE base_file_id = ?;`

rows, err := s.db.Query(selectQuery, baseFileID)
if err != nil {
return nil, err
}
defer rows.Close()

var files []*types.File
for rows.Next() {
var file types.File
err := rows.Scan(
&file.FileID, &file.UploadTimestamp, &file.Path, &file.FileIndex, &file.BaseFileID, &file.TaskID,
&file.RegTxid, &file.ActivationTxid, &file.ReqBurnTxnAmount, &file.BurnTxnID,
&file.ReqAmount, &file.IsConcluded, &file.CascadeMetadataTicketID, &file.UUIDKey,
&file.HashOfOriginalBigFile, &file.NameOfOriginalBigFileWithExt,
&file.SizeOfOriginalBigFile, &file.DataTypeOfOriginalBigFile,
&file.StartBlock, &file.DoneBlock)
if err != nil {
return nil, err
}
files = append(files, &file)
}

if err = rows.Err(); err != nil {
return nil, err
}

return files, nil
}
34 changes: 34 additions & 0 deletions common/storage/ticketstore/registration_attempts.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
type RegistrationAttemptsQueries interface {
UpsertRegistrationAttempt(attempt types.RegistrationAttempt) error
GetRegistrationAttemptByID(id int) (*types.RegistrationAttempt, error)
GetRegistrationAttemptsByFileID(fileID string) ([]*types.RegistrationAttempt, error)
}

// UpsertRegistrationAttempt upsert a new registration attempt into the registration_attempts table
Expand Down Expand Up @@ -54,3 +55,36 @@ func (s *TicketStore) GetRegistrationAttemptByID(id int) (*types.RegistrationAtt

return &attempt, nil
}

// GetRegistrationAttemptsByFileID retrieves registration attempts by file_id from the registration_attempts table
func (s *TicketStore) GetRegistrationAttemptsByFileID(fileID string) ([]*types.RegistrationAttempt, error) {
const selectQuery = `
SELECT id, file_id, reg_started_at, processor_sns, finished_at,
is_successful, error_message
FROM registration_attempts
WHERE file_id = ?;`

rows, err := s.db.Query(selectQuery, fileID)
if err != nil {
return nil, err
}
defer rows.Close()

var attempts []*types.RegistrationAttempt
for rows.Next() {
var attempt types.RegistrationAttempt
err := rows.Scan(
&attempt.ID, &attempt.FileID, &attempt.RegStartedAt, &attempt.ProcessorSNS,
&attempt.FinishedAt, &attempt.IsSuccessful, &attempt.ErrorMessage)
if err != nil {
return nil, err
}
attempts = append(attempts, &attempt)
}

if err = rows.Err(); err != nil {
return nil, err
}

return attempts, nil
}
11 changes: 4 additions & 7 deletions common/storage/ticketstore/store.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ CREATE TABLE IF NOT EXISTS files (
file_id TEXT NOT NULL PRIMARY KEY,
upload_timestamp DATETIME,
path TEXT,
index TEXT,
file_index TEXT,
base_file_id TEXT,
task_id TEXT,
reg_txid TEXT,
Expand All @@ -30,8 +30,7 @@ CREATE TABLE IF NOT EXISTS files (
size_of_original_big_file FLOAT,
data_type_of_original_big_file TEXT,
start_block INTEGER,
done_block INTEGER,
FOREIGN KEY (base_file_id) REFERENCES files(file_id)
done_block INTEGER
);
`

Expand All @@ -43,8 +42,7 @@ CREATE TABLE IF NOT EXISTS registration_attempts (
processor_sns TEXT,
finished_at DATETIME,
is_successful BOOLEAN,
error_message TEXT,
FOREIGN KEY (file_id) REFERENCES files(file_id)
error_message TEXT
);
`

Expand All @@ -54,8 +52,7 @@ CREATE TABLE IF NOT EXISTS activation_attempts (
file_id TEXT NOT NULL,
activation_attempt_at DATETIME,
is_successful BOOLEAN,
error_message TEXT,
FOREIGN KEY (file_id) REFERENCES files(file_id)
error_message TEXT
);
`

Expand Down
4 changes: 2 additions & 2 deletions common/types/ticket.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ type File struct {
FileID string
UploadTimestamp time.Time
Path string
Index string
FileIndex string
BaseFileID string
TaskID string
RegTxid string
Expand Down Expand Up @@ -38,7 +38,7 @@ type RegistrationAttempt struct {
}

type ActivationAttempt struct {
ID string
ID int
FileID string
ActivationAttemptAt time.Time
IsSuccessful bool
Expand Down
100 changes: 100 additions & 0 deletions walletnode/api/design/cascade.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,29 @@ var _ = Service("cascade", func() {
Response(StatusOK)
})
})

Method("registrationDetails", func() {
Description("Get the file registration details")
Meta("swagger:summary", "Get the file registration details")

Payload(func() {
Extend(FileRegistrationDetailPayload)
})
Result(FileRegistrationDetailResult)

HTTP(func() {
GET("/registration_details/{file_id}")
Params(func() {
Param("file_id", String)
})

// Define error HTTP statuses.
Response("UnAuthorized", StatusUnauthorized)
Response("BadRequest", StatusBadRequest)
Response("InternalServerError", StatusInternalServerError)
Response(StatusCreated)
})
})
})

// AssetUploadPayload represents a payload for uploading asset
Expand Down Expand Up @@ -218,3 +241,80 @@ var StartCascadeProcessingPayload = Type("StartCascadeProcessingPayload", func()

Required("file_id", "burn_txid", "app_pastelid", "key")
})

// FileRegistrationDetailPayload - Payload for registration detail
var FileRegistrationDetailPayload = Type("FileRegistrationDetailPayload", func() {
Description("File registration details")
Attribute("file_id", String, func() {
Description("file ID")
MaxLength(8)
Example("VK7mpAqZ")
})

Required("file_id")
})

// FileRegistrationDetailResult is registration detail result.
var FileRegistrationDetailResult = ResultType("application/vnd.cascade.registration-detail", func() {
TypeName("Registration")
Attributes(func() {
Attribute("files", ArrayOf(File), "List of files")
})
Required("files")
})

var File = Type("File", func() {
Attribute("file_id", String, "File ID")
Attribute("upload_timestamp", String, "Upload Timestamp in datetime format", func() {
Format(FormatDateTime)
})
Attribute("path", String, "Path to the file")
Attribute("file_index", String, "Index of the file")
Attribute("base_file_id", String, "Base File ID")
Attribute("task_id", String, "Task ID")
Attribute("reg_txid", String, "Registration Transaction ID")
Attribute("activation_txid", String, "Activation Transaction ID")
Attribute("req_burn_txn_amount", Float64, "Required Burn Transaction Amount")
Attribute("burn_txn_id", String, "Burn Transaction ID")
Attribute("req_amount", Float64, "Required Amount")
Attribute("is_concluded", Boolean, "Indicates if the process is concluded")
Attribute("cascade_metadata_ticket_id", String, "Cascade Metadata Ticket ID")
Attribute("uuid_key", String, "UUID Key")
Attribute("hash_of_original_big_file", String, "Hash of the Original Big File")
Attribute("name_of_original_big_file_with_ext", String, "Name of the Original Big File with Extension")
Attribute("size_of_original_big_file", Float64, "Size of the Original Big File")
Attribute("data_type_of_original_big_file", String, "Data Type of the Original Big File")
Attribute("start_block", Int32, "Start Block")
Attribute("done_block", Int, "Done Block")
Attribute("registration_attempts", ArrayOf(RegistrationAttempt), "List of registration attempts")
Attribute("activation_attempts", ArrayOf(ActivationAttempt), "List of activation attempts")
Required("file_id", "task_id", "upload_timestamp", "base_file_id", "registration_attempts", "activation_attempts",
"req_burn_txn_amount", "req_amount", "cascade_metadata_ticket_id", "hash_of_original_big_file", "name_of_original_big_file_with_ext",
"size_of_original_big_file", "data_type_of_original_big_file")
})

var RegistrationAttempt = Type("RegistrationAttempt", func() {
Attribute("id", Int, "ID")
Attribute("file_id", String, "File ID")
Attribute("reg_started_at", String, "Registration Started At in datetime format", func() {
Format(FormatDateTime)
})
Attribute("processor_sns", String, "Processor SNS")
Attribute("finished_at", String, "Finished At in datetime format", func() {
Format(FormatDateTime)
})
Attribute("is_successful", Boolean, "Indicates if the registration was successful")
Attribute("error_message", String, "Error Message")
Required("id", "file_id", "reg_started_at", "finished_at")
})

var ActivationAttempt = Type("ActivationAttempt", func() {
Attribute("id", Int, "ID")
Attribute("file_id", String, "File ID")
Attribute("activation_attempt_at", String, "Activation Attempt At in datetime format", func() {
Format(FormatDateTime)
})
Attribute("is_successful", Boolean, "Indicates if the activation was successful")
Attribute("error_message", String, "Error Message")
Required("id", "file_id", "activation_attempt_at")
})
Loading

0 comments on commit 41c196c

Please sign in to comment.