Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add API spec doc service #30

Draft
wants to merge 39 commits into
base: main
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
39 commits
Select commit Hold shift + click to select a range
e74f170
feat: initial commit
AlexS778 Aug 27, 2022
3e5c462
chore: change folder structure from dto to entity
AlexS778 Aug 28, 2022
2dc5b01
feat: create model.go generated file with models, create several gorm…
AlexS778 Aug 28, 2022
81cb417
feat: add db connection configuration
AlexS778 Aug 29, 2022
3ba476b
feat: created db relationships with gorm
AlexS778 Aug 29, 2022
02cea08
fix: remove unnecessary directories, move models to internal
AlexS778 Aug 30, 2022
401e018
fix: change relationship from has one to belongs to
AlexS778 Aug 31, 2022
f0afa90
chore: Denormalize request body and parameters.
ldmi3i Aug 31, 2022
8a8c74e
Merge pull request #24 from rog-golang-buddies/chore/denormalized_db
AlexS778 Aug 31, 2022
278c181
Merge pull request #25 from rog-golang-buddies/main
AlexS778 Sep 1, 2022
9545e14
chore: Add repository scaffold.
ldmi3i Sep 2, 2022
21989a1
chore: Fix foreign key naming.
ldmi3i Sep 2, 2022
1c71ff0
chore: Remove entity prefixes.
ldmi3i Sep 3, 2022
c6f3d47
feat: Remove entity prefixes. Fix migration. Fix tests.
ldmi3i Sep 4, 2022
575a691
chore: Add update logic.
ldmi3i Sep 4, 2022
2c92af5
fix: Update method logic. Add url check.
ldmi3i Sep 5, 2022
ca45a21
feat: create tests for Save, Delete, FindByID, SearchShort CRUD func…
AlexS778 Sep 5, 2022
d4e4c9a
fix: fix FindById and SearchShort tests
AlexS778 Sep 6, 2022
057e0f2
chore: Implement search ASD service method.
ldmi3i Sep 7, 2022
2480573
chore: Implement get service method.
ldmi3i Sep 7, 2022
fc9713a
Merge branch 'chore/repository_scaffold' into feature/asd_service
AlexS778 Sep 7, 2022
81cdb44
feat: implement Delete, FindById, SearchShort functions, add tests fo…
AlexS778 Sep 8, 2022
c2fbb55
chore: Switch parameter transform to maps.
ldmi3i Sep 7, 2022
8caccd0
chore: Update common version and add unknown types to logic.
ldmi3i Sep 7, 2022
1d9b128
chore: Fix doc.
ldmi3i Sep 9, 2022
8a4de6c
chore: API spec doc refactoring.
ldmi3i Sep 13, 2022
33200cf
Merge remote-tracking branch 'origin/main' into feature/asd_service
ldmi3i Sep 14, 2022
22a03ef
fix: fix SearchShort function, replace assert.True to assert. Equal
AlexS778 Sep 14, 2022
f3888e3
chore: Add search pageable condition.
ldmi3i Sep 15, 2022
ead3015
fix: add Offset, count to SearchShort function; change tests accordin…
AlexS778 Sep 15, 2022
c03d9bc
fix: convert int types properly.
AlexS778 Sep 15, 2022
124a5b6
fix: Fix page number.
ldmi3i Sep 15, 2022
13412b9
Merge remote-tracking branch 'origin/feature/asd_service' into featur…
AlexS778 Sep 15, 2022
c56b4f8
fix: change hard-coded SearchShort test.
AlexS778 Sep 15, 2022
a1e5bed
fix: change formatting; change from Page to PerPage limit in SearchSh…
AlexS778 Sep 15, 2022
eb49091
fix: Fix asd service page logic.
ldmi3i Sep 15, 2022
6cd3554
Merge remote-tracking branch 'origin/feature/asd_service' into featur…
AlexS778 Sep 15, 2022
c94ced6
fix: Fix ASD service return page number.
ldmi3i Sep 15, 2022
f19fbbd
fix: Fix fetch all nested elements on find by id.
ldmi3i Sep 16, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ require (
github.com/kelseyhightower/envconfig v1.4.0
github.com/lib/pq v1.10.7
github.com/pkg/errors v0.9.1
github.com/rog-golang-buddies/api_hub_common v0.1.5
github.com/rog-golang-buddies/api_hub_common v0.1.6
github.com/stretchr/testify v1.8.0
github.com/testcontainers/testcontainers-go v0.14.0
github.com/wagslane/go-rabbitmq v0.10.0
Expand Down
4 changes: 2 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -1040,8 +1040,8 @@ github.com/rabbitmq/amqp091-go v1.4.0 h1:T2G+J9W9OY4p64Di23J6yH7tOkMocgnESvYeBju
github.com/rabbitmq/amqp091-go v1.4.0/go.mod h1:JsV0ofX5f1nwOGafb8L5rBItt9GyhfQfcJj+oyz0dGg=
github.com/remyoudompheng/bigfft v0.0.0-20190728182440-6a916e37a237/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/remyoudompheng/bigfft v0.0.0-20200410134404-eec4a21b6bb0/go.mod h1:qqbHyh8v60DhA7CoWK5oRCqLrMHRGoxYCSS9EjAz6Eo=
github.com/rog-golang-buddies/api_hub_common v0.1.5 h1:GrgO5Iqh/CFhSMwWWTSIx9lcLz/340zt5R0ll7Ik7Yw=
github.com/rog-golang-buddies/api_hub_common v0.1.5/go.mod h1:lK3L/e21s8rYwOZYrSrnP3yaAST3fgKlh00WW6igI0s=
github.com/rog-golang-buddies/api_hub_common v0.1.6 h1:dnfqnyra0vXMZNT6pgNRUfyG25HZ3U/dLvMAS4MiYXM=
github.com/rog-golang-buddies/api_hub_common v0.1.6/go.mod h1:lK3L/e21s8rYwOZYrSrnP3yaAST3fgKlh00WW6igI0s=
github.com/rogpeppe/fastuuid v0.0.0-20150106093220-6724a57986af/go.mod h1:XWv6SoW27p1b0cqNHllgS5HIMJraePCO15w5zCzIWYg=
github.com/rogpeppe/fastuuid v1.2.0/go.mod h1:jVj6XXZzXRy/MSR5jhDC/2q6DgLz+nrA6LYCDYWNEvQ=
github.com/rogpeppe/go-internal v1.1.0/go.mod h1:M8bDsm7K2OlrFYOpmOWEs/qY81heoFRclV5y23lUDJ4=
Expand Down
15 changes: 15 additions & 0 deletions internal/apispecdoc/apiMethod.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
package apispecdoc

type ApiMethod struct {
ID uint `gorm:"primaryKey"`
Path string
Name string
Description string
Type string
Parameters string
Servers []*Server
RequestBody string
ExternalDoc *ExternalDoc
GroupID *uint
ApiSpecDocID *uint
}
19 changes: 19 additions & 0 deletions internal/apispecdoc/apiSpecDoc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package apispecdoc

import (
"time"

"gorm.io/gorm"
)

type ApiSpecDoc struct {
gorm.Model
Title string
Description string
Type string
Groups []*Group
ApiMethods []*ApiMethod
Md5sum string
Url string
FetchedAt time.Time
}
8 changes: 8 additions & 0 deletions internal/apispecdoc/externalDoc.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package apispecdoc

type ExternalDoc struct {
ID int `gorm:"primaryKey"`
Description string
URL string
ApiMethodID *uint
}
9 changes: 9 additions & 0 deletions internal/apispecdoc/group.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package apispecdoc

type Group struct {
ID uint `gorm:"primaryKey"`
Name string
Description string
ApiSpecDocID *uint
ApiMethods []*ApiMethod
}
140 changes: 140 additions & 0 deletions internal/apispecdoc/mock/repository.go

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

82 changes: 82 additions & 0 deletions internal/apispecdoc/mock/service.go

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

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

import (
"context"
"github.com/rog-golang-buddies/api-hub_storage-and-update-service/internal/dto"
)

// AsdPage here represents a fixed type.
// It's just workaround 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=repository.go -destination=./mock/repository.go -package=apispecdoc
type AsdRepository interface {
//Save saves new ApiSpecDoc entity to the database
Save(ctx context.Context, asd *ApiSpecDoc) (uint, error)
//Delete ApiSpecDoc soft, i.e. update deleted_at field and prevent the record from appearing in the requests
Delete(ctx context.Context, asd *ApiSpecDoc) error
//Update ApiSpecDoc by replacing all old nested elements with new ones
Update(ctx context.Context, asd *ApiSpecDoc) error
//FindById returns full ApiSpecDoc with all nested elements or nil if a such record does not exist
FindById(ctx context.Context, id uint) (*ApiSpecDoc, error)
//FindByHash returns ApiSpecDoc without nested elements or nil if nothing is found
FindByHash(ctx context.Context, hash string) (*ApiSpecDoc, error)
//FindByUrl returns ApiSpecDoc without nested elements or nil if nothing is found
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) (AsdPage, error)
}
8 changes: 8 additions & 0 deletions internal/apispecdoc/server.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package apispecdoc

