From 5b3bf88f7aa710467fcd61dc35d66c336f789466 Mon Sep 17 00:00:00 2001 From: gari8 Date: Thu, 18 May 2023 00:09:09 +0900 Subject: [PATCH] ref #38 fix author name --- controller/report.go | 48 ++-------------------- entity/report.go | 2 + infrastructure/persistence/model/report.go | 5 +++ 3 files changed, 10 insertions(+), 45 deletions(-) diff --git a/controller/report.go b/controller/report.go index 2ea5f6c..8d18a4c 100644 --- a/controller/report.go +++ b/controller/report.go @@ -4,7 +4,6 @@ import ( "github.com/fy23-gw-gackathon/reportify-backend/entity" "github.com/gin-gonic/gin" "net/http" - "time" ) type ReportController struct { @@ -18,24 +17,7 @@ func NewReportController(u ReportUseCase) *ReportController { // ReportsResponse - 日報リストレスポンス type ReportsResponse struct { // 日報リスト - Reports []*ReportResponse `json:"reports"` -} - -type ReportResponse struct { - // 日報レスポンス - ID string `json:"id"` - // ユーザID - UserID string `json:"userId"` - // ユーザ名 - UserName string `json:"userName"` - // 本文 - Body string `json:"body"` - // レビュー本文 - ReviewBody *string `json:"reviewBody"` - // 実施したタスクリスト - Tasks []entity.Task `json:"tasks"` - // 作成日時 - Timestamp time.Time `json:"timestamp"` + Reports []*entity.Report `json:"reports"` } // GetReports godoc @@ -58,19 +40,7 @@ func (c *ReportController) GetReports(ctx *gin.Context) (interface{}, error) { if err != nil { return nil, err } - var reportResponses []*ReportResponse - for _, report := range reports { - reportResponses = append(reportResponses, &ReportResponse{ - ID: report.ID, - UserID: report.UserID, - UserName: oUser.UserName, - Body: report.Body, - ReviewBody: report.ReviewBody, - Tasks: report.Tasks, - Timestamp: report.Timestamp, - }) - } - return ReportsResponse{Reports: reportResponses}, nil + return ReportsResponse{Reports: reports}, nil } // GetReport godoc @@ -90,19 +60,7 @@ func (c *ReportController) GetReport(ctx *gin.Context) (interface{}, error) { reportId := ctx.Params.ByName("reportId") user, _ := ctx.Get(entity.ContextKeyUser) oUser := user.(*entity.OrganizationUser) - report, err := c.ReportUseCase.GetReport(ctx, oUser.OrganizationID, reportId) - if err != nil { - return nil, err - } - return &ReportResponse{ - ID: reportId, - UserID: report.UserID, - UserName: oUser.UserName, - Body: report.Body, - ReviewBody: report.ReviewBody, - Tasks: report.Tasks, - Timestamp: report.Timestamp, - }, nil + return c.ReportUseCase.GetReport(ctx, oUser.OrganizationID, reportId) } // CreateReportRequest - 日報作成リクエスト diff --git a/entity/report.go b/entity/report.go index 9f7cc1b..226ddf5 100644 --- a/entity/report.go +++ b/entity/report.go @@ -7,6 +7,8 @@ type Report struct { ID string `json:"id"` // ユーザID UserID string `json:"userId"` + // ユーザー名 + UserName string `json:"userName"` // 本文 Body string `json:"body"` // レビュー本文 diff --git a/infrastructure/persistence/model/report.go b/infrastructure/persistence/model/report.go index 63320cf..1b4680b 100644 --- a/infrastructure/persistence/model/report.go +++ b/infrastructure/persistence/model/report.go @@ -23,9 +23,14 @@ func (m Report) ToEntity() *entity.Report { for _, t := range m.Tasks { tasks = append(tasks, *t.ToEntity()) } + var userName string + if m.User != nil { + userName = m.User.Name + } return &entity.Report{ ID: m.ID, UserID: m.UserID, + UserName: userName, Body: m.Body, ReviewBody: m.ReviewBody, Tasks: tasks,