-
Notifications
You must be signed in to change notification settings - Fork 0
/
student.go
116 lines (97 loc) · 3.08 KB
/
student.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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
package gopddikti
import (
"fmt"
"net/http"
"strings"
"time"
)
const (
getStudentDetailPath = "/detail_mhs"
)
type StudentDetail struct {
GeneralInfo StudentGeneralData `json:"dataumum"`
StudyHistory []StudentStudyData `json:"datastudi"`
StudyStatuses []StudentStatusData `json:"datastatuskuliah"`
}
type StudentGeneralData struct {
Gender string `json:"jk"`
Status string `json:"ket_keluar"`
ProgrammeDetailID string `json:"link_prodi"`
CollegeDetailID string `json:"link_pt"`
StartYear string `json:"mulai_smt"`
DegreeLevel string `json:"namajenjang"`
Programme string `json:"namaprodi"`
College string `json:"namapt"`
NIM string `json:"nipd"`
RegistrationStatus string `json:"nm_jns_daftar"`
Name string `json:"nm_pd"`
InitialProgramme string `json:"nm_prodi_asal"`
InitialCollege string `json:"nm_pt_asal"`
CertificateNumber string `json:"no_seri_ijazah"`
RegistrationNumber string `json:"reg_pd"`
GraduationDate time.Time `json:"tgl_keluar"`
}
type StudentStudyData struct {
Semester string `json:"id_smt"`
SubjectCode string `json:"kode_mk"`
SubjectGrade string `json:"nilai_huruf"`
SubjectName string `json:"nm_mk"`
SubjectCredits int `json:"sks_mk"`
}
type StudentStatusData struct {
Semester string `json:"id_smt"`
SemesterStatus string `json:"nm_stat_mhs"`
SemesterCredits int `json:"sks_smt"`
}
// GetStudentDetailByNIM is used to get the student information in detail.
// It receives NIM in the type of string as parameter.
func (c *Client) GetStudentDetailByNIM(nim string) (res StudentDetail, err error) {
raw, err := c.searchStudents(nim)
if err != nil {
return
}
if len(raw.Students) < 1 {
err = fmt.Errorf("empty result for id: %s", nim)
return
}
match := strings.Split(raw.Students[0].WebsiteLink, "/")
if len(match) < 3 || strings.TrimSpace(match[2]) == "" {
err = fmt.Errorf("invalid result for id: %s", nim)
return
}
res, err = c.getStudentDetail(match[2])
if err != nil {
return
}
return
}
// GetStudentDetailByDetailID is used to get the student information in detail.
// It receives detailID as parameter.
func (c *Client) GetStudentDetailByDetailID(detailID string) (res StudentDetail, err error) {
return c.getStudentDetail(detailID)
}
func (c *Client) getStudentDetail(detailID string) (res StudentDetail, err error) {
if err = checkParamString(detailID); err != nil {
return
}
req, err := c.createRequest(http.MethodGet, getStudentDetailPath+"/"+detailID)
if err != nil {
return
}
err = c.doRequest(req, &res)
if err != nil {
return
}
res.splitStudentDetailID()
return
}
func (r *StudentDetail) splitStudentDetailID() {
collegeDetailID := strings.Split(r.GeneralInfo.CollegeDetailID, "/")
if len(collegeDetailID) == 3 {
r.GeneralInfo.CollegeDetailID = collegeDetailID[2]
}
programmeDetailID := strings.Split(r.GeneralInfo.ProgrammeDetailID, "/")
if len(programmeDetailID) == 3 {
r.GeneralInfo.ProgrammeDetailID = programmeDetailID[2]
}
}