type Server struct {
ID int `gorm:"primaryKey"`
URL string
Description string
ApiMethodID *uint
}
14 changes: 14 additions & 0 deletions internal/apispecdoc/service.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package apispecdoc

import (
"context"
"github.com/rog-golang-buddies/api_hub_common/apispecdoc"
"github.com/rog-golang-buddies/api_hub_common/apispecproto"
)

//go:generate mockgen -source=service.go -destination=./mock/service.go -package=apispecdoc
type Service interface {
Search(context.Context, *apispecproto.SearchRequest) (*apispecproto.SearchResponse, error)
Get(context.Context, *apispecproto.GetRequest) (*apispecproto.GetResponse, error)
Save(context.Context, *apispecdoc.ApiSpecDoc) (uint, error)
}
12 changes: 9 additions & 3 deletions internal/app.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ import (
"github.com/rog-golang-buddies/api-hub_storage-and-update-service/internal/queue"
"github.com/rog-golang-buddies/api-hub_storage-and-update-service/internal/queue/handler"
"github.com/rog-golang-buddies/api-hub_storage-and-update-service/internal/queue/publisher"
"github.com/rog-golang-buddies/api-hub_storage-and-update-service/internal/repository"

//"github.com/rog-golang-buddies/api-hub_storage-and-update-service/internal/repository"
"github.com/rog-golang-buddies/api-hub_storage-and-update-service/internal/service"
)

