Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
27 commits
Select commit Hold shift + click to select a range
a0807d5
feat: docker-compose
dexfs Jan 30, 2025
a7f3b6f
feat: migrations
dexfs Jan 30, 2025
7f44817
feat: docker-compose
dexfs Jan 30, 2025
94c2c57
chore: update dependencies
dexfs Jan 30, 2025
f8c45b2
feat: postgresDB and dotenv
dexfs Jan 31, 2025
24827a6
feat: change user repo to postgres database
dexfs Jan 31, 2025
4935d57
refactor: update call for support interface changes
dexfs Jan 31, 2025
c9fde82
chore: create seed command
dexfs Jan 31, 2025
61bf48b
chore: update README
dexfs Jan 31, 2025
da01a22
chore: ignore test
dexfs Jan 31, 2025
f8af254
chore: temp changes for coverage
dexfs Jan 31, 2025
ae4ceb0
chore: no coverage step for now
dexfs Jan 31, 2025
387e48d
refactor: change user resources to support context
dexfs Jan 31, 2025
97596f4
chore: update seeds
dexfs Jan 31, 2025
0be75e9
refactor: pass context to dependencies
dexfs Feb 2, 2025
7cd1ecf
refactor: change validation from uuid to ulid
dexfs Feb 2, 2025
0941171
feat: postgres repository
dexfs Feb 2, 2025
7bcb19a
refactor: pass context to in memory repository
dexfs Feb 2, 2025
10676cc
feat: use postgres repository
dexfs Feb 2, 2025
15c9772
feat: use ulid
dexfs Feb 2, 2025
ecaf3db
refactor: interfaces input and output
dexfs Feb 2, 2025
ec18764
feat: migrations
dexfs Feb 2, 2025
2e1e97d
feat: postgres db
dexfs Feb 2, 2025
d2a978d
feat: postgres seed
dexfs Feb 2, 2025
493f3c4
chore: update user id for test
dexfs Feb 2, 2025
9f81e3f
chore: update dependencies
dexfs Feb 2, 2025
b44b8c3
chore: make command
dexfs Feb 2, 2025
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
1 change: 1 addition & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
DATABASE_URL="postgres://gouser:123456@localhost:5432/gotwitterclone?sslmode=disable"
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
@@ -1 +1,2 @@
bin/api
bin/api
/.env
6 changes: 3 additions & 3 deletions .testcoverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ local-prefix: "github.com/org/project"
threshold:
# (optional; default 0)
# The minimum coverage that each file should have
file: 60
file: 5

# (optional; default 0)
# The minimum coverage that each package should have
package: 70
package: 5

# (optional; default 0)
# The minimum total coverage project should have
total: 70
total: 5

# Holds regexp rules which will override thresholds for matched files or packages
# using their paths.
Expand Down
28 changes: 28 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
The MIT License (MIT)

Original Work
Copyright (c) 2016 Matthias Kadenbach
https://github.com/mattes/migrate

Modified Work
Copyright (c) 2018 Dale Hui
https://github.com/golang-migrate/migrate


Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in
all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
THE SOFTWARE.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,10 @@ test:
@go test ./... -v

build:
@go build -o bin/api cmd/api/api.go
@go build -o bin/api cmd/api/main.go

start: build
./bin/api

seed:
@go run cmd/seeds/main.go
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,16 +23,16 @@ https://dbdiagram.io/d/go-twitter-clone-660b4e8437b7e33fd741027f
// users data
const users = [
{
id: '4cfe67a9-defc-42b9-8410-cb5086bec2f5',
id: '0194bd04-66e2-7cd8-b3d9-66eda709f2ee',
username: 'alucard',
},
{
id: 'b8903f77-5d16-4176-890f-f597594ff952',
id: '0194bd04-8eac-7e70-97cd-c526cdda3d6a',
username: 'alexander',

},
{
id: '75135a97-46be-405f-8948-0821290ca83e',
id: '0194bdb1-0588-7181-809e-a825badac714',
username: 'seras_victoria',
},
];
Expand All @@ -54,6 +54,6 @@ ___



