@@ -27,22 +27,25 @@ func (err ErrUserRedirectNotExist) Error() string {
27
27
return fmt .Sprintf ("user redirect does not exist [name: %s]" , err .Name )
28
28
}
29
29
30
- // UserRedirect represents that a user name should be redirected to another
31
- //nolint
32
- type UserRedirect struct { //nolint
30
+ // Redirect represents that a user name should be redirected to another
31
+ type Redirect struct {
33
32
ID int64 `xorm:"pk autoincr"`
34
33
LowerName string `xorm:"UNIQUE(s) INDEX NOT NULL"`
35
34
RedirectUserID int64 // userID to redirect to
36
35
}
37
36
37
+ func (Redirect ) TableName () string {
38
+ return "user_redirect"
39
+ }
40
+
38
41
func init () {
39
- db .RegisterModel (new (UserRedirect ))
42
+ db .RegisterModel (new (Redirect ))
40
43
}
41
44
42
45
// LookupUserRedirect look up userID if a user has a redirect name
43
46
func LookupUserRedirect (userName string ) (int64 , error ) {
44
47
userName = strings .ToLower (userName )
45
- redirect := & UserRedirect {LowerName : userName }
48
+ redirect := & Redirect {LowerName : userName }
46
49
if has , err := db .GetEngine (db .DefaultContext ).Get (redirect ); err != nil {
47
50
return 0 , err
48
51
} else if ! has {
@@ -60,7 +63,7 @@ func NewUserRedirect(ctx context.Context, ID int64, oldUserName, newUserName str
60
63
return err
61
64
}
62
65
63
- return db .Insert (ctx , & UserRedirect {
66
+ return db .Insert (ctx , & Redirect {
64
67
LowerName : oldUserName ,
65
68
RedirectUserID : ID ,
66
69
})
@@ -70,6 +73,6 @@ func NewUserRedirect(ctx context.Context, ID int64, oldUserName, newUserName str
70
73
// anything else
71
74
func DeleteUserRedirect (ctx context.Context , userName string ) error {
72
75
userName = strings .ToLower (userName )
73
- _ , err := db .GetEngine (ctx ).Delete (& UserRedirect {LowerName : userName })
76
+ _ , err := db .GetEngine (ctx ).Delete (& Redirect {LowerName : userName })
74
77
return err
75
78
}
0 commit comments