Skip to content
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

Merged
merged 6 commits into from
Aug 28, 2023
Merged

add attendee info to ical #445

merged 6 commits into from
Aug 28, 2023

Conversation

iChemy
Copy link
Contributor

@iChemy iChemy commented Aug 2, 2023

arran4/golang-icalを使用しました.

mailtoは一旦
mailto:@ユーザー名のような形にしています.参考

(確認したところ@が入ってないとappleのカレンダーではうまく参加者として表示されなかったため)

attendeeのユーザーIDからユーザー名や表示名を取るために
func (repo *Repository) GetAtendeeMap(events []*domain.Event, info *domain.ConInfo)
usecase/production以下に作成しました.参考

Copy link
Member

@ras0q ras0q left a 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でもいいです)

Copy link
Member

@ras0q ras0q left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

幾つかこめんとしました!

Comment on lines 266 to 268
for _, event := range events {
for _, attendee := range event.Attendees {
user, err := repo.GetUser(attendee.UserID, info)
Copy link
Member

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にする方がパフォーマンスがよくなりますね

@@ -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 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

中身とは関係ないけど差分減らすために元と同じ位置に書くのがよさそう

Comment on lines 179 to 183
vevent.SetDtStampTime(time.Now())
vevent.SetStartAt(e.TimeStart)
vevent.SetEndAt(e.TimeEnd)
vevent.SetCreatedTime(e.CreatedAt)
vevent.SetModifiedAt(e.UpdatedAt)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

FormatはしなくてよくなったんですがUTC()はつけたままでよさそうです

Comment on lines 196 to 202
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))
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここらへんはfmt.Sprintfとics.WithCNを外に出してまとめておくと可読性が上がると思います

@iChemy
Copy link
Contributor Author

iChemy commented Aug 18, 2023

改善してみました.
お時間あるときにレビューをしていただけると嬉しいです:bow:

Copy link
Member

@ras0q ras0q left a 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 Show resolved Hide resolved
presentation/event.go Outdated Show resolved Hide resolved
presentation/event.go Outdated Show resolved Hide resolved
@iChemy
Copy link
Contributor Author

iChemy commented Aug 27, 2023

再度見てもらえると嬉しいです.何度もすみません

router/events.go Outdated
var buf bytes.Buffer
_ = ical.NewEncoder(&buf).Encode(cal)
cal.SerializeTo(&buf)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ここlinterに怒られてるので変更前みたいに

Suggested change
cal.SerializeTo(&buf)
_ = cal.SerializeTo(&buf)

してほしいです:pray: (handlingしてもいいけど)

router/events.go Outdated
Comment on lines 248 to 251
userMap, err := h.Repo.GetUserMap(info)
if err != nil {
return judgeErrorResponse(err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ココでしか使わないならGetUserMapは消してここにそのまま書く方がinterfaceへのメソッドの追加も防げていいのかなと思いました

Copy link
Member

@ras0q ras0q left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

少しだけ書きました:eyes:

@iChemy
Copy link
Contributor Author

iChemy commented Aug 28, 2023

再びご確認いただけますでしょうか.
お手数をおかけしております 😿

Copy link
Member

@ras0q ras0q left a 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
Comment on lines 252 to 254
if errors.Is(domain.ErrInvalidToken, err) {
return forbidden(err, message("token is invalid."), needAuthorization(true))
}
Copy link
Member

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)

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ココの空行いらないです

Copy link
Contributor Author

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)
	}

エラーハンドリング周りのコードは空行無い方が見やすいのでいれない方がいいのはわかったのですが逆に空行を入れるべきときはいつなのか気になりました.

Copy link
Member

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 とかを使うと指摘されます

Copy link
Member

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
Comment on lines 263 to 265
if err != nil {
return judgeErrorResponse(err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

同じerrに対して2回エラーハンドリングしてるためこっちは消してOKです

_ = 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())
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

UTCにしとくのが無難かも

Comment on lines 126 to 135
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)
}
}
Copy link
Member

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
Comment on lines 263 to 265
if err != nil {
return judgeErrorResponse(err)
}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

上で既にハンドリングしてるのでここはいらないです

Copy link
Member

@ras0q ras0q left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

良さそうです:+1:

@iChemy iChemy merged commit e5ef51f into main Aug 28, 2023
4 checks passed
@iChemy iChemy deleted the fix/issue-218 branch August 28, 2023 11:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants