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

パッケージ構成の変更 #705

Merged
merged 3 commits into from
Jul 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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 .github/workflows/main.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ jobs:
with:
go-version-file: ./go.mod
- name: Run tests
run: go test $(go list ./... | grep -v "integration_tests") -coverprofile=coverage_unit.txt -race -vet=off
run: go test ./internal/... -coverprofile=coverage_unit.txt -race -vet=off
- uses: actions/upload-artifact@v4
with:
name: coverage_unit
Expand Down
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ check: all lint test-all db-lint openapi-lint
test: ${GOFILES} test-unit

test-unit: ${GOFILES}
go test ${GOTEST_FLAGS} $$(go list ./... | grep -v "integration_tests")
go test ${GOTEST_FLAGS} ./internal/...

test-integration: ${GOFILES} up-db-container
go test ${GOTEST_FLAGS} ./integration_tests/...
Expand Down
56 changes: 20 additions & 36 deletions docs/architecture.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,44 +6,28 @@

```bash
.
├── bin # makeでコンパイルしたバイナリが入る
├── dev # 開発用の設定ファイル、スクリプト
│ └── bin # makeで使うシェルスクリプト
├── docs # ドキュメント
│ ├── dbschema # DBスキーマ(tblsで自動生成)
│ └── swagger # APIスキーマ
├── domain # domain層。他層に依存しないドメインオブジェクトを格納する
├── infrastructure # infrastructure層。他3層に依存する。
│ └── migration # DBのマイグレーション(go-gormigrate/gormigrateを使用)
├── integration_tests # 結合テスト
│ ├── handler
│ ├── repository
│ ├── testdata
│ └── testutils
├── interfaces # interface層。usecase層、domain層に依存する
│ ├── database # DB操作に関するインターフェイスを定義
│ │ └── mock_database # 単体テスト用モック(手書き)
│ ├── external # 外部サービス(traQ等)に関するインターフェイスを定義
│ │ ├── mock_external # 単体テスト用モック(mockgenで自動生成)
│ │ └── mock_external_e2e # E2Eテスト用モック(手書き)
│ ├── handler # echoハンドラーの実装、組み立て
│ └── repository # usecases/repositoryの実装
│ └── model # DBのモデル
├── usecases # usecase層。domain層に依存する
│ ├── repository # リポジトリ操作に関するインターフェイスを定義
│ │ └── mock_repository # 単体テスト用モック(mockgenで自動生成)
│ └── service # ビジネスロジックに関するインターフェイスの定義、実装
│ └── mock_service # 単体テスト用モック(mockgenで自動生成)
├── util # 汎用パッケージ
│ ├── config # config.yamlから設定を読み込む
│ │ └── testdata
│ ├── mockdata # E2Eテスト、結合テストで用いるサンプルデータを格納
│ ├── optional # null値を扱うためのパッケージ
│ └── random # テストで用いる乱数生成パッケージ
└── main.go
├── main.go # エントリーポイント
├── injector.go # 依存性注入
└── internal
├── domain # 他層に依存しないドメインオブジェクトを格納する
├── usecases # アプリケーションの具体的な操作を表現する (domain層に依存)
│ └── repository # リポジトリ操作に関するインターフェイスの定義
├── handler # Echoによるハンドラー&ルーティング (domain層、usecases層に依存)
│ └── schema # OpenAPIを基に自動生成されたAPIスキーマ
├── infrastructure # 外部APIやDBへのアクセス (domain層、usecases層に依存)
│ ├── external # 外部APIへのアクセス
│ ├── migration # DBのマイグレーション
│ └── repository # DBへのアクセス (usecases/repository の実装)
│ └── model # GORMのDBスキーマ
└── pkgs # 汎用パッケージ
├── config # 設定ファイル、環境変数を読み込み管理する
├── mockdata # E2Eテスト、結合テストで用いるサンプルデータを格納 (消したい)
├── optional # optionalな値を扱うためのパッケージ
├── random # テストで用いる乱数生成パッケージ
└── testutils # テストで用いるユーティリティ
```

## 依存関係
## 依存関係 (WIP)

ユーザー周りに限って紹介

Expand Down
10 changes: 5 additions & 5 deletions injector.go
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
package main

