Skip to content

Commit 346a30f

Browse files
fix: scan error
1 parent 48c5c8b commit 346a30f

File tree

2 files changed

+49
-15
lines changed

2 files changed

+49
-15
lines changed

data/seed_users.json

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
"is_active": true,
1010
"role": "admin",
1111
"avatar_url": "https://i.pravatar.cc/150?img=3",
12-
"bio": "Just a regular John Doe.",
12+
"bio": "Bildiğiniz John Doe.",
1313
"location": "Ağrı, Turkey",
14-
"favorite_genre": [ "Science Fiction", "Fantasy" ],
14+
"favorite_genre": [ "Bilim Kurgu", "Fantastik" ],
1515
"reading_goal": 20
1616
},
1717
{
@@ -23,9 +23,9 @@
2323
"is_active": true,
2424
"role": "user",
2525
"avatar_url": "https://i.pravatar.cc/150?img=5",
26-
"bio": "Avid reader and book lover.",
27-
"location": "Istanbul, Turkey",
28-
"favorite_genre": [ "Mystery", "Romance" ],
26+
"bio": "Kitap kurdu ve kitap sever.",
27+
"location": "İstanbul, Turkey",
28+
"favorite_genre": [ "Gizem", "Romantik" ],
2929
"reading_goal": 15
3030
},
3131
{
@@ -37,9 +37,9 @@
3737
"is_active": true,
3838
"role": "user",
3939
"avatar_url": "https://i.pravatar.cc/150?img=10",
40-
"bio": "Just a test user.",
40+
"bio": "Sadece bir test kullanıcısı.",
4141
"location": "Ankara, Turkey",
42-
"favorite_genre": [ "Non-Fiction", "Biography" ],
42+
"favorite_genre": [ "Kurgu Dışı", "Biyografi" ],
4343
"reading_goal": 10
4444
},
4545
{
@@ -51,9 +51,9 @@
5151
"is_active": true,
5252
"role": "user",
5353
"avatar_url": "https://i.pravatar.cc/150?img=15",
54-
"bio": "Another test user.",
55-
"location": "Izmir, Turkey",
56-
"favorite_genre": [ "Horror", "Thriller" ],
54+
"bio": "Başka bir test kullanıcısı.",
55+
"location": "İzmir, Turkey",
56+
"favorite_genre": [ "Korku", "Gerilim" ],
5757
"reading_goal": 5
5858
},
5959
{
@@ -65,9 +65,9 @@
6565
"is_active": false,
6666
"role": "user",
6767
"avatar_url": "https://i.pravatar.cc/150?img=20",
68-
"bio": "Inactive user account.",
68+
"bio": "Aktif olmayan bir kullanıcı.",
6969
"location": "Bursa, Turkey",
70-
"favorite_genre": [ "Poetry", "Drama" ],
70+
"favorite_genre": [ "Şiir", "Drama" ],
7171
"reading_goal": 0
7272
},
7373
{
@@ -79,9 +79,9 @@
7979
"is_active": true,
8080
"role": "admin",
8181
"avatar_url": "https://i.pravatar.cc/150?img=25",
82-
"bio": "Administrator of the platform.",
82+
"bio": "Platformun yöneticisi.",
8383
"location": "Metropolis, Earth",
84-
"favorite_genre": [ "All" ],
84+
"favorite_genre": [ "Roman" ],
8585
"reading_goal": 50
8686
},
8787
{
@@ -95,7 +95,7 @@
9595
"avatar_url": "https://i.pravatar.cc/150?img=30",
9696
"bio": "Quality Assurance Tester.",
9797
"location": "Testville, Testland",
98-
"favorite_genre": [ "Technical", "Educational" ],
98+
"favorite_genre": [ "Teknoloji", "Eğitim" ],
9999
"reading_goal": 25
100100
}
101101
]

internal/models/user.go

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package models
22

33
import (
4+
"database/sql/driver"
5+
"encoding/json"
46
"time"
57

68
"github.com/lib/pq"
@@ -9,6 +11,38 @@ import (
911

1012
type UserPreferences map[string]interface{}
1113

14+
func (up *UserPreferences) Scan(value interface{}) error {
15+
if value == nil {
16+
*up = make(UserPreferences)
17+
return nil
18+
}
19+
20+
var bytes []byte
21+
switch v := value.(type) {
22+
case []byte:
23+
bytes = v
24+
case string:
25+
bytes = []byte(v)
26+
default:
27+
*up = make(UserPreferences)
28+
return nil
29+
}
30+
31+
if len(bytes) == 0 {
32+
*up = make(UserPreferences)
33+
return nil
34+
}
35+
36+
return json.Unmarshal(bytes, up)
37+
}
38+
39+
func (up UserPreferences) Value() (driver.Value, error) {
40+
if len(up) == 0 {
41+
return "{}", nil
42+
}
43+
return json.Marshal(up)
44+
}
45+
1246
const (
1347
PREF_SHOW_LOCATION = "privacy.show_location"
1448
PREF_SHOW_LAST_SEEN = "privacy.show_last_seen"

0 commit comments

Comments
 (0)