-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapiPublicationList.go
69 lines (63 loc) · 1.36 KB
/
apiPublicationList.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 webui
import (
"encoding/json"
"io/ioutil"
"log"
"net/http"
"strconv"
"git.mrcyjanek.net/mrcyjanek/jwapi/helpers"
"git.mrcyjanek.net/mrcyjanek/jwapi/libjw"
"git.mrcyjanek.net/mrcyjanek/jwapi/libjw/structs"
)
type Publication struct {
Title string `json:"title"`
Code string `json:"code"`
}
func apiPublicationList(w http.ResponseWriter, req *http.Request) {
jsonData, err := ioutil.ReadFile(helpers.GetDataDir() + "/catalog/Publication.json")
if err != nil {
log.Fatal(err)
}
var publications []structs.DBPublication
err = json.Unmarshal(jsonData, &publications)
if err != nil {
log.Fatal(err)
}
var mylang int
for j := range libjw.MepsMap {
if libjw.MepsMap[j] == string(helpers.Get("lang")) {
mylang = j
break
}
}
var pubs []Publication
for i := range publications {
p := publications[i]
title := "undefined"
code := p.KeySymbol
if p.MepsLanguageID != mylang {
continue
}
if p.Title != "" {
title = p.Title
}
if p.IssueTitle != "" {
title = p.IssueTitle
}
if p.IssueTagNumber != 0 {
code = code + "_" + strconv.Itoa(p.IssueTagNumber)
}
if title != "undefined" && code != "undefined" {
pubs = append(pubs, Publication{
Title: title,
Code: code,
})
}
}
resp, err := json.Marshal(pubs)
if err != nil {
log.Fatal(err)
}
w.Header().Add("Content-Type", "application/json")
w.Write(resp)
}