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

Commit

Permalink
refactor: Getの返り値がnullにならないよう変更
Browse files Browse the repository at this point in the history
  • Loading branch information
Daaaai0809 committed Dec 29, 2023
1 parent 2b25daf commit 778720e
Showing 1 changed file with 12 additions and 4 deletions.
16 changes: 12 additions & 4 deletions server/usecase/channel_interactor.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,14 @@ func (i *ChannelInteractor) GetAllChannels(ctx context.Context, userId uint64) (
channels, err := i.userRepository.FindChannelsByUserID(ctx, userId)
if err != nil {
if err == sql.ErrNoRows {
return &presenter.GetAllChannelsResponse{}, nil
return &presenter.GetAllChannelsResponse{
Channels: []*presenter.Channel{},
}, nil
}

return &presenter.GetAllChannelsResponse{}, err
return &presenter.GetAllChannelsResponse{
Channels: []*presenter.Channel{},
}, err
}

entitiedChannels := make([]*entity.Channel, len(channels))
Expand All @@ -58,7 +62,9 @@ func (i *ChannelInteractor) GetAllChannels(ctx context.Context, userId uint64) (
func (i *ChannelInteractor) GetChannelByID(ctx context.Context, id uint64) (*presenter.GetChannelByIdResponse, error) {
channel, err := i.channelRepository.FindByID(ctx, id)
if err != nil {
return &presenter.GetChannelByIdResponse{}, err
return &presenter.GetChannelByIdResponse{
Channel: &presenter.ChannelDetail{},
}, err
}

return i.channelPresenter.GenerateGetChannelByIdResponse(channel.ToChannelEntity()), nil
Expand All @@ -67,7 +73,9 @@ func (i *ChannelInteractor) GetChannelByID(ctx context.Context, id uint64) (*pre
func (i *ChannelInteractor) GetChannelsByName(ctx context.Context, name string) (*presenter.GetChannelsByNameResponse, error) {
channels, err := i.channelRepository.FindByName(ctx, name)
if err != nil {
return &presenter.GetChannelsByNameResponse{}, err
return &presenter.GetChannelsByNameResponse{
Channels: []*presenter.Channel{},
}, err
}

entitiedChannels := make([]*entity.Channel, len(channels))
Expand Down

0 comments on commit 778720e

Please sign in to comment.