| 1 | module main |
| 2 | |
| 3 | import veb |
| 4 | |
| 5 | @['/:username/feed'] |
| 6 | pub fn (mut app App) user_feed_default(mut ctx Context, username string) veb.Result { |
| 7 | return app.user_feed(mut ctx, username, '0') |
| 8 | } |
| 9 | |
| 10 | @['/:username/feed/:page'] |
| 11 | pub fn (mut app App) user_feed(mut ctx Context, username string, page string) veb.Result { |
| 12 | exists, user := app.check_username(username) |
| 13 | |
| 14 | if !exists || ctx.user.username != user.username { |
| 15 | return ctx.not_found() |
| 16 | } |
| 17 | |
| 18 | page_i := page.int() |
| 19 | user_id := ctx.user.id |
| 20 | item_count := app.get_feed_items_count(user_id) |
| 21 | offset := feed_items_per_page * page_i |
| 22 | page_count := calculate_pages(item_count, feed_items_per_page) |
| 23 | is_first_page := check_first_page(page_i) |
| 24 | is_last_page := check_last_page(item_count, offset, feed_items_per_page) |
| 25 | prev_page, next_page := generate_prev_next_pages(page_i) |
| 26 | |
| 27 | feed := app.build_user_feed_as_page(user_id, offset) |
| 28 | mut items_start_day_group := []int{} |
| 29 | mut last_unique_date := '' |
| 30 | |
| 31 | for item in feed { |
| 32 | item_ymmdd := item.created_at.ymmdd() |
| 33 | |
| 34 | if item_ymmdd != last_unique_date { |
| 35 | items_start_day_group << item.id |
| 36 | |
| 37 | last_unique_date = item_ymmdd |
| 38 | } |
| 39 | } |
| 40 | |
| 41 | return $veb.html() |
| 42 | } |
| 43 | |