Skip to content

Commit 8caccd0

Browse files
committed
chore: Update common version and add unknown types to logic.
1 parent c2fbb55 commit 8caccd0

File tree

6 files changed

+181
-10
lines changed

6 files changed

+181
-10
lines changed

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ require (
88
github.com/kelseyhightower/envconfig v1.4.0
99
github.com/lib/pq v1.10.2
1010
github.com/pkg/errors v0.9.1
11-
github.com/rog-golang-buddies/api_hub_common v0.1.2
11+
github.com/rog-golang-buddies/api_hub_common v0.1.3
1212
github.com/stretchr/testify v1.8.0
1313
github.com/testcontainers/testcontainers-go v0.13.0
1414
github.com/wagslane/go-rabbitmq v0.10.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,8 +1008,8 @@ github.com/rabbitmq/amqp091-go v1.4.0 h1:T2G+J9W9OY4p64Di23J6yH7tOkMocgnESvYeBju
10081008
github.com/rabbitmq/amqp091-go v1.4.0/go.mod h1:JsV0ofX5f1nwOGafb8L5rBItt9GyhfQfcJj+oyz0dGg=
10091009
github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
10101010
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
1011-
github.com/rog-golang-buddies/api_hub_common v0.1.2 h1:2a8xeVXbh2fodMrqb1YKY+Tsa97E5J+k2HeMj+qwLMQ=
1012-
github.com/rog-golang-buddies/api_hub_common v0.1.2/go.mod h1:lK3L/e21s8rYwOZYrSrnP3yaAST3fgKlh00WW6igI0s=
1011+
github.com/rog-golang-buddies/api_hub_common v0.1.3 h1:lUml9+Ln3oP9OZEMaNKwhU42KZLUaL1MGpjsoDsIBjc=
1012+
github.com/rog-golang-buddies/api_hub_common v0.1.3/go.mod h1:lK3L/e21s8rYwOZYrSrnP3yaAST3fgKlh00WW6igI0s=
10131013
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
10141014
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
10151015
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=

internal/apispecdoc/asdRepository.go

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,12 @@ import (
1010
"gorm.io/gorm/clause"
1111
)
1212

13+
// AsdPage here represents a fixed type.
14+
// It's just overwork for gomock i.e. it can't generate a mock of interface with generics used in it.
15+
// Issue closed https://github.com/golang/mock/issues/621 - awaiting for gomock version 1.7.0.
16+
// TODO delete on gomock 1.7.0 version released
17+
type AsdPage = dto.Page[*ApiSpecDoc]
18+
1319
//go:generate mockgen -source=asdRepository.go -destination=./mocks/asdRepository.go
1420
type AsdRepository interface {
1521
//Save saves new ApiSpecDoc entity to the database
@@ -26,7 +32,7 @@ type AsdRepository interface {
2632
FindByUrl(ctx context.Context, url string) (*ApiSpecDoc, error)
2733
//SearchShort returns a slice of ApiSpecDoc without nested elements that match search string
2834
//The search goes by title and url fields
29-
SearchShort(ctx context.Context, search string, page dto.PageRequest) (dto.Page[*ApiSpecDoc], error)
35+
SearchShort(ctx context.Context, search string, page dto.PageRequest) (AsdPage, error)
3036
}
3137

3238
type AsdRepositoryImpl struct {
@@ -109,7 +115,7 @@ func (r *AsdRepositoryImpl) FindByUrl(ctx context.Context, url string) (*ApiSpec
109115
}
110116
}
111117

112-
func (r *AsdRepositoryImpl) SearchShort(ctx context.Context, search string, page dto.PageRequest) (dto.Page[*ApiSpecDoc], error) {
118+
func (r *AsdRepositoryImpl) SearchShort(ctx context.Context, search string, page dto.PageRequest) (AsdPage, error) {
113119
var specDocs dto.Page[*ApiSpecDoc]
114120
err := r.db.WithContext(ctx).Limit(page.Page).Where("title LIKE ?", "%"+search+"%").Or("url LIKE ?", "%"+search+"%").Find(&specDocs).Error
115121
if err != nil {

internal/apispecdoc/mocks/asdRepository.go

Lines changed: 140 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

internal/apispecdoc/service.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ var methodTypeMap = map[string]apispecproto.MethodType{
3939
}
4040

4141
var schemaTypeMap = map[apispecdoc.SchemaType]apispecproto.SchemaType{
42-
apispecdoc.Unknown: apispecproto.SchemaType_UNKNOWN,
42+
apispecdoc.Unknown: apispecproto.SchemaType_UNKNOWN_SCHEMA,
4343
apispecdoc.NotDefined: apispecproto.SchemaType_NOT_DEFINED,
4444
apispecdoc.Integer: apispecproto.SchemaType_INTEGER,
4545
apispecdoc.Boolean: apispecproto.SchemaType_BOOLEAN,
@@ -389,29 +389,29 @@ func paramTypeToResponse(pt apispecdoc.ParameterType) apispecproto.ParameterType
389389
if ok {
390390
return res
391391
}
392-
return apispecproto.ParameterType_QUERY //TODO unknown type here for default case
392+
return apispecproto.ParameterType_UNKNOWN_PARAM
393393
}
394394

395395
func methodTypeToResponse(mt string) apispecproto.MethodType {
396396
res, ok := methodTypeMap[mt]
397397
if ok {
398398
return res
399399
}
400-
return apispecproto.MethodType_GET //TODO unknown type here for default case
400+
return apispecproto.MethodType_UNKNOWN_METHOD
401401
}
402402

403403
func schemaTypeToResponse(st apispecdoc.SchemaType) apispecproto.SchemaType {
404404
res, ok := schemaTypeMap[st]
405405
if ok {
406406
return res
407407
}
408-
return apispecproto.SchemaType_UNKNOWN
408+
return apispecproto.SchemaType_UNKNOWN_SCHEMA
409409
}
410410

411411
func apiTypeToResponse(asdT string) apispecproto.Type {
412412
res, ok := asdTypeMap[asdT]
413413
if ok {
414414
return res
415415
}
416-
return apispecproto.Type_OPEN_API
416+
return apispecproto.Type_UNKNOWN_API
417417
}

internal/apispecdoc/service_test.go

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package apispecdoc
2+
3+
import (
4+
"github.com/stretchr/testify/assert"
5+
"testing"
6+
)
7+
8+
func TestServiceImpl_Search(t *testing.T) {
9+
//ctrl := gomock.NewController(t)
10+
//log := mock_logger.NewMockLogger(ctrl)
11+
//repo := mock_api
12+
//service := ServiceImpl{
13+
// log: nil,
14+
// asdRepo: nil,
15+
//}
16+
assert.True(t, false, "implement me please")
17+
}
18+
19+
func TestServiceImpl_Get(t *testing.T) {
20+
assert.True(t, false, "implement me please")
21+
}
22+
23+
func TestServiceImpl_Save(t *testing.T) {
24+
assert.True(t, false, "implement me please")
25+
}

0 commit comments

Comments
 (0)