import (
"github.com/traPtitech/traPortfolio/infrastructure/external"
"github.com/traPtitech/traPortfolio/infrastructure/external/mock_external_e2e"
"github.com/traPtitech/traPortfolio/infrastructure/repository"
"github.com/traPtitech/traPortfolio/interfaces/handler"
"github.com/traPtitech/traPortfolio/util/config"
"github.com/traPtitech/traPortfolio/internal/handler"
"github.com/traPtitech/traPortfolio/internal/infrastructure/external"
"github.com/traPtitech/traPortfolio/internal/infrastructure/external/mock_external_e2e"
"github.com/traPtitech/traPortfolio/internal/infrastructure/repository"
"github.com/traPtitech/traPortfolio/internal/pkgs/config"
"gorm.io/gorm"
)

Expand Down
14 changes: 7 additions & 7 deletions integration_tests/handler/0_utils_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ import (
"github.com/gofrs/uuid"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
"github.com/traPtitech/traPortfolio/infrastructure/external/mock_external_e2e"
"github.com/traPtitech/traPortfolio/infrastructure/migration"
"github.com/traPtitech/traPortfolio/infrastructure/repository"
"github.com/traPtitech/traPortfolio/interfaces/handler"
"github.com/traPtitech/traPortfolio/util/config"
"github.com/traPtitech/traPortfolio/util/mockdata"
"github.com/traPtitech/traPortfolio/util/random"
"github.com/traPtitech/traPortfolio/internal/handler"
"github.com/traPtitech/traPortfolio/internal/infrastructure/external/mock_external_e2e"
"github.com/traPtitech/traPortfolio/internal/infrastructure/migration"
"github.com/traPtitech/traPortfolio/internal/infrastructure/repository"
"github.com/traPtitech/traPortfolio/internal/pkgs/config"
"github.com/traPtitech/traPortfolio/internal/pkgs/mockdata"
"github.com/traPtitech/traPortfolio/internal/pkgs/random"
"gorm.io/gorm"
)

Expand Down
8 changes: 4 additions & 4 deletions integration_tests/handler/contest_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"github.com/gofrs/uuid"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
"github.com/traPtitech/traPortfolio/infrastructure/repository/model"
"github.com/traPtitech/traPortfolio/interfaces/handler/schema"
"github.com/traPtitech/traPortfolio/util/mockdata"
"github.com/traPtitech/traPortfolio/util/random"
"github.com/traPtitech/traPortfolio/internal/handler/schema"
"github.com/traPtitech/traPortfolio/internal/infrastructure/repository/model"
"github.com/traPtitech/traPortfolio/internal/pkgs/mockdata"
"github.com/traPtitech/traPortfolio/internal/pkgs/random"
)

// GetContests GET /contests
Expand Down
8 changes: 4 additions & 4 deletions integration_tests/handler/event_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ import (
"github.com/gofrs/uuid"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
"github.com/traPtitech/traPortfolio/domain"
"github.com/traPtitech/traPortfolio/interfaces/handler/schema"
"github.com/traPtitech/traPortfolio/util/mockdata"
"github.com/traPtitech/traPortfolio/util/random"
"github.com/traPtitech/traPortfolio/internal/domain"
"github.com/traPtitech/traPortfolio/internal/handler/schema"
"github.com/traPtitech/traPortfolio/internal/pkgs/mockdata"
"github.com/traPtitech/traPortfolio/internal/pkgs/random"
)

// GetEvents GET /events
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/handler/group_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ import (

"github.com/gofrs/uuid"
"github.com/labstack/echo/v4"
"github.com/traPtitech/traPortfolio/interfaces/handler/schema"
"github.com/traPtitech/traPortfolio/util/mockdata"
"github.com/traPtitech/traPortfolio/util/random"
"github.com/traPtitech/traPortfolio/internal/handler/schema"
"github.com/traPtitech/traPortfolio/internal/pkgs/mockdata"
"github.com/traPtitech/traPortfolio/internal/pkgs/random"
)

// GetGroups GET /groups
Expand Down
4 changes: 2 additions & 2 deletions integration_tests/handler/main_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import (
"testing"

"github.com/go-sql-driver/mysql"
"github.com/traPtitech/traPortfolio/util/config"
"github.com/traPtitech/traPortfolio/util/testutils"
"github.com/traPtitech/traPortfolio/internal/pkgs/config"
"github.com/traPtitech/traPortfolio/internal/pkgs/testutils"
)

