Skip to content

Commit

Permalink
Merge pull request #39 from fy23-gw-gackathon/fix/#38_report_author_name
Browse files Browse the repository at this point in the history
ref #38 fix author name
  • Loading branch information
gari8 committed May 17, 2023
2 parents 91cfff4 + 5b3bf88 commit 685cbfa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 45 deletions.
48 changes: 3 additions & 45 deletions controller/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import (
"github.com/fy23-gw-gackathon/reportify-backend/entity"
"github.com/gin-gonic/gin"
"net/http"
"time"
)

type ReportController struct {
Expand All @@ -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
Expand All @@ -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
Expand All @@ -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 - 日報作成リクエスト
Expand Down
2 changes: 2 additions & 0 deletions entity/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ type Report struct {
ID string `json:"id"`
// ユーザID
UserID string `json:"userId"`
// ユーザー名
UserName string `json:"userName"`
// 本文
Body string `json:"body"`
// レビュー本文
Expand Down
5 changes: 5 additions & 0 deletions infrastructure/persistence/model/report.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down

0 comments on commit 685cbfa

Please sign in to comment.