diff --git a/appdatabase/migrations/bindata.go b/appdatabase/migrations/bindata.go index 01e399e58..93700fe88 100644 --- a/appdatabase/migrations/bindata.go +++ b/appdatabase/migrations/bindata.go @@ -582,7 +582,7 @@ func _0013_identity_imagesDownSql() (*asset, error) { return a, nil } -var __0013_identity_imagesUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x4c\x8d\xc1\x6a\x84\x30\x14\x45\xf7\x82\xff\x70\x97\x2d\xf4\x0f\xba\x8a\x69\x86\x09\x4d\x93\x21\x93\xa9\x75\x15\x02\xbe\xea\x03\x6b\x45\x03\xc5\x7e\x7d\xa9\xe3\xc2\xe5\x3d\x9c\xc3\x95\x5e\x89\xa0\x10\x44\x65\x14\xf4\x09\xd6\x05\xa8\x0f\x7d\x0d\x57\x70\x4b\x63\xe6\xbc\x46\xfe\x4a\x1d\x2d\x0f\x65\x01\x00\x79\x9d\x08\xef\xc2\xcb\xb3\xf0\xb8\x78\xfd\x26\x7c\x83\x57\xd5\xc0\x59\x48\x67\x4f\x46\xcb\x00\xaf\x2e\x46\x48\xf5\x74\x4f\xb6\x3e\x4e\x69\x1d\xbe\x53\x8b\xca\xb8\x6a\xbb\xb1\x37\x63\x76\xe3\x87\xdb\xdc\x83\xc7\xbc\xef\x9e\xb8\xeb\xf3\x01\x7c\xf2\x40\x71\xe1\x5f\x3a\xb0\x99\xfe\x41\xcc\x69\xee\x68\x73\xcb\xe2\x11\xb5\x0e\x67\x77\x0b\xf0\xae\xd6\x2f\xcf\x65\xf1\x17\x00\x00\xff\xff\x5a\x44\xbb\x1b\xe0\x00\x00\x00") +var __0013_identity_imagesUpSql = []byte("\x1f\x8b\x08\x00\x00\x00\x00\x00\x00\xff\x4c\x8d\xc1\x6a\x84\x30\x14\x45\xf7\x82\xff\x70\x97\x2d\xf4\x0f\xba\x8a\x69\x86\x09\x4d\x93\x21\x93\xa9\x75\x15\x02\xbe\xea\x03\xb5\x45\x03\xc5\x7e\x7d\xa9\xe3\xc2\xe5\x3d\x9c\xc3\x95\x5e\x89\xa0\x10\x44\x65\x14\xf4\x09\xd6\x05\xa8\x0f\x7d\x0d\x57\x70\x4b\x53\xe6\xbc\x46\x1e\x53\x47\xcb\x43\x59\x00\xc0\x94\x46\xc2\xbb\xf0\xf2\x2c\x3c\x2e\x5e\xbf\x09\xdf\xe0\x55\x35\x70\x16\xd2\xd9\x93\xd1\x32\xc0\xab\x8b\x11\x52\x3d\xdd\x93\xad\x8f\xdf\x69\x1d\xbe\x52\x8b\xca\xb8\x6a\xbb\xb1\x37\x63\x76\xe3\x87\xdb\xdc\x83\xa7\xbc\xef\x9e\xb8\xeb\xf3\x01\x7c\xf2\x40\x71\xe1\x5f\x3a\xb0\x99\xfe\x41\xcc\x69\xee\x68\x73\xcb\xe2\x11\xb5\x0e\x67\x77\x0b\xf0\xae\xd6\x2f\xcf\x65\xf1\x17\x00\x00\xff\xff\xce\x22\x48\xbe\xe0\x00\x00\x00") func _0013_identity_imagesUpSqlBytes() ([]byte, error) { return bindataRead( @@ -597,8 +597,8 @@ func _0013_identity_imagesUpSql() (*asset, error) { return nil, err } - info := bindataFileInfo{name: "0013_identity_images.up.sql", size: 224, mode: os.FileMode(0644), modTime: time.Unix(1608048390, 0)} - a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xbb, 0x3f, 0xef, 0xda, 0x8e, 0x99, 0x86, 0xe9, 0x40, 0xef, 0xdb, 0xd4, 0x1c, 0x9c, 0x74, 0x50, 0x37, 0x7d, 0x33, 0xbe, 0x4f, 0x74, 0x6a, 0x80, 0x21, 0x48, 0x6f, 0x92, 0xad, 0x26, 0x93, 0xc5}} + info := bindataFileInfo{name: "0013_identity_images.up.sql", size: 224, mode: os.FileMode(0644), modTime: time.Unix(1608048446, 0)} + a := &asset{bytes: bytes, info: info, digest: [32]uint8{0xcc, 0x40, 0x80, 0xa3, 0x1d, 0xc0, 0x7b, 0xb8, 0xb4, 0xe8, 0x17, 0x5f, 0x4, 0xda, 0xdc, 0xe3, 0x18, 0x3, 0x31, 0xe2, 0x45, 0x19, 0xa8, 0x41, 0xae, 0x43, 0xa4, 0xeb, 0xd7, 0x66, 0x80, 0x66}} return a, nil } diff --git a/appdatabase/migrations/sql/0013_identity_images.up.sql b/appdatabase/migrations/sql/0013_identity_images.up.sql index 0a7395ec1..e775268e4 100644 --- a/appdatabase/migrations/sql/0013_identity_images.up.sql +++ b/appdatabase/migrations/sql/0013_identity_images.up.sql @@ -1,5 +1,5 @@ CREATE TABLE IF NOT EXISTS identity_images( - type VARCHAR PRIMARY KEY ON CONFLICT REPLACE, + name VARCHAR PRIMARY KEY ON CONFLICT REPLACE, image_payload BLOB NOT NULL, width int, height int, diff --git a/images/database.go b/images/database.go index 1191f57be..284bee4a4 100644 --- a/images/database.go +++ b/images/database.go @@ -12,7 +12,7 @@ type Database struct { } type IdentityImage struct { - Type string //TODO change this to Name, also in the db migration + Name string Payload []byte Width int Height int @@ -25,7 +25,7 @@ func NewDatabase(db *sql.DB) Database { } func (d *Database) GetIdentityImages() ([]*IdentityImage, error) { - rows, err := d.db.Query(`SELECT type, image_payload, width, height, file_size, resize_target FROM identity_images`) + rows, err := d.db.Query(`SELECT name, image_payload, width, height, file_size, resize_target FROM identity_images`) if err != nil { return nil, err } @@ -34,7 +34,7 @@ func (d *Database) GetIdentityImages() ([]*IdentityImage, error) { var iis []*IdentityImage for rows.Next() { ii := &IdentityImage{} - err = rows.Scan(&ii.Type, &ii.Payload, &ii.Width, &ii.Height, &ii.FileSize, &ii.ResizeTarget) + err = rows.Scan(&ii.Name, &ii.Payload, &ii.Width, &ii.Height, &ii.FileSize, &ii.ResizeTarget) if err != nil { return nil, err } @@ -46,7 +46,7 @@ func (d *Database) GetIdentityImages() ([]*IdentityImage, error) { } func (d *Database) GetIdentityImage(it string) (*IdentityImage, error) { - query := "SELECT type, image_payload, width, height, file_size, resize_target FROM identity_images WHERE type = ?" + query := "SELECT name, image_payload, width, height, file_size, resize_target FROM identity_images WHERE name = ?" rows, err := d.db.Query(query, it) if err != nil { return nil, err @@ -55,7 +55,7 @@ func (d *Database) GetIdentityImage(it string) (*IdentityImage, error) { var ii IdentityImage for rows.Next() { - err = rows.Scan(&ii.Type, &ii.Payload, &ii.Width, &ii.Height, &ii.FileSize, &ii.ResizeTarget) + err = rows.Scan(&ii.Name, &ii.Payload, &ii.Width, &ii.Height, &ii.FileSize, &ii.ResizeTarget) if err != nil { return nil, err } @@ -78,7 +78,7 @@ func (d *Database) StoreIdentityImages(iis []*IdentityImage) (err error) { _ = tx.Rollback() }() - query := "INSERT INTO identity_images (type, image_payload, width, height, file_size, resize_target) VALUES (?, ?, ?, ?, ?, ?)" + query := "INSERT INTO identity_images (name, image_payload, width, height, file_size, resize_target) VALUES (?, ?, ?, ?, ?, ?)" stmt, err := tx.Prepare(query) if err != nil { return @@ -86,7 +86,7 @@ func (d *Database) StoreIdentityImages(iis []*IdentityImage) (err error) { defer stmt.Close() for _, ii := range iis { - _, err = stmt.Exec(ii.Type, ii.Payload, ii.Width, ii.Height, ii.FileSize, ii.ResizeTarget) + _, err = stmt.Exec(ii.Name, ii.Payload, ii.Width, ii.Height, ii.FileSize, ii.ResizeTarget) if err != nil { return } @@ -96,7 +96,7 @@ func (d *Database) StoreIdentityImages(iis []*IdentityImage) (err error) { } func (d *Database) DeleteIdentityImage(it string) error { - _, err := d.db.Exec(`DELETE FROM identity_images WHERE type = ?`, it) + _, err := d.db.Exec(`DELETE FROM identity_images WHERE name = ?`, it) return err } @@ -118,14 +118,14 @@ func (i IdentityImage) MarshalJSON() ([]byte, error) { } temp := struct { - Type string `json:"type"` + Name string `json:"type"` URI string `json:"uri"` Width int `json:"width"` Height int `json:"height"` FileSize int `json:"file_size"` ResizeTarget int `json:"resize_target"` }{ - Type: i.Type, + Name: i.Name, URI: uri, Width: i.Width, Height: i.Height, diff --git a/images/database_test.go b/images/database_test.go index e8ee0ddd1..7faf284f1 100644 --- a/images/database_test.go +++ b/images/database_test.go @@ -60,7 +60,7 @@ func TestIdentityImage_GetDataURI(t *testing.T) { func TestIdentityImage_MarshalJSON(t *testing.T) { ii := IdentityImage{ - Type: "thumbnail", + Name: "thumbnail", Payload: testJpegBytes, Width: 80, Height: 80, @@ -88,7 +88,7 @@ func setupTestDB(t *testing.T) (Database, func()) { func seedTestDB(t *testing.T, db Database) { iis := []*IdentityImage{ { - Type: "thumbnail", + Name: smallDimName, Payload: testJpegBytes, Width: 80, Height: 80, @@ -96,7 +96,7 @@ func seedTestDB(t *testing.T, db Database) { ResizeTarget: 80, }, { - Type: "large", + Name: largeDimName, Payload: testPngBytes, Width: 240, Height: 300, @@ -113,7 +113,7 @@ func TestDatabase_GetIdentityImages(t *testing.T) { defer stop() seedTestDB(t, db) - expected := `[{"type":"large","uri":"data:image/png;base64,iVBORw0KGgoAAAANSUg=","width":240,"height":300,"file_size":1024,"resize_target":240},{"type":"thumbnail","uri":"data:image/jpeg;base64,/9j/2wCEAFA3PEY8MlA=","width":80,"height":80,"file_size":256,"resize_target":80}]` + expected := `[{"name":"large","uri":"data:image/png;base64,iVBORw0KGgoAAAANSUg=","width":240,"height":300,"file_size":1024,"resize_target":240},{"name":"thumbnail","uri":"data:image/jpeg;base64,/9j/2wCEAFA3PEY8MlA=","width":80,"height":80,"file_size":256,"resize_target":80}]` oiis, err := db.GetIdentityImages() require.NoError(t, err) @@ -133,12 +133,12 @@ func TestDatabase_GetIdentityImage(t *testing.T) { Expected string }{ { - "thumbnail", - `{"type":"thumbnail","uri":"data:image/jpeg;base64,/9j/2wCEAFA3PEY8MlA=","width":80,"height":80,"file_size":256,"resize_target":80}`, + smallDimName, + `{"name":"thumbnail","uri":"data:image/jpeg;base64,/9j/2wCEAFA3PEY8MlA=","width":80,"height":80,"file_size":256,"resize_target":80}`, }, { - "large", - `{"type":"large","uri":"data:image/png;base64,iVBORw0KGgoAAAANSUg=","width":240,"height":300,"file_size":1024,"resize_target":240}`, + largeDimName, + `{"name":"large","uri":"data:image/png;base64,iVBORw0KGgoAAAANSUg=","width":240,"height":300,"file_size":1024,"resize_target":240}`, }, } @@ -157,9 +157,9 @@ func TestDatabase_DeleteIdentityImage(t *testing.T) { defer stop() seedTestDB(t, db) - require.NoError(t, db.DeleteIdentityImage("thumbnail")) + require.NoError(t, db.DeleteIdentityImage(smallDimName)) - oii, err := db.GetIdentityImage("thumbnail") + oii, err := db.GetIdentityImage(smallDimName) require.NoError(t, err) require.Empty(t, oii) } diff --git a/images/main.go b/images/main.go index 493b9769f..8ae01eea9 100644 --- a/images/main.go +++ b/images/main.go @@ -31,7 +31,7 @@ func GenerateIdentityImages(filepath string, aX, aY, bX, bY int) ([]*IdentityIma } ii := &IdentityImage{ - Type: ResizeDimensionToName[s], + Name: ResizeDimensionToName[s], Payload: bb.Bytes(), Width: rImg.Bounds().Dx(), Height: rImg.Bounds().Dy(),