func Start() int {
Expand All @@ -26,11 +30,13 @@ func Start() int {
fmt.Println("error creating logger: ", err)
return 1
}
_, err = db.ConnectAndMigrate(log, &conf.DB)
DB, err := db.ConnectAndMigrate(log, &conf.DB)
if err != nil {
log.Error("error while db setup: ", err)
return 1
}
asdRepo := repository.NewASDRepository(DB)
asdServ := service.NewService(log, asdRepo, &conf.Page)

//initialize publisher connection to the queue
//this library assumes using one publisher and one consumer per application
Expand All @@ -49,7 +55,7 @@ func Start() int {
}
defer queue.CloseConsumer(consumer, log)

handl := handler.NewApiSpecDocHandler(pub, conf.Queue, log)
handl := handler.NewApiSpecDocHandler(pub, conf.Queue, log, asdServ)
listener := queue.NewListener()
err = listener.Start(ctx, consumer, &conf.Queue, handl)
if err != nil {
Expand All @@ -63,7 +69,7 @@ func Start() int {
log.Error("error creating grpc listener: ", err)
return 1
}
asdSrv := grpc.NewASDServer(log)
asdSrv := grpc.NewASDServer(log, asdServ)
errCh := grpc.StartServer(ctx, log, asdSrv, lst)

<-errCh
Expand Down
Loading