Skip to content

Commit ffae726

Browse files
authored
Add support for noticeboards (#29)
Add noticeboard support to list them and download the attachments. Key changes: Architectural restructuring - Broke down the monolithic adapter.go into specialized receivers: - agenda.go - AgendaReceiver interface and implementation - grades.go - GradesReceiver interface and implementation - noticeboards.go - NoticeboardsReceiver interface and implementation (NEW) - spaggiari.go - Centralized SpaggiariClient with Get/Post methods New Noticeboard Feature - Complete implementation for: - Listing noticeboards (adapters/spaggiari/noticeboards.go:18) - Marking noticeboards as read (adapters/spaggiari/noticeboards.go:48) - Downloading attachments (adapters/spaggiari/noticeboards.go:63) - CLI commands for listing and downloading (entrypoints/cli/cmd/noticeboards/) Improved Code Reusability: - Created SpaggiariClient with shared Get/Post methods and Unmarshal callback pattern - Eliminated code duplication across agenda, grades, and noticeboards Test Improvements: - Updated mocks to use testify/mock v2.42.0 style - Fixed mock initialization in tests - Added proper mock expectations
1 parent 015797a commit ffae726

38 files changed

+1118
-318
lines changed

.gitignore

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,3 +22,15 @@ dist/
2222

2323
# gon
2424
unused.*.zip
25+
26+
# python
27+
venv
28+
29+
# jetbrains ides
30+
.idea
31+
32+
# misc
33+
*.pdf
34+
35+
# macOS
36+
.DS_Store

.tool-versions

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
golang 1.20.2
1+
golang 1.25.1
22
golangci-lint 1.52.0
33
mockery 2.12.0

Makefile

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,15 @@
11
build:
22
go build -o classeviva -v entrypoints/cli/main.go
33

4-
mocks:
5-
mockery --dir adapters/spaggiari --name LoaderStorer --name Fetcher --name Adapter
4+
mock:
5+
mockery --dir adapters/spaggiari --name AgendaReceiver
6+
mockery --dir adapters/spaggiari --name Client
7+
mockery --dir adapters/spaggiari --name Fetcher
8+
mockery --dir adapters/spaggiari --name GradesReceiver
9+
mockery --dir adapters/spaggiari --name HTTPClient
10+
mockery --dir adapters/spaggiari --name LoaderStorer
11+
mockery --dir adapters/spaggiari --name NoticeboardsReceiver
12+
613
mockery --dir commands --name Command
714

815
test:

README.md

Lines changed: 80 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,32 @@
22

33
Classeviva is a Go library and CLI tool to access the popular school portal https://web.spaggiari.eu.
44

5-
## Grades
5+
## CLI Commands
66

7-
Text output:
7+
### Version
8+
9+
Display the application version:
10+
11+
```shell
12+
$ classeviva version
13+
Classeviva CLI v0.0.0 (123) 2022-05-08 by zmoog
14+
```
15+
16+
JSON output:
17+
18+
```shell
19+
$ classeviva version --format json
20+
{
21+
"version": "v0.0.0",
22+
"commit": "123",
23+
"date": "2022-05-08",
24+
"builtBy": "zmoog"
25+
}
26+
```
27+
28+
### Grades
29+
30+
List student grades with optional limit:
831

932
```text
1033
$ classeviva grades list --limit 3
@@ -14,7 +37,7 @@ $ classeviva grades list --limit 3
1437
| 2022-04-27 | 9 | ARTE E IMMAGINE | |
1538
| 2022-04-22 | 7+ | COMPORTAMENTO | comportamento della settimana |
1639
| | 7 | SCIENZE | |
17-
+------------+-------+-----------------+-------------------------------+%
40+
+------------+-------+-----------------+-------------------------------+
1841
```
1942

2043
JSON output:
@@ -33,9 +56,9 @@ $ classeviva grades list --limit 1 --format json
3356
]
3457
```
3558

36-
## Agenda
59+
### Agenda
3760

38-
Text output:
61+
List agenda items (homework, events) with optional date range and limit:
3962

4063
```text
4164
$ classeviva agenda list --limit 2
@@ -49,8 +72,8 @@ $ classeviva agenda list --limit 2
4972

5073
JSON output:
5174

