Skip to content
This repository has been archived by the owner on Dec 11, 2024. It is now read-only.

Commit

Permalink
refactor: remove getChannelByName
Browse files Browse the repository at this point in the history
  • Loading branch information
Daaaai0809 committed Mar 30, 2024
1 parent c691966 commit 0861016
Show file tree
Hide file tree
Showing 4 changed files with 0 additions and 72 deletions.
1 change: 0 additions & 1 deletion server/domain/repository/channel_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import (

type IChannelRepository interface {
FindByID(ctx context.Context, id uint64) (*model.Channel, error)
FindByName(ctx context.Context, name string) ([]*model.Channel, error)
Create(ctx context.Context, channel *model.Channel) (uint64, error)
Update(ctx context.Context, channel *model.Channel) error
Delete(ctx context.Context, id uint64) error
Expand Down
10 changes: 0 additions & 10 deletions server/infra/mysql/channel_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,16 +30,6 @@ func (r *ChannelRepository) FindByID(ctx context.Context, id uint64) (*model.Cha
return &channel, nil
}

func (r *ChannelRepository) FindByName(ctx context.Context, name string) ([]*model.Channel, error) {
var channels []*model.Channel

if err := r.db.NewSelect().Model(&channels).Where("name LIKE ?", "%"+name+"%").Relation("Users").Scan(ctx); err != nil {
return nil, err
}

return channels, nil
}

func (r *ChannelRepository) Create(ctx context.Context, channel *model.Channel) (uint64, error) {
r.mu.Lock()
defer r.mu.Unlock()
Expand Down
18 changes: 0 additions & 18 deletions server/usecase/channel_interactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -68,24 +68,6 @@ func (i *ChannelInteractor) GetChannelByID(ctx context.Context, id uint64) (*pre
return i.channelPresenter.GenerateGetChannelByIdResponse(channel.ToChannelEntity()), nil
}

func (i *ChannelInteractor) GetChannelsByName(ctx context.Context, name string) (*presenter.GetChannelsByNameResponse, error) {
channels, err := i.channelRepository.FindByName(ctx, name)
if err != nil {
if err == sql.ErrNoRows {
return i.channelPresenter.GenerateGetChannelsByNameResponse([]*entity.Channel{}), nil
}

return i.channelPresenter.GenerateGetChannelsByNameResponse([]*entity.Channel{}), err
}

entitiedChannels := make([]*entity.Channel, len(channels))
for i, channel := range channels {
entitiedChannels[i] = channel.ToChannelEntity()
}

return i.channelPresenter.GenerateGetChannelsByNameResponse(entitiedChannels), nil
}

func (i *ChannelInteractor) CreateChannel(ctx context.Context, name string, userId uint64) error {
id, err := i.channelRepository.Create(ctx, &model.Channel{Name: name})
if err != nil {
Expand Down
43 changes: 0 additions & 43 deletions server/usecase/channel_interactor_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -116,49 +116,6 @@ func TestChannelInteractor_Failed_GetChannelByID(t *testing.T) {
assert.Equal(t, expectedChannel, result)
}

func TestChannelInteractor_Success_GetChannelsByName(t *testing.T) {
ctx := context.Background()
repo := &mockChannelRepository{}
repoChannelUser := &mockChannelUsersRepository{}
repoChannelToChannels := &mockChannelToChannelsRepository{}
repoUser := &mockUserRepository{}
pre := &mockChannelPresenter{}

interactor := usecase.NewChannelInteractor(repo, repoChannelUser, repoChannelToChannels, repoUser, pre)

expectedChannels := []*presenter.Channel{
{
ID: 1,
Name: "test-channel",
},
}

result, err := interactor.GetChannelsByName(ctx, "test-channel")
assert.NoError(t, err)
assert.Equal(t, expectedChannels, result.Channels)
}

func TestChannelInteractor_Failed_GetChannelsByName(t *testing.T) {
ctx := context.Background()
repo := &mockChannelRepository{}
repoChannelUser := &mockChannelUsersRepository{}
repoChannelToChannels := &mockChannelToChannelsRepository{}
repoUser := &mockUserRepository{}
pre := &mockChannelPresenter{}

ctx = context.WithValue(ctx, FindByNameFailedValue, true)

interactor := usecase.NewChannelInteractor(repo, repoChannelUser, repoChannelToChannels, repoUser, pre)

expectedChannels := &presenter.GetChannelsByNameResponse{
Channels: []*presenter.Channel{},
}

result, err := interactor.GetChannelsByName(ctx, "test-channel")
assert.Error(t, err)
assert.Equal(t, expectedChannels, result)
}

func TestChannelInteractor_Success_CreateChannel(t *testing.T) {
ctx := context.Background()
repo := &mockChannelRepository{}
Expand Down

0 comments on commit 0861016

Please sign in to comment.