-
Notifications
You must be signed in to change notification settings - Fork 1
[BE-6] 3層アーキテクチャの設計、ゲーム開始 #13
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -36,3 +36,6 @@ tmp/ | |
|
|
||
| # OS | ||
| .DS_Store | ||
|
|
||
| # Serena | ||
| .serena | ||
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,30 @@ | ||||||||
| package controllers | ||||||||
|
|
||||||||
| import ( | ||||||||
| "net/http" | ||||||||
|
|
||||||||
| "github.com/gin-gonic/gin" | ||||||||
| "github.com/kc3hack/2026_team10/backend/services" | ||||||||
| ) | ||||||||
|
|
||||||||
| type IHintController interface { | ||||||||
| StartGame(ctx *gin.Context) | ||||||||
| } | ||||||||
|
|
||||||||
| type HintController struct { | ||||||||
| service services.IHintService | ||||||||
| } | ||||||||
|
|
||||||||
| func NewHintController(service services.IHintService) IHintController { | ||||||||
| return &HintController{service: service} | ||||||||
| } | ||||||||
|
|
||||||||
| func (c *HintController) StartGame(ctx *gin.Context) { | ||||||||
| result, err := c.service.StartGame() | ||||||||
| if err != nil { | ||||||||
|
||||||||
| if err != nil { | |
| if err != nil { | |
| ctx.Error(err) |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,13 +1,26 @@ | ||
| package main | ||
|
|
||
| import "github.com/gin-gonic/gin" | ||
| import ( | ||
| "github.com/gin-gonic/gin" | ||
| "github.com/kc3hack/2026_team10/backend/controllers" | ||
| "github.com/kc3hack/2026_team10/backend/model" | ||
| "github.com/kc3hack/2026_team10/backend/repositories" | ||
| "github.com/kc3hack/2026_team10/backend/services" | ||
| ) | ||
|
|
||
| func main() { | ||
| router := gin.Default() | ||
| router.GET("/ping", func(c *gin.Context) { | ||
| rounds := []model.Round{} | ||
|
|
||
| hintRepository := repositories.NewHintMemoryRepository(rounds) | ||
| hintService := services.NewHintService(hintRepository) | ||
| hintController := controllers.NewHintController(hintService) | ||
|
|
||
| r := gin.Default() | ||
| r.GET("/ping", func(c *gin.Context) { | ||
| c.JSON(200, gin.H{ | ||
| "message": "pong", | ||
| }) | ||
| }) | ||
| router.Run() // デフォルトで0.0.0.0:8080で待機します | ||
| r.POST("/solo", hintController.StartGame) | ||
| r.Run() // デフォルトで0.0.0.0:8080で待機します | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| package model | ||
|
|
||
| type Round struct { | ||
| ID int | ||
| Answer string | ||
| Hints []string | ||
| } | ||
|
|
||
| type StartGameResult struct { | ||
| ID int `json:"id"` | ||
| Hints []string `json:"hints"` | ||
| } |
| Original file line number | Diff line number | Diff line change | ||||||
|---|---|---|---|---|---|---|---|---|
| @@ -0,0 +1,32 @@ | ||||||||
| package repositories | ||||||||
|
|
||||||||
| import "github.com/kc3hack/2026_team10/backend/model" | ||||||||
|
|
||||||||
| type IHintRepository interface { | ||||||||
| CreateRound(answer string, hints []string) (*model.Round, error) | ||||||||
| } | ||||||||
|
|
||||||||
| type HintMemoryRepository struct { | ||||||||
| rounds []model.Round | ||||||||
| } | ||||||||
|
|
||||||||
| func NewHintMemoryRepository(rounds []model.Round) IHintRepository { | ||||||||
| return &HintMemoryRepository{rounds: rounds} | ||||||||
| } | ||||||||
|
|
||||||||
| func (r *HintMemoryRepository) CreateRound(answer string, hints []string) (*model.Round, error) { | ||||||||
| maxID := 0 | ||||||||
| for _, rd := range r.rounds { | ||||||||
| if rd.ID > maxID { | ||||||||
| maxID = rd.ID | ||||||||
|
Comment on lines
+17
to
+21
|
||||||||
| } | ||||||||
| } | ||||||||
| newID := maxID + 1 | ||||||||
| round := model.Round{ | ||||||||
| ID: newID, | ||||||||
| Answer: answer, | ||||||||
| Hints: hints, | ||||||||
| } | ||||||||
| r.rounds = append(r.rounds, round) | ||||||||
| return &r.rounds[len(r.rounds)-1], nil | ||||||||
|
||||||||
| return &r.rounds[len(r.rounds)-1], nil | |
| retRound := round | |
| return &retRound, nil |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,39 @@ | ||
| package services | ||
|
|
||
| import ( | ||
| "fmt" | ||
|
|
||
| "github.com/kc3hack/2026_team10/backend/model" | ||
| "github.com/kc3hack/2026_team10/backend/repositories" | ||
| ) | ||
|
|
||
| type IHintService interface { | ||
| StartGame() (*model.StartGameResult, error) | ||
| } | ||
|
|
||
| type HintService struct { | ||
| repository repositories.IHintRepository | ||
| } | ||
|
|
||
| func NewHintService(repository repositories.IHintRepository) IHintService { | ||
| return &HintService{repository: repository} | ||
| } | ||
|
|
||
| func (s *HintService) StartGame() (*model.StartGameResult, error) { | ||
| // お題、ヒントを作成 | ||
| answer := "お題" | ||
| hints := []string{"ヒント1", "ヒント2", "ヒント3"} | ||
|
|
||
| // データを保存 | ||
| result, err := s.repository.CreateRound(answer, hints) | ||
| if err != nil { | ||
| return nil, fmt.Errorf("failed to save hint data: %w", err) | ||
| } | ||
|
Comment on lines
+28
to
+31
|
||
|
|
||
| // IDとヒントを返す | ||
| response := &model.StartGameResult{ | ||
| ID: result.ID, | ||
| Hints: result.Hints, | ||
| } | ||
| return response, nil | ||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
POST /solo のハンドラ名が GetHints になっており、処理内容(ゲーム開始/ラウンド作成)と名前が一致していません。用途が伝わるように StartGame / CreateRound などの名前に揃えることを検討してください。