52-
```text
53-
$ classeviva agenda list --until 2022-04-27 --limit 2
75+
```shell
76+
$ classeviva agenda list --until 2022-04-27 --limit 2 --format json
5477
[
5578
{
5679
"evtId": 546249,
@@ -72,3 +95,53 @@ $ classeviva agenda list --until 2022-04-27 --limit 2
7295
}
7396
]
7497
```
98+
99+
### Noticeboards
100+
101+
List school announcements and circulars:
102+
103+
```text
104+
$ classeviva noticeboards list
105+
+---------------------+------+---------------------------------------+
106+
| PUBLICATIONDATE | READ | TITLE |
107+
+---------------------+------+---------------------------------------+
108+
| 2022-04-28T10:30:00 | true | Comunicazione assemblea di istituto |
109+
| 2022-04-25T15:45:00 | false| Circolare n. 123 - Uscita anticipata |
110+
+---------------------+------+---------------------------------------+
111+
```
112+
113+
JSON output:
114+
115+
```shell
116+
$ classeviva noticeboards list --format json
117+
[
118+
{
119+
"pubId": 12345,
120+
"cntTitle": "Comunicazione assemblea di istituto",
121+
"readStatus": true,
122+
"pubDT": "2022-04-28T10:30:00",
123+
"evtCode": "CF",
124+
"cntValidInRange": true,
125+
"cntStatus": "active",
126+
"cntCategory": "General",
127+
"cntHasAttach": true,
128+
"attachments": [
129+
{
130+
"fileName": "comunicazione.pdf",
131+
"attachNum": 1
132+
}
133+
]
134+
}
135+
]
136+
```
137+
138+
Download noticeboard attachments:
139+
140+
```shell
141+
$ classeviva noticeboards download --publication_id 12345 --output-filename ./downloads
142+
+----------------------------------+
143+
| FILE |
144+
+----------------------------------+
145+
| ./downloads/12345-documento.pdf |
146+
+----------------------------------+
147+
```

adapters/spaggiari/adapter.go

Lines changed: 0 additions & 143 deletions
This file was deleted.

adapters/spaggiari/agenda.go

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
package spaggiari
2+
3+
import (
4+
"encoding/json"
5+
"time"
6+
)
7+
8+
type AgendaReceiver interface {
9+
List(since, until time.Time) ([]AgendaEntry, error)
10+
}
11+
12+
type agendaReceiver struct {
13+
Client SpaggiariClient
14+
IdentityProvider Provider
15+
}
16+
17+
func (r agendaReceiver) List(since, until time.Time) ([]AgendaEntry, error) {
18+
identity, err := r.IdentityProvider.Get()
19+
if err != nil {
20+
return []AgendaEntry{}, err
21+
}
22+
23+
_since := since.Format("20060102")
24+
_until := until.Format("20060102")
25+
26+
url := baseUrl + "/students/" + identity.ID + "/agenda/all/" + _since + "/" + _until
27+
28+
entries := []AgendaEntry{}
29+
30+
err = r.Client.Get(url, func(body []byte) error {
31+
envelope := map[string][]AgendaEntry{}
32+
33+
err := json.Unmarshal(body, &envelope)
34+
if err != nil {
35+
return err
36+
}
37+
38+
entries = envelope["agenda"]
39+
40+
return nil
41+
})
42+
if err != nil {
43+
return []AgendaEntry{}, err
44+
}
45+
46+
return entries, nil
47+
}

adapters/spaggiari/grades.go

Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package spaggiari
2+
3+
import "encoding/json"
4+
5+
type GradesReceiver interface {
6+
List() ([]Grade, error)
7+
}
8+
9+
type gradeReceiver struct {
10+
Client SpaggiariClient
11+
IdentityProvider Provider
12+
}
13+
14+
func (r gradeReceiver) List() ([]Grade, error) {
15+
identity, err := r.IdentityProvider.Get()
16+
if err != nil {
17+
return []Grade{}, err
18+
}
19+
20+
url := baseUrl + "/students/" + identity.ID + "/grades"
21+
22+
grades := []Grade{}
23+
24+
err = r.Client.Get(url, func(body []byte) error {
25+
envelope := map[string][]Grade{}
26+
27+
err := json.Unmarshal(body, &envelope)
28+
if err != nil {
29+
return err
30+
}
31+
32+
grades = envelope["grades"]
33+
34+
return nil
35+
})
36+
if err != nil {
37+
return []Grade{}, err
38+
}
39+
40+
return grades, nil
41+
}

0 commit comments

Comments
 (0)