var (
Expand Down
6 changes: 3 additions & 3 deletions integration_tests/handler/project_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ import (
"github.com/gofrs/uuid"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
"github.com/traPtitech/traPortfolio/interfaces/handler/schema"
"github.com/traPtitech/traPortfolio/util/mockdata"
"github.com/traPtitech/traPortfolio/util/random"
"github.com/traPtitech/traPortfolio/internal/handler/schema"
"github.com/traPtitech/traPortfolio/internal/pkgs/mockdata"
"github.com/traPtitech/traPortfolio/internal/pkgs/random"
)

// GetProjects GET /projects
Expand Down
8 changes: 4 additions & 4 deletions integration_tests/handler/user_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,10 @@ import (
"github.com/gofrs/uuid"
"github.com/labstack/echo/v4"
"github.com/stretchr/testify/assert"
"github.com/traPtitech/traPortfolio/domain"
"github.com/traPtitech/traPortfolio/interfaces/handler/schema"
"github.com/traPtitech/traPortfolio/util/mockdata"
"github.com/traPtitech/traPortfolio/util/random"
"github.com/traPtitech/traPortfolio/internal/domain"
"github.com/traPtitech/traPortfolio/internal/handler/schema"
"github.com/traPtitech/traPortfolio/internal/pkgs/mockdata"
"github.com/traPtitech/traPortfolio/internal/pkgs/random"
)

// GetUsers GET /users
Expand Down
File renamed without changes.
2 changes: 1 addition & 1 deletion domain/duration.go → internal/domain/duration.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package domain

import "github.com/traPtitech/traPortfolio/util/optional"
import "github.com/traPtitech/traPortfolio/internal/pkgs/optional"

type YearWithSemester struct {
Year int
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ package domain
import (
"testing"

"github.com/traPtitech/traPortfolio/util/optional"
"github.com/traPtitech/traPortfolio/internal/pkgs/optional"
)

func Test_YearWithSemester_IsValid(t *testing.T) {
Expand Down
File renamed without changes.
3 changes: 2 additions & 1 deletion domain/event.go → internal/domain/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@ import (
"database/sql"
"database/sql/driver"
"fmt"
"github.com/traPtitech/traPortfolio/util/optional"
"time"

"github.com/traPtitech/traPortfolio/internal/pkgs/optional"

"github.com/gofrs/uuid"
)

Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
2 changes: 1 addition & 1 deletion interfaces/handler/api.go → internal/handler/api.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import (

"github.com/gofrs/uuid"
"github.com/labstack/echo/v4"
"github.com/traPtitech/traPortfolio/usecases/repository"
"github.com/traPtitech/traPortfolio/internal/usecases/repository"
)

type API struct {
Expand Down
6 changes: 3 additions & 3 deletions interfaces/handler/contest.go → internal/handler/contest.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,12 @@ import (
"time"

"github.com/gofrs/uuid"
"github.com/traPtitech/traPortfolio/interfaces/handler/schema"
"github.com/traPtitech/traPortfolio/internal/handler/schema"

"github.com/traPtitech/traPortfolio/util/optional"
"github.com/traPtitech/traPortfolio/internal/pkgs/optional"

"github.com/labstack/echo/v4"
"github.com/traPtitech/traPortfolio/usecases/repository"
"github.com/traPtitech/traPortfolio/internal/usecases/repository"
)

type ContestHandler struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,12 @@ import (
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"

"github.com/traPtitech/traPortfolio/domain"
"github.com/traPtitech/traPortfolio/interfaces/handler/schema"
"github.com/traPtitech/traPortfolio/usecases/repository"
"github.com/traPtitech/traPortfolio/usecases/repository/mock_repository"
"github.com/traPtitech/traPortfolio/util/optional"
"github.com/traPtitech/traPortfolio/util/random"
"github.com/traPtitech/traPortfolio/internal/domain"
"github.com/traPtitech/traPortfolio/internal/handler/schema"
"github.com/traPtitech/traPortfolio/internal/pkgs/optional"
"github.com/traPtitech/traPortfolio/internal/pkgs/random"
"github.com/traPtitech/traPortfolio/internal/usecases/repository"
"github.com/traPtitech/traPortfolio/internal/usecases/repository/mock_repository"
)

const (
Expand Down
8 changes: 4 additions & 4 deletions interfaces/handler/event.go → internal/handler/event.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,15 @@ import (
"net/http"
"time"

"github.com/traPtitech/traPortfolio/interfaces/handler/schema"
"github.com/traPtitech/traPortfolio/util/optional"
"github.com/traPtitech/traPortfolio/internal/handler/schema"
"github.com/traPtitech/traPortfolio/internal/pkgs/optional"

"github.com/traPtitech/traPortfolio/domain"
"github.com/traPtitech/traPortfolio/internal/domain"

"github.com/gofrs/uuid"

"github.com/labstack/echo/v4"
"github.com/traPtitech/traPortfolio/usecases/repository"
"github.com/traPtitech/traPortfolio/internal/usecases/repository"
)

type EventHandler struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,12 @@ import (

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/traPtitech/traPortfolio/domain"
"github.com/traPtitech/traPortfolio/interfaces/handler/schema"
"github.com/traPtitech/traPortfolio/usecases/repository"
"github.com/traPtitech/traPortfolio/usecases/repository/mock_repository"
"github.com/traPtitech/traPortfolio/util/optional"
"github.com/traPtitech/traPortfolio/util/random"
"github.com/traPtitech/traPortfolio/internal/domain"
"github.com/traPtitech/traPortfolio/internal/handler/schema"
"github.com/traPtitech/traPortfolio/internal/pkgs/optional"
"github.com/traPtitech/traPortfolio/internal/pkgs/random"
"github.com/traPtitech/traPortfolio/internal/usecases/repository"
"github.com/traPtitech/traPortfolio/internal/usecases/repository/mock_repository"
)

func setupEventMock(t *testing.T) (MockRepository, API) {
Expand Down
9 changes: 5 additions & 4 deletions interfaces/handler/group.go → internal/handler/group.go
Original file line number Diff line number Diff line change
@@ -1,12 +1,13 @@
package handler

import (
"github.com/gofrs/uuid"
"net/http"

"github.com/traPtitech/traPortfolio/domain"
"github.com/traPtitech/traPortfolio/interfaces/handler/schema"
"github.com/traPtitech/traPortfolio/usecases/repository"
"github.com/gofrs/uuid"

"github.com/traPtitech/traPortfolio/internal/domain"
"github.com/traPtitech/traPortfolio/internal/handler/schema"
"github.com/traPtitech/traPortfolio/internal/usecases/repository"

"github.com/labstack/echo/v4"
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,11 +9,11 @@ import (

"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/traPtitech/traPortfolio/domain"
"github.com/traPtitech/traPortfolio/interfaces/handler/schema"
"github.com/traPtitech/traPortfolio/usecases/repository"
"github.com/traPtitech/traPortfolio/usecases/repository/mock_repository"
"github.com/traPtitech/traPortfolio/util/random"
"github.com/traPtitech/traPortfolio/internal/domain"
"github.com/traPtitech/traPortfolio/internal/handler/schema"
"github.com/traPtitech/traPortfolio/internal/pkgs/random"
"github.com/traPtitech/traPortfolio/internal/usecases/repository"
"github.com/traPtitech/traPortfolio/internal/usecases/repository/mock_repository"
)

func setupGroupMock(t *testing.T) (MockRepository, API) {
Expand Down
File renamed without changes.
8 changes: 4 additions & 4 deletions interfaces/handler/project.go → internal/handler/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@ import (

"github.com/gofrs/uuid"
"github.com/labstack/echo/v4"
"github.com/traPtitech/traPortfolio/domain"
"github.com/traPtitech/traPortfolio/interfaces/handler/schema"
"github.com/traPtitech/traPortfolio/usecases/repository"
"github.com/traPtitech/traPortfolio/util/optional"
"github.com/traPtitech/traPortfolio/internal/domain"
"github.com/traPtitech/traPortfolio/internal/handler/schema"
"github.com/traPtitech/traPortfolio/internal/pkgs/optional"
"github.com/traPtitech/traPortfolio/internal/usecases/repository"
)

type ProjectHandler struct {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,16 @@ import (
"net/http"
"testing"

"github.com/traPtitech/traPortfolio/interfaces/handler/schema"
"github.com/traPtitech/traPortfolio/usecases/repository"
"github.com/traPtitech/traPortfolio/util/optional"
"github.com/traPtitech/traPortfolio/internal/handler/schema"
"github.com/traPtitech/traPortfolio/internal/pkgs/optional"
"github.com/traPtitech/traPortfolio/internal/usecases/repository"

"github.com/gofrs/uuid"
"github.com/golang/mock/gomock"
"github.com/stretchr/testify/assert"
"github.com/traPtitech/traPortfolio/domain"
"github.com/traPtitech/traPortfolio/usecases/repository/mock_repository"
"github.com/traPtitech/traPortfolio/util/random"
"github.com/traPtitech/traPortfolio/internal/domain"
"github.com/traPtitech/traPortfolio/internal/pkgs/random"
"github.com/traPtitech/traPortfolio/internal/usecases/repository/mock_repository"
)

var (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import (
vd "github.com/go-ozzo/ozzo-validation/v4"
"github.com/labstack/echo/v4"
"github.com/labstack/echo/v4/middleware"
"github.com/traPtitech/traPortfolio/usecases/repository"
"github.com/traPtitech/traPortfolio/internal/usecases/repository"
)

type Option func(*echo.Echo) error
Expand Down
Loading