Skip to content

Commit 31c57c1

Browse files
committed
remove traces of mongo
1 parent 5945f22 commit 31c57c1

8 files changed

Lines changed: 32 additions & 33 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ The APIs will have separate directory based on the endpoint. Example `blog` and
4242
- [GitHub - afteracademy/goserve](https://github.com/afteracademy/goserve)
4343

4444
### Startup Flow
45-
cmd/main → startup/server → module, mongo, redis, router → api/[feature]/middlewares → api/[feature]/controller -> api/[feature]/service, authentication, authorization → handlers → sender
45+
cmd/main → startup/server → module, postgres, redis, router → api/[feature]/middlewares → api/[feature]/controller -> api/[feature]/service, authentication, authorization → handlers → sender
4646

4747
### API Structure
4848
```
@@ -72,7 +72,7 @@ Sample API
7272
9. **utils**: contains utility functions
7373

7474
**Helper/Optional Directories**
75-
1. **.extra**: mongo script for initialization inside docker, other web assets and documents
75+
1. **.extra**: postgres sql scripts for initialization inside docker, other web assets and documents
7676
2. **.github**: CI for tests
7777
3. **.tools**: api code, RSA key generator, and .env copier
7878
4. **.vscode**: editor config and debug launch settings

api/blog/dto/blog_public.go

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -7,20 +7,20 @@ import (
77
"github.com/afteracademy/goserve-example-api-server-postgres/api/user/dto"
88
"github.com/afteracademy/goserve/v2/utility"
99
"github.com/go-playground/validator/v10"
10-
"go.mongodb.org/mongo-driver/bson/primitive"
10+
"github.com/google/uuid"
1111
)
1212

1313
type BlogPublic struct {
14-
ID primitive.ObjectID `json:"id" binding:"required" validate:"required"`
15-
Title string `json:"title" validate:"required,min=3,max=500"`
16-
Description string `json:"description" validate:"required,min=3,max=2000"`
17-
Text string `json:"text" validate:"required,max=50000"`
18-
Slug string `json:"slug" validate:"required,min=3,max=200"`
19-
Author *dto.UserPublic `json:"author,omitempty" validate:"required,omitempty"`
20-
ImgURL *string `json:"imgUrl,omitempty" validate:"omitempty,uri,max=200"`
21-
Score *float64 `json:"score,omitempty" validate:"omitempty,min=0,max=1"`
22-
Tags *[]string `json:"tags,omitempty" validate:"omitempty,dive,uppercase"`
23-
PublishedAt *time.Time `json:"publishedAt,omitempty"`
14+
ID uuid.UUID `json:"id" binding:"required" validate:"required"`
15+
Title string `json:"title" validate:"required,min=3,max=500"`
16+
Description string `json:"description" validate:"required,min=3,max=2000"`
17+
Text string `json:"text" validate:"required,max=50000"`
18+
Slug string `json:"slug" validate:"required,min=3,max=200"`
19+
Author *dto.UserPublic `json:"author,omitempty" validate:"required,omitempty"`
20+
ImgURL *string `json:"imgUrl,omitempty" validate:"omitempty,uri,max=200"`
21+
Score *float64 `json:"score,omitempty" validate:"omitempty,min=0,max=1"`
22+
Tags *[]string `json:"tags,omitempty" validate:"omitempty,dive,uppercase"`
23+
PublishedAt *time.Time `json:"publishedAt,omitempty"`
2424
}
2525

2626
func EmptyBlogPublic() *BlogPublic {

api/blog/service.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ func NewService(db *pgxpool.Pool, store redis.Store, userService user.Service) S
4242
}
4343

4444
func (s *service) SetBlogDtoCacheById(blog *dto.BlogPublic) error {
45-
key := "blog_" + blog.ID.Hex()
45+
key := "blog_" + blog.ID.String()
4646
return s.publicBlogCache.SetJSON(key, blog, time.Duration(10*time.Minute))
4747
}
4848

api/blogs/dto/blog_Item.go

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,18 +6,18 @@ import (
66
"github.com/afteracademy/goserve-example-api-server-postgres/api/blog/model"
77
"github.com/afteracademy/goserve/v2/utility"
88
"github.com/go-playground/validator/v10"
9-
"go.mongodb.org/mongo-driver/bson/primitive"
9+
"github.com/google/uuid"
1010
)
1111

1212
type BlogItem struct {
13-
ID primitive.ObjectID `json:"id" binding:"required" validate:"required"`
14-
Title string `json:"title" validate:"required,min=3,max=500"`
15-
Description string `json:"description" validate:"required,min=3,max=2000"`
16-
Slug string `json:"slug" validate:"required,min=3,max=200"`
17-
ImgURL *string `json:"imgUrl,omitempty" validate:"omitempty,uri,max=200"`
18-
Score float64 `json:"score," validate:"required,min=0,max=1"`
19-
Tags []string `json:"tags" validate:"required,dive,uppercase"`
20-
PublishedAt *time.Time `json:"publishedAt,omitempty"`
13+
ID uuid.UUID `json:"id" binding:"required" validate:"required"`
14+
Title string `json:"title" validate:"required,min=3,max=500"`
15+
Description string `json:"description" validate:"required,min=3,max=2000"`
16+
Slug string `json:"slug" validate:"required,min=3,max=200"`
17+
ImgURL *string `json:"imgUrl,omitempty" validate:"omitempty,uri,max=200"`
18+
Score float64 `json:"score," validate:"required,min=0,max=1"`
19+
Tags []string `json:"tags" validate:"required,dive,uppercase"`
20+
PublishedAt *time.Time `json:"publishedAt,omitempty"`
2121
}
2222

2323
func NewBlogItem(blog *model.Blog) (*BlogItem, error) {

api/blogs/service.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@ import (
1313
"github.com/google/uuid"
1414
"github.com/jackc/pgx/v5"
1515
"github.com/jackc/pgx/v5/pgxpool"
16-
"go.mongodb.org/mongo-driver/bson"
1716
)
1817

1918
type Service interface {
@@ -222,7 +221,7 @@ func (s *service) GetSimilarBlogs(
222221
return items, nil
223222
}
224223

225-
func (s *service) getPublicPaginated(filter bson.M, p *coredto.Pagination) ([]*dto.BlogItem, error) {
224+
func (s *service) GetPublicPaginated(p *coredto.Pagination) ([]*dto.BlogItem, error) {
226225
query := `
227226
SELECT
228227
id,

api/contact/dto/message.go

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,14 @@ import (
55

66
"github.com/afteracademy/goserve/v2/utility"
77
"github.com/go-playground/validator/v10"
8-
"go.mongodb.org/mongo-driver/bson/primitive"
8+
"github.com/google/uuid"
99
)
1010

1111
type Message struct {
12-
ID primitive.ObjectID `json:"id" binding:"required"`
13-
Type string `json:"type" binding:"required"`
14-
Msg string `json:"msg" binding:"required"`
15-
CreatedAt time.Time `json:"createdAt" binding:"required"`
12+
ID uuid.UUID `json:"id" binding:"required"`
13+
Type string `json:"type" binding:"required"`
14+
Msg string `json:"msg" binding:"required"`
15+
CreatedAt time.Time `json:"createdAt" binding:"required"`
1616
}
1717

1818
func EmptyMessage() *Message {

api/contact/service.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -38,9 +38,9 @@ func (s *service) CreateMessage(
3838
query := `
3939
INSERT INTO messages (
4040
type,
41-
msg,
41+
msg
4242
)
43-
VALUES ($1, $2, $3, $4, $5)
43+
VALUES ($1, $2)
4444
RETURNING
4545
id,
4646
type,

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@ require (
1111
github.com/jackc/pgx/v5 v5.8.0
1212
github.com/spf13/viper v1.19.0
1313
github.com/stretchr/testify v1.11.1
14-
go.mongodb.org/mongo-driver v1.17.6
1514
golang.org/x/crypto v0.26.0
1615
)
1716

@@ -62,6 +61,7 @@ require (
6261
github.com/xdg-go/scram v1.1.2 // indirect
6362
github.com/xdg-go/stringprep v1.0.4 // indirect
6463
github.com/youmark/pkcs8 v0.0.0-20240726163527-a2c0da244d78 // indirect
64+
go.mongodb.org/mongo-driver v1.17.6 // indirect
6565
go.uber.org/multierr v1.11.0 // indirect
6666
golang.org/x/arch v0.8.0 // indirect
6767
golang.org/x/exp v0.0.0-20240613232115-7f521ea00fb8 // indirect

0 commit comments

Comments
 (0)