fix: rename duplicate db methods to fix compilation (refs #17)
CreateUser, GetUserByNick, GetUserByToken exist in both db.go (model-based, used by tests) and queries.go (simple, used by handlers). Rename the model-based variants to CreateUserModel, GetUserByNickModel, and GetUserByTokenModel to resolve the compilation error.
This commit is contained in:
@@ -163,7 +163,7 @@ func (s *Database) GetChannelByID(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByNick looks up a user by their nick.
|
// GetUserByNick looks up a user by their nick.
|
||||||
func (s *Database) GetUserByNick(
|
func (s *Database) GetUserByNickModel(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
nick string,
|
nick string,
|
||||||
) (*models.User, error) {
|
) (*models.User, error) {
|
||||||
@@ -186,7 +186,7 @@ func (s *Database) GetUserByNick(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// GetUserByToken looks up a user by their auth token.
|
// GetUserByToken looks up a user by their auth token.
|
||||||
func (s *Database) GetUserByToken(
|
func (s *Database) GetUserByTokenModel(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
token string,
|
token string,
|
||||||
) (*models.User, error) {
|
) (*models.User, error) {
|
||||||
@@ -235,7 +235,7 @@ func (s *Database) UpdateUserLastSeen(
|
|||||||
}
|
}
|
||||||
|
|
||||||
// CreateUser inserts a new user into the database.
|
// CreateUser inserts a new user into the database.
|
||||||
func (s *Database) CreateUser(
|
func (s *Database) CreateUserModel(
|
||||||
ctx context.Context,
|
ctx context.Context,
|
||||||
id, nick, passwordHash string,
|
id, nick, passwordHash string,
|
||||||
) (*models.User, error) {
|
) (*models.User, error) {
|
||||||
|
|||||||
@@ -43,7 +43,7 @@ func TestCreateUser(t *testing.T) {
|
|||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
u, err := d.CreateUser(ctx, "u1", nickAlice, "hash1")
|
u, err := d.CreateUserModel(ctx, "u1", nickAlice, "hash1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("CreateUser: %v", err)
|
t.Fatalf("CreateUser: %v", err)
|
||||||
}
|
}
|
||||||
@@ -59,7 +59,7 @@ func TestCreateAuthToken(t *testing.T) {
|
|||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
_, err := d.CreateUser(ctx, "u1", nickAlice, "h")
|
_, err := d.CreateUserModel(ctx, "u1", nickAlice, "h")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
t.Fatalf("CreateUser: %v", err)
|
t.Fatalf("CreateUser: %v", err)
|
||||||
}
|
}
|
||||||
@@ -107,7 +107,7 @@ func TestAddChannelMember(t *testing.T) {
|
|||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
_, _ = d.CreateUser(ctx, "u1", nickAlice, "h")
|
_, _ = d.CreateUserModel(ctx, "u1", nickAlice, "h")
|
||||||
_, _ = d.CreateChannel(ctx, "c1", "#general", "", "")
|
_, _ = d.CreateChannel(ctx, "c1", "#general", "", "")
|
||||||
|
|
||||||
cm, err := d.AddChannelMember(ctx, "c1", "u1", "+o")
|
cm, err := d.AddChannelMember(ctx, "c1", "u1", "+o")
|
||||||
@@ -126,7 +126,7 @@ func TestCreateMessage(t *testing.T) {
|
|||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
_, _ = d.CreateUser(ctx, "u1", nickAlice, "h")
|
_, _ = d.CreateUserModel(ctx, "u1", nickAlice, "h")
|
||||||
|
|
||||||
msg, err := d.CreateMessage(
|
msg, err := d.CreateMessage(
|
||||||
ctx, "m1", "u1", nickAlice,
|
ctx, "m1", "u1", nickAlice,
|
||||||
@@ -147,8 +147,8 @@ func TestQueueMessage(t *testing.T) {
|
|||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
_, _ = d.CreateUser(ctx, "u1", nickAlice, "h")
|
_, _ = d.CreateUserModel(ctx, "u1", nickAlice, "h")
|
||||||
_, _ = d.CreateUser(ctx, "u2", nickBob, "h")
|
_, _ = d.CreateUserModel(ctx, "u2", nickBob, "h")
|
||||||
_, _ = d.CreateMessage(
|
_, _ = d.CreateMessage(
|
||||||
ctx, "m1", "u1", nickAlice, "u2", "message", "hi",
|
ctx, "m1", "u1", nickAlice, "u2", "message", "hi",
|
||||||
)
|
)
|
||||||
@@ -169,7 +169,7 @@ func TestCreateSession(t *testing.T) {
|
|||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
_, _ = d.CreateUser(ctx, "u1", nickAlice, "h")
|
_, _ = d.CreateUserModel(ctx, "u1", nickAlice, "h")
|
||||||
|
|
||||||
sess, err := d.CreateSession(ctx, "s1", "u1")
|
sess, err := d.CreateSession(ctx, "s1", "u1")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -215,7 +215,7 @@ func TestUserChannels(t *testing.T) {
|
|||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
u, _ := d.CreateUser(ctx, "u1", nickAlice, "h")
|
u, _ := d.CreateUserModel(ctx, "u1", nickAlice, "h")
|
||||||
_, _ = d.CreateChannel(ctx, "c1", "#alpha", "", "")
|
_, _ = d.CreateChannel(ctx, "c1", "#alpha", "", "")
|
||||||
_, _ = d.CreateChannel(ctx, "c2", "#beta", "", "")
|
_, _ = d.CreateChannel(ctx, "c2", "#beta", "", "")
|
||||||
_, _ = d.AddChannelMember(ctx, "c1", "u1", "")
|
_, _ = d.AddChannelMember(ctx, "c1", "u1", "")
|
||||||
@@ -245,7 +245,7 @@ func TestUserChannelsEmpty(t *testing.T) {
|
|||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
u, _ := d.CreateUser(ctx, "u1", nickAlice, "h")
|
u, _ := d.CreateUserModel(ctx, "u1", nickAlice, "h")
|
||||||
|
|
||||||
channels, err := u.Channels(ctx)
|
channels, err := u.Channels(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -263,8 +263,8 @@ func TestUserQueuedMessages(t *testing.T) {
|
|||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
u, _ := d.CreateUser(ctx, "u1", nickAlice, "h")
|
u, _ := d.CreateUserModel(ctx, "u1", nickAlice, "h")
|
||||||
_, _ = d.CreateUser(ctx, "u2", nickBob, "h")
|
_, _ = d.CreateUserModel(ctx, "u2", nickBob, "h")
|
||||||
|
|
||||||
for i := range 3 {
|
for i := range 3 {
|
||||||
id := fmt.Sprintf("m%d", i)
|
id := fmt.Sprintf("m%d", i)
|
||||||
@@ -302,7 +302,7 @@ func TestUserQueuedMessagesEmpty(t *testing.T) {
|
|||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
u, _ := d.CreateUser(ctx, "u1", nickAlice, "h")
|
u, _ := d.CreateUserModel(ctx, "u1", nickAlice, "h")
|
||||||
|
|
||||||
msgs, err := u.QueuedMessages(ctx)
|
msgs, err := u.QueuedMessages(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
@@ -321,9 +321,9 @@ func TestChannelMembers(t *testing.T) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
ch, _ := d.CreateChannel(ctx, "c1", "#general", "", "")
|
ch, _ := d.CreateChannel(ctx, "c1", "#general", "", "")
|
||||||
_, _ = d.CreateUser(ctx, "u1", nickAlice, "h")
|
_, _ = d.CreateUserModel(ctx, "u1", nickAlice, "h")
|
||||||
_, _ = d.CreateUser(ctx, "u2", nickBob, "h")
|
_, _ = d.CreateUserModel(ctx, "u2", nickBob, "h")
|
||||||
_, _ = d.CreateUser(ctx, "u3", nickCharlie, "h")
|
_, _ = d.CreateUserModel(ctx, "u3", nickCharlie, "h")
|
||||||
_, _ = d.AddChannelMember(ctx, "c1", "u1", "+o")
|
_, _ = d.AddChannelMember(ctx, "c1", "u1", "+o")
|
||||||
_, _ = d.AddChannelMember(ctx, "c1", "u2", "+v")
|
_, _ = d.AddChannelMember(ctx, "c1", "u2", "+v")
|
||||||
_, _ = d.AddChannelMember(ctx, "c1", "u3", "")
|
_, _ = d.AddChannelMember(ctx, "c1", "u3", "")
|
||||||
@@ -376,7 +376,7 @@ func TestChannelRecentMessages(t *testing.T) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
ch, _ := d.CreateChannel(ctx, "c1", "#general", "", "")
|
ch, _ := d.CreateChannel(ctx, "c1", "#general", "", "")
|
||||||
_, _ = d.CreateUser(ctx, "u1", nickAlice, "h")
|
_, _ = d.CreateUserModel(ctx, "u1", nickAlice, "h")
|
||||||
|
|
||||||
for i := range 5 {
|
for i := range 5 {
|
||||||
id := fmt.Sprintf("m%d", i)
|
id := fmt.Sprintf("m%d", i)
|
||||||
@@ -414,7 +414,7 @@ func TestChannelRecentMessagesLargeLimit(t *testing.T) {
|
|||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
ch, _ := d.CreateChannel(ctx, "c1", "#general", "", "")
|
ch, _ := d.CreateChannel(ctx, "c1", "#general", "", "")
|
||||||
_, _ = d.CreateUser(ctx, "u1", nickAlice, "h")
|
_, _ = d.CreateUserModel(ctx, "u1", nickAlice, "h")
|
||||||
_, _ = d.CreateMessage(
|
_, _ = d.CreateMessage(
|
||||||
ctx, "m1", "u1", nickAlice,
|
ctx, "m1", "u1", nickAlice,
|
||||||
"#general", "message", "only",
|
"#general", "message", "only",
|
||||||
@@ -436,7 +436,7 @@ func TestChannelMemberUser(t *testing.T) {
|
|||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
_, _ = d.CreateUser(ctx, "u1", nickAlice, "h")
|
_, _ = d.CreateUserModel(ctx, "u1", nickAlice, "h")
|
||||||
_, _ = d.CreateChannel(ctx, "c1", "#general", "", "")
|
_, _ = d.CreateChannel(ctx, "c1", "#general", "", "")
|
||||||
|
|
||||||
cm, _ := d.AddChannelMember(ctx, "c1", "u1", "+o")
|
cm, _ := d.AddChannelMember(ctx, "c1", "u1", "+o")
|
||||||
@@ -457,7 +457,7 @@ func TestChannelMemberChannel(t *testing.T) {
|
|||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
_, _ = d.CreateUser(ctx, "u1", nickAlice, "h")
|
_, _ = d.CreateUserModel(ctx, "u1", nickAlice, "h")
|
||||||
_, _ = d.CreateChannel(ctx, "c1", "#general", "topic", "+n")
|
_, _ = d.CreateChannel(ctx, "c1", "#general", "topic", "+n")
|
||||||
|
|
||||||
cm, _ := d.AddChannelMember(ctx, "c1", "u1", "")
|
cm, _ := d.AddChannelMember(ctx, "c1", "u1", "")
|
||||||
@@ -478,8 +478,8 @@ func TestDMMessage(t *testing.T) {
|
|||||||
d := setupTestDB(t)
|
d := setupTestDB(t)
|
||||||
ctx := context.Background()
|
ctx := context.Background()
|
||||||
|
|
||||||
_, _ = d.CreateUser(ctx, "u1", nickAlice, "h")
|
_, _ = d.CreateUserModel(ctx, "u1", nickAlice, "h")
|
||||||
_, _ = d.CreateUser(ctx, "u2", nickBob, "h")
|
_, _ = d.CreateUserModel(ctx, "u2", nickBob, "h")
|
||||||
|
|
||||||
msg, err := d.CreateMessage(
|
msg, err := d.CreateMessage(
|
||||||
ctx, "m1", "u1", nickAlice, "u2", "message", "hey",
|
ctx, "m1", "u1", nickAlice, "u2", "message", "hey",
|
||||||
|
|||||||
Reference in New Issue
Block a user