ilk
This commit is contained in:
32
svc/repository/user_role_repo.go
Normal file
32
svc/repository/user_role_repo.go
Normal file
@@ -0,0 +1,32 @@
|
||||
package repository
|
||||
|
||||
import "database/sql"
|
||||
|
||||
type UserRole struct {
|
||||
RoleID int
|
||||
RoleCode string
|
||||
IsSystem bool
|
||||
}
|
||||
|
||||
// repository/user_roles.go
|
||||
// repository/user_roles.go
|
||||
func GetUserRolesByUserID(db *sql.DB, userID int64) ([]int, error) {
|
||||
rows, err := db.Query(`
|
||||
SELECT role_id
|
||||
FROM dfrole_usr
|
||||
WHERE mk_dfusr_id = $1
|
||||
`, userID)
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
defer rows.Close()
|
||||
|
||||
var roles []int
|
||||
for rows.Next() {
|
||||
var rid int
|
||||
if err := rows.Scan(&rid); err == nil {
|
||||
roles = append(roles, rid)
|
||||
}
|
||||
}
|
||||
return roles, nil
|
||||
}
|
||||
Reference in New Issue
Block a user