Add evidence type link

close #44

Signed-off-by: gearnode <bryan@frimin.fr>
This commit is contained in:
gearnode
2025-03-20 17:25:29 +01:00
parent 7117c6a210
commit b8bbeaba11
13 changed files with 798 additions and 167 deletions

View File

@@ -28,15 +28,18 @@ import (
type (
Evidence struct {
ID gid.GID `db:"id"`
TaskID gid.GID `db:"task_id"`
State EvidenceState `db:"state"`
ObjectKey string `db:"object_key"`
MimeType string `db:"mime_type"`
Size uint64 `db:"size"`
Filename string `db:"filename"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
ID gid.GID `db:"id"`
TaskID gid.GID `db:"task_id"`
State EvidenceState `db:"state"`
Type EvidenceType `db:"type"`
ObjectKey string `db:"object_key"`
MimeType string `db:"mime_type"`
Size uint64 `db:"size"`
Filename string `db:"filename"`
URL string `db:"url"`
Description string `db:"description"`
CreatedAt time.Time `db:"created_at"`
UpdatedAt time.Time `db:"updated_at"`
}
Evidences []*Evidence
@@ -66,7 +69,10 @@ INSERT INTO
mime_type,
size,
state,
type,
filename,
url,
description,
created_at,
updated_at
)
@@ -78,7 +84,10 @@ VALUES (
@mime_type,
@size,
@state,
@type,
@filename,
@url,
@description,
@created_at,
@updated_at
)
@@ -95,6 +104,9 @@ VALUES (
"created_at": e.CreatedAt,
"updated_at": e.UpdatedAt,
"state": e.State,
"type": e.Type,
"url": e.URL,
"description": e.Description,
}
_, err := conn.Exec(ctx, q, args)
return err
@@ -111,10 +123,13 @@ SELECT
id,
task_id,
state,
type,
object_key,
mime_type,
size,
filename,
url,
description,
created_at,
updated_at
FROM
@@ -157,10 +172,13 @@ SELECT
id,
task_id,
state,
type,
object_key,
mime_type,
size,
filename,
url,
description,
created_at,
updated_at
FROM

View File

@@ -0,0 +1,74 @@
// Copyright (c) 2025 Probo Inc <hello@getprobo.com>.
//
// Permission to use, copy, modify, and/or distribute this software for any
// purpose with or without fee is hereby granted, provided that the above
// copyright notice and this permission notice appear in all copies.
//
// THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES WITH
// REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY
// AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT,
// INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM
// LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
// OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
// PERFORMANCE OF THIS SOFTWARE.
package coredata
import (
"database/sql/driver"
"fmt"
)
type (
EvidenceType uint8
)
const (
EvidenceTypeFile EvidenceType = iota
EvidenceTypeLink
)
func (et EvidenceType) MarshalText() ([]byte, error) {
return []byte(et.String()), nil
}
func (et *EvidenceType) UnmarshalText(data []byte) error {
val := string(data)
switch val {
case EvidenceTypeFile.String():
*et = EvidenceTypeFile
case EvidenceTypeLink.String():
*et = EvidenceTypeLink
default:
return fmt.Errorf("invalid EvidenceType value: %q", val)
}
return nil
}
func (et EvidenceType) String() string {
var val string
switch et {
case EvidenceTypeFile:
val = "FILE"
case EvidenceTypeLink:
val = "LINK"
}
return val
}
func (et *EvidenceType) Scan(value any) error {
val, ok := value.(string)
if !ok {
return fmt.Errorf("invalid scan source for EvidenceType, expected string got %T", value)
}
return et.UnmarshalText([]byte(val))
}
func (et EvidenceType) Value() (driver.Value, error) {
return et.String(), nil
}

View File

@@ -0,0 +1,15 @@
-- Add evidence type enum
CREATE TYPE evidence_type AS ENUM (
'FILE',
'LINK'
);
ALTER TABLE evidences
ADD COLUMN type evidence_type NOT NULL DEFAULT 'FILE',
ADD COLUMN url TEXT NOT NULL DEFAULT '',
ADD COLUMN description TEXT NOT NULL DEFAULT '';
ALTER TABLE evidences
ALTER COLUMN type DROP DEFAULT,
ALTER COLUMN url DROP DEFAULT,
ALTER COLUMN description DROP DEFAULT;