## Styleguide
## Styleguide

[uber go style guide](https://github.com/alcir-junior-caju/uber-go-style-guide-pt-br)
[uber go style guide](https://github.com/alcir-junior-caju/uber-go-style-guide-pt-br)
6 changes: 3 additions & 3 deletions adapter/input/adapter_http/posts_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ func (pc *postsController) CreatePost(c *gin.Context) {
return
}

postDomain, err := pc.createPostUseCase.Execute(input.CreatePostUseCaseInput{
postDomain, err := pc.createPostUseCase.Execute(c, input.CreatePostUseCaseInput{
UserID: createPostRequest.UserID,
Content: createPostRequest.Content,
})
Expand All @@ -56,7 +56,7 @@ func (pc *postsController) CreateRepost(c *gin.Context) {
return
}

postDomain, err := pc.createRepostUseCase.Execute(input.CreateRepostUseCaseInput{
postDomain, err := pc.createRepostUseCase.Execute(c, input.CreateRepostUseCaseInput{
PostID: createRequest.PostID,
UserID: createRequest.UserID,
})
Expand All @@ -80,7 +80,7 @@ func (pc *postsController) CreateQuote(c *gin.Context) {
return
}

postDomain, err := pc.createQuoteUseCase.Execute(input.CreateQuoteUseCaseInput{
postDomain, err := pc.createQuoteUseCase.Execute(c, input.CreateQuoteUseCaseInput{
PostID: createRequest.PostID,
UserID: createRequest.UserID,
Quote: createRequest.Quote,
Expand Down
4 changes: 2 additions & 2 deletions adapter/input/adapter_http/users_controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func (uc *usersController) GetInfo(c *gin.Context) {
c.JSON(errRest.Code, errRest)
return
}
userFeedDomain, err := uc.getUserInfoUseCase.Execute(userInfoRequest.Username)
userFeedDomain, err := uc.getUserInfoUseCase.Execute(c, userInfoRequest.Username)
if err != nil {
c.JSON(err.Code, err)
return
Expand All @@ -53,7 +53,7 @@ func (uc *usersController) GetFeed(c *gin.Context) {
return
}

userFeedDomain, err := uc.getUserFeedUseCase.Execute(userRequest.Username)
userFeedDomain, err := uc.getUserFeedUseCase.Execute(c, userRequest.Username)
if err != nil {
c.JSON(err.Code, err)
return
Expand Down
2 changes: 1 addition & 1 deletion adapter/input/model/request/post_create_request.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package request

type CreatePostRequest struct {
UserID string `json:"user_id" binding:"required,uuid4"`
UserID string `json:"user_id" binding:"required,ulid"`
Content string `json:"content" binding:"required,min=10,max=255"`
}
4 changes: 2 additions & 2 deletions adapter/input/model/request/quote_request.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package request

type QuoteRequest struct {
UserID string `json:"user_id" binding:"required,uuid4"`
PostID string `json:"post_id" binding:"required,uuid4"`
UserID string `json:"user_id" binding:"required,ulid"`
PostID string `json:"post_id" binding:"required,ulid"`
Quote string `json:"quote" binding:"required,min=10,max=100"`
}
4 changes: 2 additions & 2 deletions adapter/input/model/request/repost_request.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package request

type RepostRequest struct {
UserID string `json:"user_id" binding:"required,uuid4"`
PostID string `json:"post_id" binding:"required,uuid4"`
UserID string `json:"user_id" binding:"required,ulid"`
PostID string `json:"post_id" binding:"required,ulid"`
}
2 changes: 1 addition & 1 deletion adapter/input/model/request/user_request.go
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package request

type UserInfoRequest struct {
Username string `uri:"username" binding:"required,min=5,max=10,alphanum,lowercase"`
Username string `uri:"username" binding:"required,min=5,max=14,alphanum,lowercase"`
}

type UserFeedRequest struct {
Expand Down
11 changes: 6 additions & 5 deletions adapter/output/repository/inmemory/post_inmemory_repo.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package inmemory

import (
"context"
"errors"
"github.com/dexfs/go-twitter-clone/adapter/output/mappers"
inmemory_schema "github.com/dexfs/go-twitter-clone/adapter/output/repository/inmemory/schema"
Expand All @@ -22,7 +23,7 @@ func NewInMemoryPostRepository(db *database.InMemoryDB) *inMemoryPostRepository
}
}

func (r *inMemoryPostRepository) CreatePost(aPost *domain.Post) error {
func (r *inMemoryPostRepository) CreatePost(ctx context.Context, aPost *domain.Post) error {
r.insert(&inmemory_schema.PostSchema{
ID: aPost.ID,
UserID: aPost.User.ID,
Expand All @@ -38,7 +39,7 @@ func (r *inMemoryPostRepository) CreatePost(aPost *domain.Post) error {
return nil
}

func (r *inMemoryPostRepository) HasReachedPostingLimitDay(aUserId string, aLimit uint64) bool {
func (r *inMemoryPostRepository) HasReachedPostingLimitDay(ctx context.Context, aUserId string, aLimit uint64) bool {
var count = uint64(0)

for _, currentData := range r.getAll() {
Expand All @@ -57,7 +58,7 @@ func (r *inMemoryPostRepository) HasReachedPostingLimitDay(aUserId string, aLimi
}
}

func (r *inMemoryPostRepository) AllByUserID(aUser *domain.User) []*domain.Post {
func (r *inMemoryPostRepository) AllByUserID(ctx context.Context, aUser *domain.User) []*domain.Post {
var feed []*domain.Post
for _, currentData := range r.getAll() {
if currentData.UserID == aUser.ID {
Expand All @@ -68,7 +69,7 @@ func (r *inMemoryPostRepository) AllByUserID(aUser *domain.User) []*domain.Post
return feed
}

func (r *inMemoryPostRepository) FindByID(aPostID string) (*domain.Post, error) {
func (r *inMemoryPostRepository) FindByID(ctx context.Context, aPostID string) (*domain.Post, error) {
for _, currentData := range r.getAll() {
if currentData.ID == aPostID {
var postUser *domain.User
Expand All @@ -84,7 +85,7 @@ func (r *inMemoryPostRepository) FindByID(aPostID string) (*domain.Post, error)
return nil, errors.New("post not found")
}

func (r *inMemoryPostRepository) HasPostBeenRepostedByUser(postID string, userID string) bool {
func (r *inMemoryPostRepository) HasPostBeenRepostedByUser(ctx context.Context, postID string, userID string) bool {
for _, vPost := range r.getAll() {
if vPost.IsRepost {
if vPost.UserID == userID && vPost.OriginalPostID == postID {
Expand Down
5 changes: 3 additions & 2 deletions adapter/output/repository/inmemory/user_inmemory_repo.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package inmemory

import (
"context"
"errors"
inmemory_schema "github.com/dexfs/go-twitter-clone/adapter/output/repository/inmemory/schema"
"github.com/dexfs/go-twitter-clone/internal/core/domain"
Expand All @@ -19,7 +20,7 @@ func NewInMemoryUserRepository(db *database.InMemoryDB) *inMemoryUserRepository
}
}

func (r *inMemoryUserRepository) ByUsername(username string) (*domain.User, error) {
func (r *inMemoryUserRepository) ByUsername(ctx context.Context, username string) (*domain.User, error) {
for _, currentUser := range r.getAll() {
if currentUser.Username == username {
return &domain.User{
Expand All @@ -34,7 +35,7 @@ func (r *inMemoryUserRepository) ByUsername(username string) (*domain.User, erro
return nil, errors.New("user not found")
}

func (r *inMemoryUserRepository) FindByID(id string) (*domain.User, error) {
func (r *inMemoryUserRepository) FindByID(ctx context.Context, id string) (*domain.User, error) {
for _, currentUser := range r.getAll() {
if currentUser.ID == id {
return &domain.User{
Expand Down
Loading
Loading