Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
83 commits
Select commit Hold shift + click to select a range
2c5429a
common domain
hikaru-0602 Feb 16, 2026
85409c2
course domain
hikaru-0602 Feb 16, 2026
2ba0bd9
timatable domain
hikaru-0602 Feb 16, 2026
714d72b
faculty domain
hikaru-0602 Feb 16, 2026
95f1afa
subject domain
hikaru-0602 Feb 16, 2026
db58e42
subject_category domain
hikaru-0602 Feb 16, 2026
92b8273
SubjectのAPIURL
hikaru-0602 Feb 16, 2026
191d9a5
APIクライアントの生成をまとめた
hikaru-0602 Feb 16, 2026
464a44d
外部のクライアントを一括初期化する処理に修正
hikaru-0602 Feb 16, 2026
1c86ab8
courseの型変換
hikaru-0602 Feb 16, 2026
c6ce38c
timetableの型変換
hikaru-0602 Feb 16, 2026
92ed37f
facultyの型変換
hikaru-0602 Feb 16, 2026
49433d8
科目区分の型変換
hikaru-0602 Feb 16, 2026
c45e06b
Subjectの型変換
hikaru-0602 Feb 16, 2026
162bf52
HandlerをWithパターンに変更
hikaru-0602 Feb 16, 2026
0e03679
Withパターンに対応
hikaru-0602 Feb 16, 2026
26184f4
facultyの変換関数を追加
hikaru-0602 Feb 16, 2026
a6900dc
facultyのHandler実装
hikaru-0602 Feb 16, 2026
016a87d
Handlerの初期化にfacultyも追加
hikaru-0602 Feb 16, 2026
513f68d
facultyのService実装
hikaru-0602 Feb 16, 2026
3f9c6c9
facultyのRepository実装
hikaru-0602 Feb 16, 2026
8ef96c2
courseを追加
hikaru-0602 Feb 16, 2026
d80b0b2
courseの変換関数を追加
hikaru-0602 Feb 16, 2026
e9b2e01
courseのHandler実装
hikaru-0602 Feb 16, 2026
37284fd
Handlerの初期化にcourse追加
hikaru-0602 Feb 16, 2026
e607434
courseのRepository実装
hikaru-0602 Feb 16, 2026
a337e25
courseのService実装
hikaru-0602 Feb 16, 2026
4eb4efc
timetable追加
hikaru-0602 Feb 17, 2026
6eee108
timetable追加
hikaru-0602 Feb 17, 2026
a84ba13
timetableのHandler実装
hikaru-0602 Feb 17, 2026
71443a5
timetable追加
hikaru-0602 Feb 17, 2026
55b02b5
timetableのRepository実装
hikaru-0602 Feb 17, 2026
cdd7f54
timetableのService実装
hikaru-0602 Feb 17, 2026
bb4b9b7
subject_category追加
hikaru-0602 Feb 17, 2026
fa5151d
subject_category
hikaru-0602 Feb 17, 2026
2b049dc
subject_category
hikaru-0602 Feb 17, 2026
de67954
subject_categoryのHandler実装
hikaru-0602 Feb 17, 2026
74c7d0f
subject_categoryのRepository実装
hikaru-0602 Feb 17, 2026
e9e7ed4
subject_categoryのService実装
hikaru-0602 Feb 17, 2026
7df7cd6
subject追加
hikaru-0602 Feb 17, 2026
17aade9
subject
hikaru-0602 Feb 17, 2026
f6b1e4b
subject追加
hikaru-0602 Feb 17, 2026
a5b3eed
subjectのHandler実装
hikaru-0602 Feb 17, 2026
d516329
subjectのService実装
hikaru-0602 Feb 17, 2026
9d90125
subjectのRepository実装
hikaru-0602 Feb 17, 2026
7267331
courseのRepositoryモック実装
hikaru-0602 Feb 17, 2026
3b66a72
timetableのRepositoryモック実装
hikaru-0602 Feb 17, 2026
d94764d
facultyのRepositoryモック実装
hikaru-0602 Feb 17, 2026
6a2d720
subject_categoryのRepositoryモック実装
hikaru-0602 Feb 17, 2026
bf90ecb
subjectのRepositoryモック実装
hikaru-0602 Feb 17, 2026
052b45a
courseのHandlerテスト実装
hikaru-0602 Feb 17, 2026
bd8373c
timetableのHandlerテスト実装
hikaru-0602 Feb 17, 2026
6609fc0
facultyのHandlerテスト実装
hikaru-0602 Feb 17, 2026
dbc2cc6
subject_categoryのHandlerテスト実装
hikaru-0602 Feb 17, 2026
4599205
subjectのHandlerテスト実装
hikaru-0602 Feb 17, 2026
f5493e8
CDにSubjectの環境変数を追加
hikaru-0602 Feb 17, 2026
6eefa6b
converterファイルをAPIごとに切り分け(お試し実装)
hikaru-0602 Feb 17, 2026
3637144
リクエストにタイムアウトを設定
hikaru-0602 Feb 17, 2026
ad1d594
デフォルト値を削除
hikaru-0602 Feb 18, 2026
3b9862d
setupMockを使用してテストごとにモックを設定
hikaru-0602 Feb 18, 2026
e0492f5
ドメインモデルからJsonの型を外した
hikaru-0602 Feb 18, 2026
97f0525
facultyにカスタムID追加
hikaru-0602 Feb 18, 2026
05426c5
courseをカスタムIDに
hikaru-0602 Feb 18, 2026
e6be923
timetableをカスタムIDに
hikaru-0602 Feb 18, 2026
cfabf1b
announcement, subject_category, subjectをカスタムIDに
hikaru-0602 Feb 18, 2026
b43aafb
テスト削除
hikaru-0602 Feb 19, 2026
f6e0081
Handlerに直接挿入
hikaru-0602 Feb 19, 2026
5642abf
必要ないので削除
hikaru-0602 Feb 19, 2026
d66b671
削除
hikaru-0602 Feb 19, 2026
9518071
削除
hikaru-0602 Feb 19, 2026
6f18b65
クライアント持つ
hikaru-0602 Feb 19, 2026
ee88537
そのまま返す
hikaru-0602 Feb 19, 2026
ea57a78
修正
hikaru-0602 Feb 19, 2026
a74e9dd
Merge pull request #12 from fun-dotto/feature/announcement-api-reduction
hikaru-0602 Feb 19, 2026
67eea37
Subject関連も薄くした
hikaru-0602 Feb 19, 2026
8e8b97e
クライアントチェック追加
hikaru-0602 Feb 20, 2026
99bb390
Update internal/handler/day_of_week_timetable_slot.go
hikaru-0602 Feb 20, 2026
3962411
Update internal/handler/subject.go
hikaru-0602 Feb 20, 2026
d8c5e25
Update internal/handler/subject_category.go
hikaru-0602 Feb 20, 2026
76fae46
Update internal/handler/announcement.go
hikaru-0602 Feb 20, 2026
be1a29b
Update internal/handler/faculty.go
hikaru-0602 Feb 20, 2026
cb28ff3
Update internal/handler/course.go
hikaru-0602 Feb 20, 2026
c885262
Update internal/handler/subject.go
hikaru-0602 Feb 20, 2026
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
@@ -1,3 +1,4 @@
ANNOUNCEMENT_API_URL=
GOOGLE_APPLICATION_CREDENTIALS=
GOOGLE_CLOUD_PROJECT=
SUBJECT_API_URL=
1 change: 1 addition & 0 deletions .github/workflows/cd.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -125,5 +125,6 @@ jobs:
region: ${{ vars._DEPLOY_REGION }}
env_vars: |
ANNOUNCEMENT_API_URL=${{ vars.ANNOUNCEMENT_API_URL }}
SUBJECT_API_URL=${{ vars.SUBJECT_API_URL }}
env_vars_update_strategy: overwrite
secrets_update_strategy: overwrite
31 changes: 4 additions & 27 deletions cmd/server/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,20 +3,16 @@ package main
import (
"context"
"log"
"os"

firebase "firebase.google.com/go/v4"
api "github.com/fun-dotto/api-template/generated"
"github.com/fun-dotto/api-template/generated/external/announcement_api"
"github.com/fun-dotto/api-template/internal/handler"
"github.com/fun-dotto/api-template/internal/infrastructure"
"github.com/fun-dotto/api-template/internal/middleware"
"github.com/fun-dotto/api-template/internal/repository"
"github.com/fun-dotto/api-template/internal/service"
"github.com/getkin/kin-openapi/openapi3"
"github.com/gin-gonic/gin"
"github.com/joho/godotenv"
oapimiddleware "github.com/oapi-codegen/gin-middleware"
"google.golang.org/api/idtoken"
)

