@@ -15,19 +15,14 @@ type CommentWithUser = ItemWithUser[Comment]
15
15
['/api/v1/:username/:repo_name/issues/count' ]
16
16
fn (mut app App) handle_issues_count (username string , repo_name string ) vweb.Result {
17
17
has_access := app.has_user_repo_read_access_by_repo_name (app.user.id, username, repo_name)
18
-
19
18
if ! has_access {
20
19
return app.json_error ('Not found' )
21
20
}
22
-
23
21
repo := app.find_repo_by_name_and_username (repo_name, username)
24
-
25
22
if repo.id == 0 {
26
23
return app.json_error ('Not found' )
27
24
}
28
-
29
25
count := app.get_repo_issue_count (repo.id)
30
-
31
26
return app.json (api.ApiIssueCount{
32
27
success: true
33
28
result: count
@@ -39,13 +34,10 @@ pub fn (mut app App) new_issue(username string, repo_name string) vweb.Result {
39
34
if ! app.logged_in {
40
35
return app.not_found ()
41
36
}
42
-
43
37
repo := app.find_repo_by_name_and_username (repo_name, username)
44
-
45
38
if repo.id == 0 {
46
39
return app.not_found ()
47
40
}
48
-
49
41
return $vweb.html ()
50
42
}
51
43
@@ -60,33 +52,24 @@ pub fn (mut app App) handle_add_repo_issue(username string, repo_name string) vw
60
52
if ! app.logged_in || (app.logged_in && app.user.posts_count > = posts_per_day) {
61
53
return app.redirect_to_index ()
62
54
}
63
-
64
55
repo := app.find_repo_by_name_and_username (repo_name, username)
65
-
66
56
if repo.id == 0 {
67
57
return app.not_found ()
68
58
}
69
-
70
59
title := app.form['title' ]
71
60
text := app.form['text' ]
72
-
73
61
is_title_empty := validation.is_string_empty (title)
74
62
is_text_empty := validation.is_string_empty (text)
75
-
76
63
if is_title_empty || is_text_empty {
77
64
return app.redirect ('/${username} /${repo_name} /issues/new' )
78
65
}
79
-
80
66
app.increment_user_post (mut app.user) or { app.info (err.str ()) }
81
67
app.add_issue (repo.id, app.user.id, title, text) or { app.info (err.str ()) }
82
68
app.increment_repo_issues (repo.id) or { app.info (err.str ()) }
83
-
84
69
has_first_issue_activity := app.has_activity (app.user.id, 'first_issue' )
85
-
86
70
if ! has_first_issue_activity {
87
71
app.add_activity (app.user.id, 'first_issue' ) or { app.info (err.str ()) }
88
72
}
89
-
90
73
return app.redirect ('/${username} /${repo_name} /issues' )
91
74
}
92
75
@@ -98,25 +81,19 @@ pub fn (mut app App) handle_get_repo_issues(username string, repo_name string) v
98
81
['/:username/:repo_name/issues/:page' ]
99
82
pub fn (mut app App) issues (username string , repo_name string , page int ) vweb.Result {
100
83
repo := app.find_repo_by_name_and_username (repo_name, username)
101
-
102
84
if repo.id == 0 {
103
- app.not_found ()
85
+ return app.not_found ()
104
86
}
105
-
106
87
mut issues_with_users := []IssueWithUser{}
107
-
108
88
for issue in app.find_repo_issues_as_page (repo.id, page) {
109
89
user := app.get_user_by_id (issue.author_id) or { continue }
110
-
111
90
issues_with_users << IssueWithUser{
112
91
item: issue
113
92
user: user
114
93
}
115
94
}
116
-
117
95
mut first := false
118
96
mut last := false
119
-
120
97
if repo.open_issues_count > commits_per_page {
121
98
offset := page * commits_per_page
122
99
delta := repo.open_issues_count - offset
@@ -131,35 +108,27 @@ pub fn (mut app App) issues(username string, repo_name string, page int) vweb.Re
131
108
last = true
132
109
first = true
133
110
}
134
-
135
111
page_count := calculate_pages (repo.open_issues_count, commits_per_page)
136
112
prev_page , next_page := generate_prev_next_pages (page)
137
-
138
113
return $vweb.html ()
139
114
}
140
115
141
116
['/:username/:repo_name/issue/:id' ]
142
117
pub fn (mut app App) issue (username string , repo_name string , id string ) vweb.Result {
143
118
repo := app.find_repo_by_name_and_username (repo_name, username)
144
-
145
119
if repo.id == 0 {
146
120
return app.not_found ()
147
121
}
148
-
149
122
issue := app.find_issue_by_id (id.int ()) or { return app.not_found () }
150
123
issue_author := app.get_user_by_id (issue.author_id) or { return app.not_found () }
151
-
152
124
mut comments_with_users := []CommentWithUser{}
153
-
154
125
for comment in app.get_all_issue_comments (issue.id) {
155
126
user := app.get_user_by_id (comment.author_id) or { continue }
156
-
157
127
comments_with_users << CommentWithUser{
158
128
item: comment
159
129
user: user
160
130
}
161
131
}
162
-
163
132
return $vweb.html ()
164
133
}
165
134
@@ -168,27 +137,21 @@ pub fn (mut app App) user_issues(username string, page int) vweb.Result {
168
137
if ! app.logged_in {
169
138
return app.not_found ()
170
139
}
171
-
172
140
if app.user.username != username {
173
141
return app.not_found ()
174
142
}
175
-
176
143
exists , user := app.check_username (username)
177
-
178
144
if ! exists {
179
145
return app.not_found ()
180
146
}
181
-
182
147
mut issues := app.find_user_issues (user.id)
183
148
mut first := false
184
149
mut last := false
185
-
186
150
for i, issue in issues {
187
151
repo := app.find_repo_by_id (issue.repo_id)
188
152
issues[i].repo_author = repo.user_name
189
153
issues[i].repo_name = repo.name
190
154
}
191
-
192
155
if issues.len > commits_per_page {
193
156
offset := page * commits_per_page
194
157
delta := issues.len - offset
@@ -203,24 +166,18 @@ pub fn (mut app App) user_issues(username string, page int) vweb.Result {
203
166
last = true
204
167
first = true
205
168
}
206
-
207
169
mut issues_with_users := []IssueWithUser{}
208
-
209
170
for issue in issues {
210
171
issue_author := app.get_user_by_id (issue.author_id) or { continue }
211
-
212
172
issues_with_users << IssueWithUser{
213
173
item: issue
214
174
user: issue_author
215
175
}
216
176
}
217
-
218
177
mut last_site := 0
219
178
if page > 0 {
220
179
last_site = page - 1
221
180
}
222
-
223
181
next_site := page + 1
224
-
225
182
return $vweb.html ()
226
183
}
0 commit comments