forked from hnrss/hnrss
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwhoishiring.go
69 lines (58 loc) · 1.43 KB
/
whoishiring.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
package main
import (
"errors"
"fmt"
"github.com/gin-gonic/gin"
"net/http"
"net/url"
"strings"
)
func HiringCommon(c *gin.Context, query string) {
params := make(url.Values)
if query != "" {
params.Set("query", fmt.Sprintf("\"%s\"", query))
params.Set("hitsPerPage", "1")
}
params.Set("tags", "story,author_whoishiring")
results, err := GetResults(params)
if err != nil {
c.Error(err)
c.String(http.StatusBadGateway, err.Error())
return
}
if len(results.Hits) < 1 {
e := errors.New("No whoishiring stories found")
c.Error(e)
c.String(http.StatusBadGateway, e.Error())
return
}
var sp SearchParams
var op OutputParams
ParseRequest(c, &sp, &op)
sp.Tags = "comment"
if query != "" {
sp.Filters = "parent_id=" + results.Hits[0].ObjectID
} else {
var filters []string
for _, hit := range results.Hits {
filters = append(filters, "parent_id="+hit.ObjectID)
}
sp.Filters = strings.Join(filters, " OR ")
}
sp.SearchAttributes = "default"
op.Title = results.Hits[0].Title
op.Link = "https://news.ycombinator.com/item?id=" + results.Hits[0].ObjectID
Generate(c, &sp, &op)
}
func SeekingEmployees(c *gin.Context) {
HiringCommon(c, "Ask HN: Who is hiring?")
}
func SeekingEmployers(c *gin.Context) {
HiringCommon(c, "Ask HN: Who wants to be hired?")
}
func SeekingFreelance(c *gin.Context) {
HiringCommon(c, "Ask HN: Freelancer? Seeking freelancer?")
}
func SeekingAll(c *gin.Context) {
HiringCommon(c, "")
}