-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from naohito-T/feature/container-to-crean-arch
♻️ Fix: connect crean arch
- Loading branch information
Showing
8 changed files
with
161 additions
and
15 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,8 +1,7 @@ | ||
package domain | ||
|
||
type ShortURL struct { | ||
ID int `json:"id"` | ||
ShortURL string `json:"short_url"` | ||
ID string `json:"id"` | ||
OriginalURL string `json:"original"` | ||
CreatedAt string `json:"created_at"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package container | ||
|
||
import ( | ||
"github.com/naohito-T/tinyurl/backend/internal/infrastructures/dynamo" | ||
"github.com/naohito-T/tinyurl/backend/internal/infrastructures/slog" | ||
repoDynamo "github.com/naohito-T/tinyurl/backend/internal/repository/dynamo" | ||
"github.com/naohito-T/tinyurl/backend/internal/usecase" | ||
|
||
"sync" | ||
) | ||
|
||
type GuestContainer struct { | ||
URLUsecase *usecase.ShortURLUsecase | ||
} | ||
|
||
var newGuestContainer = sync.OnceValue(func() *GuestContainer { | ||
dynamoRepo := repoDynamo.NewShortURLRepository(dynamo.NewDynamoConnection(), slog.NewLogger()) | ||
return &GuestContainer{ | ||
URLUsecase: usecase.NewURLUsecase(dynamoRepo), | ||
} | ||
}) | ||
|
||
func NewGuestContainer() *GuestContainer { | ||
return newGuestContainer() | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
package usecase | ||
|
||
import ( | ||
"github.com/naohito-T/tinyurl/backend/domain" | ||
) | ||
|
||
type IShortURLRepo interface { | ||
GetByShortURL(id string) (domain.ShortURL, error) | ||
CreateShortURL(params *domain.ShortURL) error | ||
} | ||
|
||
type ShortURLUsecase struct { | ||
shortURLRepo IShortURLRepo | ||
} | ||
|
||
func NewURLUsecase(u IShortURLRepo) *ShortURLUsecase { | ||
return &ShortURLUsecase{ | ||
shortURLRepo: u, | ||
} | ||
} | ||
|
||
func (u *ShortURLUsecase) GetByShortURL(id string) domain.ShortURL { | ||
shortURL, err := u.shortURLRepo.GetByShortURL(id) | ||
if err != nil { | ||
panic(err) | ||
} | ||
return shortURL | ||
} | ||
|
||
func (u *ShortURLUsecase) CreateShortURL(params *domain.ShortURL) error { | ||
return u.shortURLRepo.CreateShortURL(params) | ||
} |