Skip to content
This repository has been archived by the owner on May 7, 2023. It is now read-only.

Commit

Permalink
Merge pull request #2 from jacexh/hotfix/0.2.1
Browse files Browse the repository at this point in the history
hotfix-0.2.1
  • Loading branch information
jacexh authored Jul 5, 2020
2 parents f344e93 + 4db1fa7 commit b72ee49
Show file tree
Hide file tree
Showing 9 changed files with 55 additions and 27 deletions.
7 changes: 6 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ a DDD project template in golang

## Change Log

### 0.2.1

- 区分`DataObject`以及`Entity`
- 修改目录名称 `infrastructure/repository` -> `infrastructure/persistence`

### 0.2.0

基于依赖反转原则以及六边形架构重构整个项目
Expand All @@ -19,4 +24,4 @@ a DDD project template in golang
- `Repository`定义在`Domain`层内
- `Application`+`Domain` 使用依赖反转,具备了更好的可测试性
- 更清晰的分支管理:`master`分支为golang项目,`template`分支为模板
- 严格区分了`Entity``ValueObject``DataTransferObject``DomainEvent`
- 严格区分了`Entity``ValueObject``DataTransferObject``DomainEvent`
8 changes: 4 additions & 4 deletions application/user.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import (
"context"

"{{.Module}}/domain/user"
"{{.Module}}/types"
"{{.Module}}/types/dto"
)

var (
Expand All @@ -23,8 +23,8 @@ func BuildUserApplication(repo user.UserRepository) {
}
}

func convert(user *user.UserEntity) *types.UserDTO {
return &types.UserDTO{
func convert(user *user.UserEntity) *dto.UserDTO {
return &dto.UserDTO{
ID: user.ID,
Name: user.Name,
Email: user.Email,
Expand All @@ -35,7 +35,7 @@ func (ua *userApplication) WithUserRepository(repo user.UserRepository) {
ua.repo = repo
}

func (ua *userApplication) GetUserByID(ctx context.Context, uid string) (*types.UserDTO, error) {
func (ua *userApplication) GetUserByID(ctx context.Context, uid string) (*dto.UserDTO, error) {
user, err := ua.repo.GetUserByID(ctx, uid)
if err != nil {
return nil, err
Expand Down
6 changes: 3 additions & 3 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ import (
"syscall"

"{{.Module}}/application"
"{{.Module}}/infrastructure/repository"
"{{.Module}}/infrastructure/persistence"
"{{.Module}}/logger"
"{{.Module}}/option"
"{{.Module}}/router"
Expand Down Expand Up @@ -85,11 +85,11 @@ func main() {
logger.Logger.Info("loaded options", zap.Any("option", opt), zap.String("version", version))

// 创建数据库连接
db, err := repository.BuildDBConnection(opt.Database)
db, err := persistence.BuildDBConnection(opt.Database)
if err != nil {
logger.Logger.Panic("failed to connect with database", zap.Error(err))
}
ur := repository.NewUserRepository(db)
ur := persistence.NewUserRepository(db)

// 初始化application层
application.BuildUserApplication(ur)
Expand Down
11 changes: 4 additions & 7 deletions domain/user/user.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,8 @@
package user

import "time"

type UserEntity struct {
ID string `ddb:"id"`
Name string `ddb:"name"`
Email string `ddb:"email"`
CTime time.Time `ddb:"ctime"`
MTime time.Time `ddb:"mtime"`
ID string
Name string
Password string
Email string
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package repository
package persistence

import (
"database/sql"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package repository
package persistence

import (
"context"
"database/sql"

"{{.Module}}/domain/user"
"{{.Module}}/types/do"
)

type (
Expand All @@ -13,6 +14,15 @@ type (
}
)

func convert(entity *user.UserEntity) *do.UserDo {
return &do.UserDo{
ID: entity.ID,
Name: entity.Name,
Password: entity.Password,
Email: entity.Email,
}
}

func NewUserRepository(db *sql.DB) user.UserRepository {
return &UserRepository{db}
}
Expand Down
13 changes: 13 additions & 0 deletions types/do/do.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package do

import "time"

type UserDo struct {
ID string `ddb:"id"`
Name string `ddb:"name"`
Password string `ddb:"password"`
Email string `ddb:"email"`
Version int `ddb:"version"`
CTime time.Time `ddb:"ctime"`
MTime time.Time `ddb:"mtime"`
}
10 changes: 0 additions & 10 deletions types/dto.go

This file was deleted.

13 changes: 13 additions & 0 deletions types/dto/dto.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package dto

type (
// UserDTO use的dto定义,用于api层
UserDTO struct {
ID string `json:"id"`
Name string `json:"name"`
Email string `json:"email"`
Version string `json:"version"`
CTime string `json:"ctime"`
MTime string `json:"mtime"`
}
)

0 comments on commit b72ee49

Please sign in to comment.