Skip to content

Commit

Permalink
chore: Update common version and add unknown types to logic.
Browse files Browse the repository at this point in the history
  • Loading branch information
ldmi3i committed Sep 9, 2022
1 parent e6901b6 commit 2902e89
Show file tree
Hide file tree
Showing 3 changed files with 173 additions and 2 deletions.
10 changes: 8 additions & 2 deletions internal/apispecdoc/asdRepository.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,12 @@ import (
"gorm.io/gorm/clause"
)

// AsdPage here represents a fixed type.
// It's just overwork for gomock i.e. it can't generate a mock of interface with generics used in it.
// Issue closed https://github.com/golang/mock/issues/621 - awaiting for gomock version 1.7.0.
// TODO delete on gomock 1.7.0 version released
type AsdPage = dto.Page[*ApiSpecDoc]

//go:generate mockgen -source=asdRepository.go -destination=./mocks/asdRepository.go
type AsdRepository interface {
//Save saves new ApiSpecDoc entity to the database
Expand All @@ -26,7 +32,7 @@ type AsdRepository interface {
FindByUrl(ctx context.Context, url string) (*ApiSpecDoc, error)
//SearchShort returns a slice of ApiSpecDoc without nested elements that match search string
//The search goes by title and url fields
SearchShort(ctx context.Context, search string, page dto.PageRequest) (dto.Page[*ApiSpecDoc], error)
SearchShort(ctx context.Context, search string, page dto.PageRequest) (AsdPage, error)
}

type AsdRepositoryImpl struct {
Expand Down Expand Up @@ -109,7 +115,7 @@ func (r *AsdRepositoryImpl) FindByUrl(ctx context.Context, url string) (*ApiSpec
}
}

func (r *AsdRepositoryImpl) SearchShort(ctx context.Context, search string, page dto.PageRequest) (dto.Page[*ApiSpecDoc], error) {
func (r *AsdRepositoryImpl) SearchShort(ctx context.Context, search string, page dto.PageRequest) (AsdPage, error) {
var specDocs dto.Page[*ApiSpecDoc]
err := r.db.WithContext(ctx).Limit(page.Page).Where("title LIKE ?", "%"+search+"%").Or("url LIKE ?", "%"+search+"%").Find(&specDocs).Error
if err != nil {
Expand Down
140 changes: 140 additions & 0 deletions internal/apispecdoc/mocks/asdRepository.go

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

25 changes: 25 additions & 0 deletions internal/apispecdoc/service_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package apispecdoc

import (
"github.com/stretchr/testify/assert"
"testing"
)

func TestServiceImpl_Search(t *testing.T) {
//ctrl := gomock.NewController(t)
//log := mock_logger.NewMockLogger(ctrl)
//repo := mock_api
//service := ServiceImpl{
// log: nil,
// asdRepo: nil,
//}
assert.True(t, false, "implement me please")
}

func TestServiceImpl_Get(t *testing.T) {
assert.True(t, false, "implement me please")
}

func TestServiceImpl_Save(t *testing.T) {
assert.True(t, false, "implement me please")
}

0 comments on commit 2902e89

Please sign in to comment.