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

實作 #53 Get popular board list #80

Merged
merged 7 commits into from Feb 19, 2021
Merged

實作 #53 Get popular board list #80

merged 7 commits into from Feb 19, 2021

Conversation

nickyanggg
Copy link
Collaborator

📝 相關的 issue / Related Issues

⛏ 變更內容 / Details of Changes

  • 實作 delivery/http/route_boards.go 中的 getPopularBoardList
  • 實作 usecase/board.go 中的 GetPopularBoards
  • 增加 delivery/http/route_boards_test.go 中的 TestGetPopularBoardList
  • TODO: 依 BoardRecord 中的 number_of_user 遞減排序

因為之前再寫的時候 ptt-backend 是蠻舊版本的,所以就重新 merge、增加了簡單的測試並重發 pr。

@PichuChen PichuChen self-requested a review February 19, 2021 05:12
boards, err := delivery.usecase.GetPopularBoards(context.Background())
if err != nil {
// TODO: record error
delivery.logger.Warningf("find popular board failed: %v", err)
Copy link
Member

Choose a reason for hiding this comment

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

因為使用者沒辦法順利進行某一項功能了,也許這邊應該是使用 Errorf 會更好?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

嗯嗯的確,我馬上改

Copy link
Member

@PichuChen PichuChen left a comment

Choose a reason for hiding this comment

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

LGTM

if err != nil {
// TODO: record error
delivery.logger.Errorf("find popular board failed: %v", err)
w.WriteHeader(http.StatusInternalServerError)
Copy link
Contributor

Choose a reason for hiding this comment

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

建議把w.WriteHeader 放在w.Write上一行, 閱讀起來的連貫性比較好

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

好的

t.Logf("got response %v", rr.Body.String())
responseData := responseMap["data"]
popularBoards := responseData.(map[string]interface{})["items"].([]interface{})
for i := range popularBoards[1:] {
Copy link
Contributor

Choose a reason for hiding this comment

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

可以寫得更直觀一點,另外atoi失敗或不按順序排列就直接t.Fatalf,不用再比較下去了

Suggested change
for i := range popularBoards[1:] {
var prevNum int
for i := range popularBoards{
curr := popularBoards[i].(map[string]interface{})["number_of_user"]
currNum, err := strconv.Atoi(curr.(string))
if err != nil {
t.Fatalf("handler returned unexpected body, invalid number_of_user: got %v",
currNum)
}
if i > 0 && prevNum < currNum {
t.Fatalf("handler returned unexpected body, invalid order: got %v before %v",
prevNum, currNum)
}
prevNum = currNum
}

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

嗯嗯了解,感謝!

Copy link
Contributor

@Julian-Chu Julian-Chu left a comment

Choose a reason for hiding this comment

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

LGTM

@PichuChen PichuChen merged commit 4bb43f4 into Ptt-official-app:development Feb 19, 2021
@PichuChen PichuChen linked an issue Feb 19, 2021 that may be closed by this pull request
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.

[主線] [PTT] 實作熱門看板的看板列表的 http 套件
3 participants