MCPcopy Index your code
hub / github.com/dnote/dnote / parseGetNotesQuery

Function parseGetNotesQuery

pkg/server/controllers/notes.go:69–116  ·  view source on GitHub ↗
(q url.Values)

Source from the content-addressed store, hash-verified

67}
68
69func parseGetNotesQuery(q url.Values) (app.GetNotesParams, error) {
70 yearStr := q.Get("year")
71 monthStr := q.Get("month")
72 books := q["book"]
73 pageStr := q.Get("page")
74
75 page, err := parsePageQuery(q)
76 if err != nil {
77 return app.GetNotesParams{}, errors.Errorf("invalid page %s", pageStr)
78 }
79 if page < 1 {
80 return app.GetNotesParams{}, errors.Errorf("invalid page %s", pageStr)
81 }
82
83 var year int
84 if len(yearStr) > 0 {
85 y, err := strconv.Atoi(yearStr)
86 if err != nil {
87 return app.GetNotesParams{}, errors.Errorf("invalid year %s", yearStr)
88 }
89
90 year = y
91 }
92
93 var month int
94 if len(monthStr) > 0 {
95 m, err := strconv.Atoi(monthStr)
96 if err != nil {
97 return app.GetNotesParams{}, errors.Errorf("invalid month %s", monthStr)
98 }
99 if m < 1 || m > 12 {
100 return app.GetNotesParams{}, errors.Errorf("invalid month %s", monthStr)
101 }
102
103 month = m
104 }
105
106 ret := app.GetNotesParams{
107 Year: year,
108 Month: month,
109 Page: page,
110 Search: parseSearchQuery(q),
111 Books: books,
112 PerPage: notesPerPage,
113 }
114
115 return ret, nil
116}
117
118func (n *Notes) getNotes(r *http.Request) (app.GetNotesResult, app.GetNotesParams, error) {
119 user := context.User(r.Context())

Callers 1

getNotesMethod · 0.85

Calls 2

parsePageQueryFunction · 0.85
parseSearchQueryFunction · 0.85

Tested by

no test coverage detected