func main() {
Expand Down Expand Up @@ -46,31 +42,12 @@ func main() {
router.Use(oapimiddleware.OapiRequestValidator(spec))
router.Use(middleware.FirebaseAuth(authClient))

announcementAPIURL := os.Getenv("ANNOUNCEMENT_API_URL")
if announcementAPIURL == "" {
log.Fatal("ANNOUNCEMENT_API_URL is required")
}
// 認証付きHTTPクライアントを作成
announcementAPIAuthClient, err := idtoken.NewClient(ctx, announcementAPIURL)
clients, err := infrastructure.NewExternalClients(ctx)
if err != nil {
log.Fatal("Failed to create auth client:", err)
log.Fatalf("Failed to initialize external clients: %v", err)
}

// 生成されたクライアントに認証付きHTTPクライアントを注入
apiClient, err := announcement_api.NewClientWithResponses(
announcementAPIURL,
announcement_api.WithHTTPClient(announcementAPIAuthClient),
)
if err != nil {
log.Fatal("Failed to create API client:", err)
}

// Initialize layers
announcementRepo := repository.NewAnnouncementRepository(apiClient)
announcementService := service.NewAnnouncementService(announcementRepo)

// Register handlers
h := handler.NewHandler(announcementService)
h := handler.NewHandler(clients.Announcement, clients.Subject)
api.RegisterHandlers(router, h)

addr := ":8080"
Expand Down
3 changes: 0 additions & 3 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@ require (
github.com/joho/godotenv v1.5.1
github.com/oapi-codegen/gin-middleware v1.0.2
github.com/oapi-codegen/runtime v1.1.2
github.com/stretchr/testify v1.11.1
google.golang.org/api v0.231.0
)

Expand All @@ -35,7 +34,6 @@ require (
github.com/cespare/xxhash/v2 v2.3.0 // indirect
github.com/cloudwego/base64x v0.1.6 // indirect
github.com/cncf/xds/go v0.0.0-20250501225837-2ac532fd4443 // indirect
github.com/davecgh/go-spew v1.1.1 // indirect
github.com/dprotaso/go-yit v0.0.0-20220510233725-9ba8df137936 // indirect
github.com/envoyproxy/go-control-plane/envoy v1.32.4 // indirect
github.com/envoyproxy/protoc-gen-validate v1.2.1 // indirect
Expand Down Expand Up @@ -74,7 +72,6 @@ require (
github.com/pelletier/go-toml/v2 v2.2.4 // indirect
github.com/perimeterx/marshmallow v1.1.5 // indirect
github.com/planetscale/vtprotobuf v0.6.1-0.20240319094008-0393e58bdf10 // indirect
github.com/pmezard/go-difflib v1.0.0 // indirect
github.com/quic-go/qpack v0.5.1 // indirect
github.com/quic-go/quic-go v0.55.0 // indirect
github.com/rogpeppe/go-internal v1.14.1 // indirect
Expand Down
20 changes: 0 additions & 20 deletions internal/domain/announcement.go

This file was deleted.

27 changes: 0 additions & 27 deletions internal/external/announcement.go

This file was deleted.

59 changes: 38 additions & 21 deletions internal/handler/announcement.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import (

"github.com/gin-gonic/gin"

api "github.com/fun-dotto/api-template/generated"
"github.com/fun-dotto/api-template/generated/external/announcement_api"
"github.com/fun-dotto/api-template/internal/middleware"
)

Expand All @@ -15,15 +15,18 @@ func (h *Handler) AnnouncementsV1List(c *gin.Context) {
return
}

announcements, err := h.announcementService.List(c.Request.Context())
response, err := h.announcementClient.AnnouncementsV1ListWithResponse(c.Request.Context(), nil)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

c.JSON(http.StatusOK, api.AnnouncementsV1List200JSONResponse{
Announcements: ToAPIAnnouncements(announcements),
})
if response.JSON200 == nil {
c.JSON(response.StatusCode(), gin.H{"error": "unexpected response from upstream"})
return
}

c.JSON(http.StatusOK, response.JSON200)
}

// AnnouncementsV1Detail 詳細を取得する
Expand All @@ -32,15 +35,18 @@ func (h *Handler) AnnouncementsV1Detail(c *gin.Context, id string) {
return
}

announcement, err := h.announcementService.Detail(c.Request.Context(), id)
response, err := h.announcementClient.AnnouncementsV1DetailWithResponse(c.Request.Context(), id)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

c.JSON(http.StatusOK, api.AnnouncementsV1Detail200JSONResponse{
Announcement: ToAPIAnnouncement(announcement),
})
if response.JSON200 == nil {
c.JSON(response.StatusCode(), gin.H{"error": "unexpected response from upstream"})
return
}

c.JSON(http.StatusOK, response.JSON200)
}

// AnnouncementsV1Create 新規作成する
Expand All @@ -49,21 +55,24 @@ func (h *Handler) AnnouncementsV1Create(c *gin.Context) {
return
}

var req api.AnnouncementServiceAnnouncementRequest
var req announcement_api.AnnouncementRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

announcement, err := h.announcementService.Create(c.Request.Context(), ToDomainAnnouncementRequest(&req))
response, err := h.announcementClient.AnnouncementsV1CreateWithResponse(c.Request.Context(), req)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

c.JSON(http.StatusCreated, api.AnnouncementsV1Create201JSONResponse{
Announcement: ToAPIAnnouncement(announcement),
})
if response.JSON201 == nil {
c.JSON(response.StatusCode(), gin.H{"error": "unexpected response from upstream"})
return
}

c.JSON(http.StatusCreated, response.JSON201)
}

// AnnouncementsV1Delete 削除する
Expand All @@ -72,13 +81,18 @@ func (h *Handler) AnnouncementsV1Delete(c *gin.Context, id string) {
return
}

if err := h.announcementService.Delete(c.Request.Context(), id); err != nil {
response, err := h.announcementClient.AnnouncementsV1DeleteWithResponse(c.Request.Context(), id)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

if response.StatusCode() != http.StatusNoContent {
c.JSON(response.StatusCode(), gin.H{"error": "unexpected response from upstream"})
return
}

c.Status(http.StatusNoContent)
c.Writer.WriteHeaderNow()
}

// AnnouncementsV1Update 更新する
Expand All @@ -87,19 +101,22 @@ func (h *Handler) AnnouncementsV1Update(c *gin.Context, id string) {
return
}

var req api.AnnouncementServiceAnnouncementRequest
var req announcement_api.AnnouncementRequest
if err := c.ShouldBindJSON(&req); err != nil {
c.JSON(http.StatusBadRequest, gin.H{"error": err.Error()})
return
}

announcement, err := h.announcementService.Update(c.Request.Context(), id, ToDomainAnnouncementRequest(&req))
response, err := h.announcementClient.AnnouncementsV1UpdateWithResponse(c.Request.Context(), id, req)
if err != nil {
c.JSON(http.StatusInternalServerError, gin.H{"error": err.Error()})
return
}

c.JSON(http.StatusOK, api.AnnouncementsV1Update200JSONResponse{
Announcement: ToAPIAnnouncement(announcement),
})
if response.JSON200 == nil {
c.JSON(response.StatusCode(), gin.H{"error": "unexpected response from upstream"})
return
}

c.JSON(http.StatusOK, response.JSON200)
}
Loading