-
Notifications
You must be signed in to change notification settings - Fork 2
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
add attendee info to ical #445
Conversation
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.
icalのライブラリを同時に2つ使うのは怖いので、置き換えるPRも出してもらえると助かります!🙏(別PRでも同PRでもいいです)
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.
幾つかこめんとしました!
usecase/production/event.go
Outdated
for _, event := range events { | ||
for _, attendee := range event.Attendees { | ||
user, err := repo.GetUser(attendee.UserID, info) |
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.
for文の(しかも2重の)中でGetUserを回すのは避けたいです
GetUserをたくさん回すならGetAllUsersを1回叩いてそれをmapにする方がパフォーマンスがよくなりますね
presentation/event.go
Outdated
@@ -214,3 +173,51 @@ func ConvdomainEventToEventDetailRes(src domain.Event) (dst EventDetailRes) { | |||
dst.Model = Model(src.Model) | |||
return | |||
} | |||
|
|||
func iCalVeventFormat(e *domain.Event, host string, attendeeMap map[uuid.UUID]*domain.User) *ics.VEvent { |
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.
中身とは関係ないけど差分減らすために元と同じ位置に書くのがよさそう
presentation/event.go
Outdated
vevent.SetDtStampTime(time.Now()) | ||
vevent.SetStartAt(e.TimeStart) | ||
vevent.SetEndAt(e.TimeEnd) | ||
vevent.SetCreatedTime(e.CreatedAt) | ||
vevent.SetModifiedAt(e.UpdatedAt) |
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.
FormatはしなくてよくなったんですがUTC()はつけたままでよさそうです
presentation/event.go
Outdated
case domain.Attendance: | ||
vevent.AddAttendee(fmt.Sprintf("@%s", userName), ics.ParticipationStatusAccepted, ics.WithCN(userDisplayName)) | ||
case domain.Absent: | ||
vevent.AddAttendee(fmt.Sprintf("@%s", userName), ics.ParticipationStatusDeclined, ics.WithCN(userDisplayName)) | ||
default: | ||
vevent.AddAttendee(fmt.Sprintf("@%s", userName), ics.WithCN(userDisplayName)) | ||
} |
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.
ここらへんはfmt.Sprintfとics.WithCNを外に出してまとめておくと可読性が上がると思います
改善してみました. |
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.
コメント保留したまま出し忘れてました、ごめんなさい
いくつか書きました🙏
再度見てもらえると嬉しいです.何度もすみません |
router/events.go
Outdated
var buf bytes.Buffer | ||
_ = ical.NewEncoder(&buf).Encode(cal) | ||
cal.SerializeTo(&buf) |
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.
ここlinterに怒られてるので変更前みたいに
cal.SerializeTo(&buf) | |
_ = cal.SerializeTo(&buf) |
してほしいです:pray: (handlingしてもいいけど)
router/events.go
Outdated
userMap, err := h.Repo.GetUserMap(info) | ||
if err != nil { | ||
return judgeErrorResponse(err) | ||
} |
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.
ココでしか使わないならGetUserMapは消してここにそのまま書く方がinterfaceへのメソッドの追加も防げていいのかなと思いました
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.
少しだけ書きました:eyes:
再びご確認いただけますでしょうか. |
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.
いくつかお願いします!
多分これ終わったらマージできます
router/events.go
Outdated
if errors.Is(domain.ErrInvalidToken, err) { | ||
return forbidden(err, message("token is invalid."), needAuthorization(true)) | ||
} |
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.
ここはjudgeErrorResponse
に同じような記述があるのでそっちに処理を任せれば十分だと思います
@@ -245,12 +246,25 @@ func (h *Handlers) HandleGetiCalByPrivateID(c echo.Context) error { | |||
if err != nil { | |||
return judgeErrorResponse(err) | |||
} | |||
userMap, err := h.Repo.GetUserMap(info) | |||
users, err := h.Repo.GetAllUsers(false, true, info) | |||
|
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.
ココの空行いらないです
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.
上の空行に関連して疑問に思ったのですが以下の部分(// この行に空行いれた方がいいですか?
)に空行はいれた方がいいでしょうか?
events, err := h.Repo.GetEvents(expr, info)
if err != nil {
return judgeErrorResponse(err)
}
// この行に空行いれた方がいいですか?
users, err := h.Repo.GetAllUsers(false, true, info)
if err != nil {
return judgeErrorResponse(err)
}
エラーハンドリング周りのコードは空行無い方が見やすいのでいれない方がいいのはわかったのですが逆に空行を入れるべきときはいつなのか気になりました.
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.
強い気持ちはないですが個人的には入れたほうがいいです
https://github.com/bombsimon/wsl とかを使うと指摘されます
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.
golangci-lintにもあります
https://golangci-lint.run/usage/linters/#wsl
router/events.go
Outdated
if err != nil { | ||
return judgeErrorResponse(err) | ||
} |
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.
同じerr
に対して2回エラーハンドリングしてるためこっちは消してOKです
presentation/event.go
Outdated
_ = vevent.AddProperty("summary", e.Name) | ||
func iCalVeventFormat(e *domain.Event, host string, userMap map[uuid.UUID]*domain.User) *ics.VEvent { | ||
vevent := ics.NewEvent(e.ID.String()) | ||
vevent.SetDtStampTime(time.Now()) |
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.
UTCにしとくのが無難かも
presentation/event.go
Outdated
userDisplayName := ics.WithCN(user.DisplayName) | ||
switch v.Schedule { | ||
case domain.Attendance: | ||
vevent.AddAttendee(userName, ics.ParticipationStatusAccepted, userDisplayName) | ||
case domain.Absent: | ||
vevent.AddAttendee(userName, ics.ParticipationStatusDeclined, userDisplayName) | ||
default: | ||
vevent.AddAttendee(userName, userDisplayName) | ||
} | ||
} |
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.
デフォルトはics.ParticipationStatusNeedsAction
でいい気がする
その上で↓のように書くと若干きれいになるかもです
participationStatus
はgoならps
とかでもいい
var participationStatus ParticipationStatus
switch v.Schedule {
case domain.Attendance:
participationStatus = ics.ParticipationStatusAccepted
case domain.Absent:
participationStatus = ics.ParticipationStatusDeclined
default:
participationStatus = ics.ParticipationStatusNeedsAction
}
vevent.AddAttendee(userName, ics.WithCN(user.DisplayName), participationStatus)
}
router/events.go
Outdated
if err != nil { | ||
return judgeErrorResponse(err) | ||
} |
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.
上で既にハンドリングしてるのでここはいらないです
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.
良さそうです:+1:
arran4/golang-icalを使用しました.
mailtoは一旦
mailto:@ユーザー名
のような形にしています.参考(確認したところ@が入ってないとappleのカレンダーではうまく参加者として表示されなかったため)
attendeeのユーザーIDからユーザー名や表示名を取るために
func (repo *Repository) GetAtendeeMap(events []*domain.Event, info *domain.ConInfo)
を
usecase/production
以下に作成しました.参考