delete mock from this repo

This commit is contained in:
zypherift
2026-08-28 13:16:42 +02:00
parent 5320625d83
commit 09ac4b7f61
12 changed files with 0 additions and 2672 deletions

View File

@@ -1,3 +0,0 @@
mock_kreta_server
auth.json

View File

@@ -1,216 +0,0 @@
package main
import (
"encoding/json"
"fmt"
"net/http"
"time"
)
func fillGradeBlanks(store *Store, grades []Grade) []Grade {
groups := store.GetClassGroups()
groupUid := ""
subjectUid := ""
if len(groups) > 0 {
groupUid = groups[0].Uid
}
for _, g := range store.GetGrades() {
if g.Tantargy.Uid != "" {
subjectUid = g.Tantargy.Uid
break
}
}
for i := range grades {
if grades[i].Uid == "" {
grades[i].Uid = fmt.Sprintf("admin-%d-%d", time.Now().UnixNano(), i)
}
if grades[i].OsztalyCsoport.Uid == "" {
grades[i].OsztalyCsoport.Uid = groupUid
}
if grades[i].Tantargy.Uid == "" {
grades[i].Tantargy.Uid = subjectUid
}
}
return grades
}
func decodeBody(r *http.Request, v any) error {
defer r.Body.Close()
return json.NewDecoder(r.Body).Decode(v)
}
func (s *Server) adminCollection(
get func() any,
set func(*http.Request) error,
) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
switch r.Method {
case http.MethodGet:
writeJSON(w, get())
case http.MethodPut:
if err := set(r); err != nil {
http.Error(w, err.Error(), http.StatusBadRequest)
return
}
w.WriteHeader(http.StatusNoContent)
default:
w.WriteHeader(http.StatusMethodNotAllowed)
}
}
}
func (s *Server) registerAdminRoutes(mux *http.ServeMux) {
mux.HandleFunc("/admin/api/config", s.adminCollection(
func() any { return s.store.GetConfig() },
func(r *http.Request) error {
var v ServerConfig
if err := decodeBody(r, &v); err != nil {
return err
}
s.store.SetConfig(v)
return nil
},
))
mux.HandleFunc("/admin/api/student", s.adminCollection(
func() any { return s.store.GetStudent() },
func(r *http.Request) error {
var v Student
if err := decodeBody(r, &v); err != nil {
return err
}
s.store.SetStudent(v)
return nil
},
))
mux.HandleFunc("/admin/api/classGroups", s.adminCollection(
func() any { return s.store.GetClassGroups() },
func(r *http.Request) error {
var v []ClassGroup
if err := decodeBody(r, &v); err != nil {
return err
}
s.store.SetClassGroups(v)
return nil
},
))
mux.HandleFunc("/admin/api/grades", s.adminCollection(
func() any { return s.store.GetGrades() },
func(r *http.Request) error {
var v []Grade
if err := decodeBody(r, &v); err != nil {
return err
}
s.store.SetGrades(fillGradeBlanks(s.store, v))
return nil
},
))
mux.HandleFunc("/admin/api/homework", s.adminCollection(
func() any { return s.store.GetHomework() },
func(r *http.Request) error {
var v []Homework
if err := decodeBody(r, &v); err != nil {
return err
}
s.store.SetHomework(v)
return nil
},
))
mux.HandleFunc("/admin/api/tests", s.adminCollection(
func() any { return s.store.GetTests() },
func(r *http.Request) error {
var v []Test
if err := decodeBody(r, &v); err != nil {
return err
}
s.store.SetTests(v)
return nil
},
))
mux.HandleFunc("/admin/api/omissions", s.adminCollection(
func() any { return s.store.GetOmissions() },
func(r *http.Request) error {
var v []Omission
if err := decodeBody(r, &v); err != nil {
return err
}
s.store.SetOmissions(v)
return nil
},
))
mux.HandleFunc("/admin/api/lessons", s.adminCollection(
func() any { return s.store.GetLessons() },
func(r *http.Request) error {
var v []Lesson
if err := decodeBody(r, &v); err != nil {
return err
}
s.store.SetLessons(v)
return nil
},
))
mux.HandleFunc("/admin/api/notices", s.adminCollection(
func() any { return s.store.GetNotices() },
func(r *http.Request) error {
var v []NoticeBoardItem
if err := decodeBody(r, &v); err != nil {
return err
}
s.store.SetNotices(v)
return nil
},
))
mux.HandleFunc("/admin/api/infoBoard", s.adminCollection(
func() any { return s.store.GetInfoBoard() },
func(r *http.Request) error {
var v []InfoBoardItem
if err := decodeBody(r, &v); err != nil {
return err
}
s.store.SetInfoBoard(v)
return nil
},
))
mux.HandleFunc("/admin/api/dktSubjects", s.adminCollection(
func() any { return s.store.GetDktSubjects() },
func(r *http.Request) error {
var v []DktSubject
if err := decodeBody(r, &v); err != nil {
return err
}
s.store.SetDktSubjects(v)
return nil
},
))
mux.HandleFunc("/admin/api/averages", s.adminCollection(
func() any { return s.store.GetAverages() },
func(r *http.Request) error {
var v []ClassGroupSubjectAverage
if err := decodeBody(r, &v); err != nil {
return err
}
s.store.SetAverages(v)
return nil
},
))
mux.HandleFunc("/admin/api/reset", func(w http.ResponseWriter, r *http.Request) {
if r.Method != http.MethodPost {
w.WriteHeader(http.StatusMethodNotAllowed)
return
}
s.store.Reset()
w.WriteHeader(http.StatusNoContent)
})
}

View File

@@ -1,55 +0,0 @@
package main
import (
"encoding/json"
"net/http"
)
func writeJSON(w http.ResponseWriter, v any) {
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(v)
}
func (s *Server) handleGetStudent(w http.ResponseWriter, r *http.Request) {
writeJSON(w, s.store.GetStudent())
}
func (s *Server) handleGetClassGroups(w http.ResponseWriter, r *http.Request) {
writeJSON(w, s.store.GetClassGroups())
}
func (s *Server) handleGetNoticeBoard(w http.ResponseWriter, r *http.Request) {
writeJSON(w, s.store.GetNotices())
}
func (s *Server) handleGetInfoBoard(w http.ResponseWriter, r *http.Request) {
writeJSON(w, s.store.GetInfoBoard())
}
func (s *Server) handleGetGrades(w http.ResponseWriter, r *http.Request) {
writeJSON(w, s.store.GetGrades())
}
func (s *Server) handleGetClassGroupAverages(w http.ResponseWriter, r *http.Request) {
writeJSON(w, s.store.GetAverages())
}
func (s *Server) handleGetTimeTable(w http.ResponseWriter, r *http.Request) {
writeJSON(w, s.store.GetLessons())
}
func (s *Server) handleGetOmissions(w http.ResponseWriter, r *http.Request) {
writeJSON(w, s.store.GetOmissions())
}
func (s *Server) handleGetHomework(w http.ResponseWriter, r *http.Request) {
writeJSON(w, s.store.GetHomework())
}
func (s *Server) handleGetTests(w http.ResponseWriter, r *http.Request) {
writeJSON(w, s.store.GetTests())
}
func (s *Server) handleGetDktSubjects(w http.ResponseWriter, r *http.Request) {
writeJSON(w, s.store.GetDktSubjects())
}

View File

@@ -1,257 +0,0 @@
package main
import (
"crypto/rand"
"encoding/base64"
"encoding/json"
"fmt"
"log"
"net/http"
"os"
"sync"
"time"
)
func randomToken() string {
b := make([]byte, 24)
rand.Read(b)
return base64.RawURLEncoding.EncodeToString(b)
}
func base64URL(v any) string {
b, _ := json.Marshal(v)
return base64.RawURLEncoding.EncodeToString(b)
}
func buildIdToken(instituteCode, userId, username, studentName string) string {
header := map[string]string{"alg": "none", "typ": "JWT"}
payload := map[string]any{
"kreta:institute_code": instituteCode,
"kreta:institute_user_id": userId,
"kreta:user_name": username,
"name": studentName,
"role": "Tanulo",
"iat": time.Now().Unix(),
}
sig := make([]byte, 16)
rand.Read(sig)
return base64URL(header) + "." + base64URL(payload) + "." + base64.RawURLEncoding.EncodeToString(sig)
}
type sessionInfo struct {
InstituteCode string `json:"instituteCode"`
UserId string `json:"userId"`
Username string `json:"username"`
}
type AuthStore struct {
mu sync.Mutex
path string
pendingCodes map[string]bool
accessTokens map[string]sessionInfo
refreshTokens map[string]sessionInfo
}
type authFile struct {
AccessTokens map[string]sessionInfo `json:"accessTokens"`
RefreshTokens map[string]sessionInfo `json:"refreshTokens"`
}
func NewAuthStore(path string) *AuthStore {
a := &AuthStore{
path: path,
pendingCodes: map[string]bool{},
accessTokens: map[string]sessionInfo{},
refreshTokens: map[string]sessionInfo{},
}
raw, err := os.ReadFile(path)
if err != nil {
return a
}
var f authFile
if json.Unmarshal(raw, &f) != nil {
return a
}
if f.AccessTokens != nil {
a.accessTokens = f.AccessTokens
}
if f.RefreshTokens != nil {
a.refreshTokens = f.RefreshTokens
}
return a
}
func (a *AuthStore) save() {
raw, err := json.MarshalIndent(authFile{
AccessTokens: a.accessTokens,
RefreshTokens: a.refreshTokens,
}, "", " ")
if err != nil {
return
}
os.WriteFile(a.path, raw, 0o644)
}
func (a *AuthStore) issueCode() string {
a.mu.Lock()
defer a.mu.Unlock()
code := randomToken()
a.pendingCodes[code] = true
return code
}
func (a *AuthStore) consumeCode(code string) bool {
a.mu.Lock()
defer a.mu.Unlock()
if !a.pendingCodes[code] {
return false
}
delete(a.pendingCodes, code)
return true
}
func (a *AuthStore) issueTokens(info sessionInfo) (string, string) {
a.mu.Lock()
defer a.mu.Unlock()
access := randomToken()
refresh := randomToken()
a.accessTokens[access] = info
a.refreshTokens[refresh] = info
a.save()
return access, refresh
}
func (a *AuthStore) consumeRefresh(token string) (sessionInfo, bool) {
a.mu.Lock()
defer a.mu.Unlock()
info, ok := a.refreshTokens[token]
if !ok {
return sessionInfo{}, false
}
delete(a.refreshTokens, token)
a.save()
return info, true
}
func (a *AuthStore) isValidAccess(token string) bool {
a.mu.Lock()
defer a.mu.Unlock()
_, ok := a.accessTokens[token]
return ok
}
func loginPageHTML(code string) string {
return fmt.Sprintf(`<!doctype html>
<html><head><meta charset="utf-8"><title>Mock e-Kréta login</title>
<style>body{font-family:sans-serif;max-width:420px;margin:80px auto;padding:0 16px}
button{width:100%%;padding:12px;font-size:16px;background:#4c6b3a;color:#fff;border:none;border-radius:8px;cursor:pointer}</style>
</head><body>
<h2>Mock e-Kréta bejelentkezés</h2>
<p>Ez a firka mock szerver bejelentkezési képernyője. Nincs szükség valódi felhasználónévre vagy jelszóra.</p>
<form method="get" action="/ellenorzo-student/prod/oauthredirect">
<input type="hidden" name="code" value="%s">
<button type="submit">Belépés mock diákként</button>
</form>
</body></html>`, code)
}
func (s *Server) handleAccountLogin(w http.ResponseWriter, r *http.Request) {
code := s.auth.issueCode()
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write([]byte(loginPageHTML(code)))
}
func (s *Server) handleOauthRedirect(w http.ResponseWriter, r *http.Request) {
code := r.URL.Query().Get("code")
if code == "" {
http.Error(w, "missing code", http.StatusBadRequest)
return
}
w.Header().Set("Content-Type", "text/html; charset=utf-8")
w.Write([]byte("<!doctype html><html><body>OK, code issued: " + code + "</body></html>"))
}
func (s *Server) handleToken(w http.ResponseWriter, r *http.Request) {
if err := r.ParseForm(); err != nil {
http.Error(w, "bad request", http.StatusBadRequest)
return
}
cfg := s.store.GetConfig()
student := s.store.GetStudent()
grantType := r.FormValue("grant_type")
log.Printf(
"connect/token: content-type=%q grant_type=%q username=%q form=%v",
r.Header.Get("Content-Type"), grantType, r.FormValue("username"), r.Form,
)
var info sessionInfo
switch grantType {
case "authorization_code":
code := r.FormValue("code")
if !s.auth.consumeCode(code) {
w.WriteHeader(http.StatusUnauthorized)
return
}
info = sessionInfo{
InstituteCode: cfg.InstituteCode,
UserId: student.Uid,
Username: cfg.Username,
}
case "refresh_token":
token := r.FormValue("refresh_token")
found, ok := s.auth.consumeRefresh(token)
if !ok {
w.WriteHeader(http.StatusBadRequest)
return
}
info = found
case "password":
username := r.FormValue("username")
password := r.FormValue("password")
if username != cfg.Username || password != cfg.Password {
w.WriteHeader(http.StatusUnauthorized)
return
}
info = sessionInfo{
InstituteCode: cfg.InstituteCode,
UserId: student.Uid,
Username: cfg.Username,
}
default:
w.WriteHeader(http.StatusBadRequest)
return
}
access, refresh := s.auth.issueTokens(info)
idToken := buildIdToken(info.InstituteCode, info.UserId, info.Username, student.Nev)
resp := map[string]any{
"id_token": idToken,
"access_token": access,
"expires_in": cfg.AccessTokenTTLSeconds,
"token_type": "Bearer",
"refresh_token": refresh,
"scope": "openid email offline_access kreta-ellenorzo-webapi.public",
}
w.Header().Set("Content-Type", "application/json")
json.NewEncoder(w).Encode(resp)
}
func (s *Server) requireAuth(next http.HandlerFunc) http.HandlerFunc {
return func(w http.ResponseWriter, r *http.Request) {
authz := r.Header.Get("Authorization")
const prefix = "Bearer "
if len(authz) <= len(prefix) || authz[:len(prefix)] != prefix {
w.WriteHeader(http.StatusUnauthorized)
return
}
token := authz[len(prefix):]
if !s.auth.isValidAccess(token) {
w.WriteHeader(http.StatusUnauthorized)
return
}
next(w, r)
}
}

View File

@@ -1,535 +0,0 @@
{
"config": {
"instituteCode": "mockschool",
"username": "student",
"password": "student",
"accessTokenTtlSeconds": 43200
},
"student": {
"Uid": "100",
"Nev": "Teszt Elek",
"Cimek": [
"1234 Budapest, Példa utca 1."
],
"Bankszamla": {
"IsReadOnly": false,
"BankszamlaTulajdonosTipusId": 0
},
"SzuletesiEv": 2008,
"SzuletesiHonap": 9,
"SzuletesiNap": 1,
"EmailCim": "teszt.elek@example.com",
"Telefonszam": "+3612345678",
"TanevUid": "2025/2026",
"Gondviselok": [
{
"Uid": "200",
"Nev": "Teszt Anna",
"EmailCim": "teszt.anna@example.com",
"IsTorvenyesKepviselo": true,
"Telefonszam": "+36301234567"
}
],
"IntezmenyAzonosito": "mockschool",
"IntezmenyNev": "Mock Gimnázium",
"Intezmeny": {
"Uid": "1",
"RovidNev": "Mock Gimnázium",
"TestreszabasBeallitasok": {
"ErtekelesekMegjelenitesenekKesleltetesenekMerteke": 0,
"IsOsztalyAtlagMegjeleniteseEllenorzoben": true,
"IsTanorakTemajaMegtekinthetoEllenorzoben": true,
"KovetkezoTelepitesDatuma": ""
},
"Rendszermodulok": []
}
},
"classGroups": [
{
"Uid": "10,11.A",
"Nev": "11.A",
"OsztalyFonok": {
"Uid": ""
},
"OsztalyFonokHelyettes": {
"Uid": ""
},
"OktatasNevelesiKategoria": {
"Uid": "1",
"Nev": "Gimnázium",
"Leiras": "Nappali gimnáziumi oktatás"
},
"OktatasNevelesiKategoriaSortIndex": 0,
"OktatasNevelesiFeladat": {
"Uid": "",
"Nev": "",
"Leiras": ""
},
"IsAktiv": true,
"Tipus": "Osztaly"
}
],
"grades": [
{
"Uid": "admin-1787910857503014843-0",
"RogzitesDatuma": "2026-08-28T09:53:09.136Z",
"KeszitesDatuma": "2026-08-28T09:53:09.136Z",
"Tantargy": {
"Uid": "1,MATEK",
"Nev": "szia xou",
"Kategoria": {
"Uid": "1",
"Nev": "Kötelező",
"Leiras": ""
},
"SortIndex": 0
},
"Tema": "szia xou",
"Tipus": {
"Uid": "1",
"Nev": "Írásbeli",
"Leiras": ""
},
"ErtekFajta": {
"Uid": "1",
"Nev": "Osztályzat",
"Leiras": ""
},
"ErtekeloTanarNeve": "xou",
"Jelleg": "Ertekeles",
"SzamErtek": 5,
"SzovegesErtek": "Jeles",
"SulySzazalekErteke": 100,
"OsztalyCsoport": {
"Uid": "10,11.A"
},
"SortIndex": 0
},
{
"Uid": "admin-1787910857503016597-1",
"RogzitesDatuma": "2026-08-28T09:53:31.201Z",
"KeszitesDatuma": "2026-08-28T09:53:31.201Z",
"Tantargy": {
"Uid": "1,MATEK",
"Nev": "szia xou",
"Kategoria": {
"Uid": "1",
"Nev": "Kötelező",
"Leiras": ""
},
"SortIndex": 0
},
"Tema": "szia xou",
"Tipus": {
"Uid": "1",
"Nev": "Írásbeli",
"Leiras": ""
},
"ErtekFajta": {
"Uid": "1",
"Nev": "Osztályzat",
"Leiras": ""
},
"ErtekeloTanarNeve": "szia xou",
"Jelleg": "Ertekeles",
"SzamErtek": 4,
"SzovegesErtek": "Jeles",
"SulySzazalekErteke": 100,
"OsztalyCsoport": {
"Uid": "10,11.A"
},
"SortIndex": 0
},
{
"Uid": "admin-1787910857503016887-2",
"RogzitesDatuma": "2026-08-28T09:53:38.256Z",
"KeszitesDatuma": "2026-08-28T09:53:38.256Z",
"Tantargy": {
"Uid": "1,MATEK",
"Nev": "szia xou",
"Kategoria": {
"Uid": "1",
"Nev": "Kötelező",
"Leiras": ""
},
"SortIndex": 0
},
"Tema": "szia xou",
"Tipus": {
"Uid": "1",
"Nev": "Írásbeli",
"Leiras": ""
},
"ErtekFajta": {
"Uid": "1",
"Nev": "Osztályzat",
"Leiras": ""
},
"ErtekeloTanarNeve": "szia xou",
"Jelleg": "Ertekeles",
"SzamErtek": 3,
"SzovegesErtek": "Jeles",
"SulySzazalekErteke": 100,
"OsztalyCsoport": {
"Uid": "10,11.A"
},
"SortIndex": 0
},
{
"Uid": "admin-1787910857503017128-3",
"RogzitesDatuma": "2026-08-28T09:53:39.615Z",
"KeszitesDatuma": "2026-08-28T09:53:39.615Z",
"Tantargy": {
"Uid": "1,MATEK",
"Nev": "szia xou",
"Kategoria": {
"Uid": "1",
"Nev": "Kötelező",
"Leiras": ""
},
"SortIndex": 0
},
"Tema": "szia xou",
"Tipus": {
"Uid": "1",
"Nev": "Írásbeli",
"Leiras": ""
},
"ErtekFajta": {
"Uid": "1",
"Nev": "Osztályzat",
"Leiras": ""
},
"ErtekeloTanarNeve": "szia xou",
"Jelleg": "Ertekeles",
"SzamErtek": 2,
"SzovegesErtek": "Jeles",
"SulySzazalekErteke": 100,
"OsztalyCsoport": {
"Uid": "10,11.A"
},
"SortIndex": 0
},
{
"Uid": "admin-1787910857503017428-4",
"RogzitesDatuma": "2026-08-28T09:53:39.743Z",
"KeszitesDatuma": "2026-08-28T09:53:39.743Z",
"Tantargy": {
"Uid": "1,MATEK",
"Nev": "szia xou",
"Kategoria": {
"Uid": "1",
"Nev": "Kötelező",
"Leiras": ""
},
"SortIndex": 0
},
"Tema": "szia xou",
"Tipus": {
"Uid": "1",
"Nev": "Írásbeli",
"Leiras": ""
},
"ErtekFajta": {
"Uid": "1",
"Nev": "Osztályzat",
"Leiras": ""
},
"ErtekeloTanarNeve": "szia xou",
"Jelleg": "Ertekeles",
"SzamErtek": 1,
"SzovegesErtek": "Jeles",
"SulySzazalekErteke": 100,
"OsztalyCsoport": {
"Uid": "10,11.A"
},
"SortIndex": 0
}
],
"homework": [
{
"Uid": "2000",
"Tantargy": {
"Uid": "2,MAGYAR",
"Nev": "Magyar nyelv és irodalom",
"Kategoria": {
"Uid": "1",
"Nev": "Kötelező",
"Leiras": "Kötelező tantárgy"
},
"SortIndex": 2
},
"TantargyNeve": "Magyar nyelv és irodalom",
"RogzitoTanarNeve": "Nagy Ilona",
"Szoveg": "Olvassátok el az 5. fejezetet.",
"FeladasDatuma": "2026-08-26T00:00:00",
"HataridoDatuma": "2026-09-02T00:00:00",
"RogzitesIdopontja": "2026-08-26T00:00:00",
"IsTanarRogzitette": true,
"IsMegoldva": false,
"IsBeadhato": false,
"OsztalyCsoport": {
"Uid": "10,11.A"
},
"IsCsatolasEngedelyezes": false
}
],
"tests": [
{
"Uid": "3000",
"Datum": "2026-08-31T00:00:00",
"BejelentesDatuma": "2026-08-26T00:00:00",
"RogzitoTanarNeve": "Kovács Béla",
"OrarendiOraOraszama": 2,
"Tantargy": {
"Uid": "1,MATEK",
"Nev": "Matematika",
"Kategoria": {
"Uid": "1",
"Nev": "Kötelező",
"Leiras": "Kötelező tantárgy"
},
"SortIndex": 1
},
"TantargyNeve": "Matematika",
"Temaja": "Trigonometria",
"Modja": {
"Uid": "1",
"Nev": "Írásbeli",
"Leiras": "Írásbeli dolgozat"
},
"OsztalyCsoport": {
"Uid": "10,11.A"
}
}
],
"omissions": [
{
"Uid": "4000",
"Tantargy": {
"Uid": "1,MATEK",
"Nev": "Matematika",
"Kategoria": {
"Uid": "1",
"Nev": "Kötelező",
"Leiras": "Kötelező tantárgy"
},
"SortIndex": 1
},
"Ora": {
"KezdoDatum": "2026-08-24T00:00:00",
"VegDatum": "2026-08-24T00:00:00",
"Oraszam": 1
},
"Datum": "2026-08-24T00:00:00",
"RogzitoTanarNeve": "Kovács Béla",
"Tipus": {
"Uid": "1",
"Nev": "Hiányzás",
"Leiras": "Hiányzás"
},
"Mod": {
"Uid": "",
"Nev": "",
"Leiras": ""
},
"KeszitesDatuma": "2026-08-24T00:00:00",
"IgazolasAllapota": "Igazolt",
"IgazolasTipusa": {
"Uid": "",
"Nev": "",
"Leiras": ""
},
"OsztalyCsoport": {
"Uid": "10,11.A"
}
},
{
"Uid": "",
"Tantargy": {
"Uid": "",
"Nev": "fasz",
"Kategoria": {
"Uid": "1",
"Nev": "Kötelező",
"Leiras": ""
},
"SortIndex": 0
},
"Ora": {
"KezdoDatum": "2026-08-26T20:00:26.713Z",
"VegDatum": "2026-08-26T20:00:26.713Z",
"Oraszam": 1
},
"Datum": "2026-08-26T20:00:26.713Z",
"RogzitoTanarNeve": "fasz",
"Tipus": {
"Uid": "1",
"Nev": "Hiányzás",
"Leiras": ""
},
"Mod": {
"Uid": "",
"Nev": "",
"Leiras": ""
},
"KeszitesDatuma": "2026-08-26T20:00:26.713Z",
"IgazolasAllapota": "Igazolt",
"IgazolasTipusa": {
"Uid": "",
"Nev": "",
"Leiras": ""
},
"OsztalyCsoport": {
"Uid": ""
}
}
],
"lessons": [
{
"Uid": "5000",
"Datum": "2026-08-26T00:00:00",
"KezdetIdopont": "2026-08-26T08:00:00",
"VegIdopont": "2026-08-26T08:45:00",
"Nev": "Matematika",
"Oraszam": 1,
"OsztalyCsoport": {
"Uid": "10,11.A",
"Nev": "11.A"
},
"TanarNeve": "Kovács Béla",
"Tantargy": {
"Uid": "1,MATEK",
"Nev": "Matematika",
"Kategoria": {
"Uid": "1",
"Nev": "Kötelező",
"Leiras": "Kötelező tantárgy"
},
"SortIndex": 1
},
"TeremNeve": "101",
"Tipus": {
"Uid": "1",
"Nev": "Tanóra",
"Leiras": "Normál tanóra"
},
"TanuloJelenlet": {
"Uid": "",
"Nev": "",
"Leiras": ""
},
"Allapot": {
"Uid": "1",
"Nev": "Megtartott",
"Leiras": "Megtartott óra"
},
"IsTanuloHaziFeladatEnabled": true,
"IsHaziFeladatMegoldva": false,
"Csatolmanyok": [],
"IsDigitalisOra": false,
"DigitalisTamogatoEszkozTipusList": [],
"Letrehozas": "2026-07-27T00:00:00",
"UtolsoModositas": "2026-07-27T00:00:00"
},
{
"Uid": "",
"Datum": "2026-08-26T20:15:10.348Z",
"KezdetIdopont": "2026-08-26T20:10:10.348Z",
"VegIdopont": "2026-08-26T20:50:10.348Z",
"Nev": "meow",
"Oraszam": 1,
"OsztalyCsoport": {
"Uid": "",
"Nev": ""
},
"TanarNeve": "meow",
"Tantargy": {
"Uid": "",
"Nev": "meow",
"Kategoria": {
"Uid": "1",
"Nev": "Kötelező",
"Leiras": ""
},
"SortIndex": 0
},
"TeremNeve": "meoow szoba",
"Tipus": {
"Uid": "1",
"Nev": "Tanóra",
"Leiras": ""
},
"TanuloJelenlet": {
"Uid": "",
"Nev": "",
"Leiras": ""
},
"Allapot": {
"Uid": "1",
"Nev": "Megtartott",
"Leiras": ""
},
"IsTanuloHaziFeladatEnabled": true,
"IsHaziFeladatMegoldva": false,
"Csatolmanyok": [],
"IsDigitalisOra": false,
"DigitalisTamogatoEszkozTipusList": [],
"Letrehozas": "2026-08-26T20:15:10.348Z",
"UtolsoModositas": "2026-08-26T20:15:10.348Z"
}
],
"notices": [
{
"Uid": "6000",
"RogzitoNeve": "Igazgatóság",
"ErvenyessegKezdete": "2026-08-26T00:00:00",
"ErvenyessegVege": "2026-09-09T00:00:00",
"Cim": "Őszi szünet",
"Tartalom": "Az őszi szünet előtti utolsó tanítási nap...",
"TartalomText": "Az őszi szünet előtti utolsó tanítási nap..."
}
],
"infoBoard": [
{
"Uid": "7000",
"Cim": "Osztályfőnöki bejegyzés",
"Datum": "2026-08-26T00:00:00",
"KeszitoTanarNeve": "Kovács Béla",
"KeszitesDatuma": "2026-08-26T00:00:00",
"Tartalom": "Dicséret szorgalmi feladatért.",
"TartalomFormazott": "",
"Tipus": {
"Uid": "1",
"Nev": "Dicséret",
"Leiras": "Szaktanári dicséret"
}
}
],
"dktSubjects": [
{
"tantargyId": 1,
"tantargyNev": "Matematika",
"alkalmazottNev": "Kovács Béla",
"osztalyCsoportNev": "11.A",
"tipusId": 0
}
],
"averages": [
{
"Uid": "8000",
"Tantargy": {
"Uid": "1,MATEK",
"Nev": "Matematika",
"Kategoria": {
"Uid": "1",
"Nev": "Kötelező",
"Leiras": "Kötelező tantárgy"
},
"SortIndex": 1
},
"TanuloAtlag": 4.5,
"OsztalyCsoportAtlag": 3.8
}
]
}

View File

@@ -1,3 +0,0 @@
module mock_kreta_server
go 1.26.5

View File

@@ -1,64 +0,0 @@
package main
import (
"embed"
"flag"
"io/fs"
"log"
"net/http"
)
//go:embed static
var staticFiles embed.FS
type Server struct {
store *Store
auth *AuthStore
}
func main() {
addr := flag.String("addr", ":8090", "listen address")
dataPath := flag.String("data", "data.json", "path to the JSON data file")
flag.Parse()
s := &Server{
store: NewStore(*dataPath),
auth: NewAuthStore("auth.json"),
}
mux := http.NewServeMux()
staticContent, err := fs.Sub(staticFiles, "static")
if err != nil {
log.Fatal(err)
}
mux.Handle("/", http.FileServer(http.FS(staticContent)))
mux.HandleFunc("/Account/Login", s.handleAccountLogin)
mux.HandleFunc("/ellenorzo-student/prod/oauthredirect", s.handleOauthRedirect)
mux.HandleFunc("/connect/token", s.handleToken)
mux.HandleFunc("/ellenorzo/v3/sajat/TanuloAdatlap", s.requireAuth(s.handleGetStudent))
mux.HandleFunc("/ellenorzo/v3/sajat/OsztalyCsoportok", s.requireAuth(s.handleGetClassGroups))
mux.HandleFunc("/ellenorzo/v3/sajat/FaliujsagElemek", s.requireAuth(s.handleGetNoticeBoard))
mux.HandleFunc("/ellenorzo/v3/sajat/Feljegyzesek", s.requireAuth(s.handleGetInfoBoard))
mux.HandleFunc("/ellenorzo/v3/sajat/Ertekelesek", s.requireAuth(s.handleGetGrades))
mux.HandleFunc("/ellenorzo/v3/sajat/Ertekelesek/Atlagok/OsztalyAtlagok", s.requireAuth(s.handleGetClassGroupAverages))
mux.HandleFunc("/ellenorzo/v3/sajat/OrarendElemek", s.requireAuth(s.handleGetTimeTable))
mux.HandleFunc("/ellenorzo/v3/sajat/Mulasztasok", s.requireAuth(s.handleGetOmissions))
mux.HandleFunc("/ellenorzo/v3/sajat/HaziFeladatok", s.requireAuth(s.handleGetHomework))
mux.HandleFunc("/ellenorzo/v3/sajat/BejelentettSzamonkeresek", s.requireAuth(s.handleGetTests))
mux.HandleFunc("/dktapi/intezmenyek/munkaterek/tanulok", s.requireAuth(s.handleGetDktSubjects))
s.registerAdminRoutes(mux)
log.Printf("mock kreta server listening on %s (data: %s)", *addr, *dataPath)
log.Fatal(http.ListenAndServe(*addr, logRequests(mux)))
}
func logRequests(next http.Handler) http.Handler {
return http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
log.Printf("%s %s from %s", r.Method, r.URL.String(), r.RemoteAddr)
next.ServeHTTP(w, r)
})
}

View File

@@ -1,211 +0,0 @@
package main
import "time"
func iso(t time.Time) string {
return t.Format("2006-01-02T15:04:05")
}
func seedData() storeData {
now := time.Now()
today := time.Date(now.Year(), now.Month(), now.Day(), 0, 0, 0, 0, now.Location())
mathSubject := Subject{
Uid: "1,MATEK",
Nev: "Matematika",
Kategoria: NameUidDesc{Uid: "1", Nev: "Kötelező", Leiras: "Kötelező tantárgy"},
SortIndex: 1,
}
litSubject := Subject{
Uid: "2,MAGYAR",
Nev: "Magyar nyelv és irodalom",
Kategoria: NameUidDesc{Uid: "1", Nev: "Kötelező", Leiras: "Kötelező tantárgy"},
SortIndex: 2,
}
classGroup := UidRef{Uid: "10,11.A"}
return storeData{
Config: ServerConfig{
InstituteCode: "mockschool",
Username: "student",
Password: "student",
AccessTokenTTLSeconds: 43200,
},
Student: Student{
Uid: "100",
Nev: "Teszt Elek",
Cimek: []string{
"1234 Budapest, Példa utca 1.",
},
Bankszamla: BankAccount{
BankszamlaSzam: "",
IsReadOnly: false,
BankszamlaTulajdonosNeve: "",
BankszamlaTulajdonosTipusId: 0,
},
SzuletesiEv: 2008,
SzuletesiHonap: 9,
SzuletesiNap: 1,
EmailCim: "teszt.elek@example.com",
Telefonszam: "",
TanevUid: "2025/2026",
IntezmenyAzonosito: "mockschool",
IntezmenyNev: "Mock Gimnázium",
Gondviselok: []Guardian{
{
Uid: "200",
Nev: "Teszt Anna",
EmailCim: "teszt.anna@example.com",
IsTorvenyesKepviselo: true,
Telefonszam: "+36301234567",
},
},
Intezmeny: Institution{
Uid: "1",
RovidNev: "Mock Gimnázium",
TestreszabasBeallitasok: CustomizationSettings{
ErtekelesekMegjelenitesenekKesleltetesenekMerteke: 0,
IsOsztalyAtlagMegjeleniteseEllenorzoben: true,
IsTanorakTemajaMegtekinthetoEllenorzoben: true,
KovetkezoTelepitesDatuma: "",
},
Rendszermodulok: []SystemModule{},
},
},
ClassGroups: []ClassGroup{
{
Uid: classGroup.Uid,
Nev: "11.A",
OktatasNevelesiKategoria: NameUidDesc{Uid: "1", Nev: "Gimnázium", Leiras: "Nappali gimnáziumi oktatás"},
IsAktiv: true,
Tipus: "Osztaly",
},
},
Grades: []Grade{
{
Uid: "1000",
RogzitesDatuma: iso(today.Add(-24 * time.Hour)),
KeszitesDatuma: iso(today.Add(-24 * time.Hour)),
Tantargy: mathSubject,
Tema: "Másodfokú egyenletek",
Tipus: NameUidDesc{Uid: "1", Nev: "Írásbeli", Leiras: "Írásbeli felelet"},
ErtekFajta: NameUidDesc{Uid: "1", Nev: "Osztályzat", Leiras: "Osztályzat"},
ErtekeloTanarNeve: "Kovács Béla",
Jelleg: "Ertekeles",
SzamErtek: 5,
SzovegesErtek: "Jeles",
SulySzazalekErteke: 100,
OsztalyCsoport: classGroup,
SortIndex: 1,
},
},
Homework: []Homework{
{
Uid: "2000",
Tantargy: litSubject,
TantargyNeve: litSubject.Nev,
RogzitoTanarNeve: "Nagy Ilona",
Szoveg: "Olvassátok el az 5. fejezetet.",
FeladasDatuma: iso(today),
HataridoDatuma: iso(today.Add(7 * 24 * time.Hour)),
RogzitesIdopontja: iso(today),
IsTanarRogzitette: true,
OsztalyCsoport: classGroup,
},
},
Tests: []Test{
{
Uid: "3000",
Datum: iso(today.Add(5 * 24 * time.Hour)),
BejelentesDatuma: iso(today),
RogzitoTanarNeve: "Kovács Béla",
OrarendiOraOraszama: 2,
Tantargy: mathSubject,
TantargyNeve: mathSubject.Nev,
Temaja: "Trigonometria",
Modja: NameUidDesc{Uid: "1", Nev: "Írásbeli", Leiras: "Írásbeli dolgozat"},
OsztalyCsoport: classGroup,
},
},
Omissions: []Omission{
{
Uid: "4000",
Tantargy: mathSubject,
Ora: &OmittedLesson{
KezdoDatum: iso(today.Add(-48 * time.Hour)),
VegDatum: iso(today.Add(-48*time.Hour + 45*time.Minute)),
Oraszam: 1,
},
Datum: iso(today.Add(-48 * time.Hour)),
RogzitoTanarNeve: "Kovács Béla",
Tipus: NameUidDesc{Uid: "1", Nev: "Hiányzás", Leiras: "Hiányzás"},
KeszitesDatuma: iso(today.Add(-48 * time.Hour)),
IgazolasAllapota: "Igazolt",
OsztalyCsoport: classGroup,
},
},
Lessons: []Lesson{
{
Uid: "5000",
Datum: iso(today),
KezdetIdopont: iso(today.Add(8 * time.Hour)),
VegIdopont: iso(today.Add(8*time.Hour + 45*time.Minute)),
Nev: mathSubject.Nev,
Oraszam: 1,
OsztalyCsoport: NameUid{Uid: classGroup.Uid, Nev: "11.A"},
TanarNeve: "Kovács Béla",
Tantargy: mathSubject,
TeremNeve: "101",
Tipus: NameUidDesc{Uid: "1", Nev: "Tanóra", Leiras: "Normál tanóra"},
Allapot: NameUidDesc{Uid: "1", Nev: "Megtartott", Leiras: "Megtartott óra"},
IsTanuloHaziFeladatEnabled: true,
Csatolmanyok: []NameUid{},
DigitalisTamogatoEszkozTipusList: []string{},
Letrehozas: iso(today.Add(-30 * 24 * time.Hour)),
UtolsoModositas: iso(today.Add(-30 * 24 * time.Hour)),
},
},
Notices: []NoticeBoardItem{
{
Uid: "6000",
RogzitoNeve: "Igazgatóság",
ErvenyessegKezdete: iso(today),
ErvenyessegVege: iso(today.Add(14 * 24 * time.Hour)),
Cim: "Őszi szünet",
Tartalom: "Az őszi szünet előtti utolsó tanítási nap...",
TartalomText: "Az őszi szünet előtti utolsó tanítási nap...",
},
},
InfoBoard: []InfoBoardItem{
{
Uid: "7000",
Cim: "Osztályfőnöki bejegyzés",
Datum: iso(today),
KeszitoTanarNeve: "Kovács Béla",
KeszitesDatuma: iso(today),
Tartalom: "Dicséret szorgalmi feladatért.",
Tipus: NameUidDesc{Uid: "1", Nev: "Dicséret", Leiras: "Szaktanári dicséret"},
},
},
DktSubjects: []DktSubject{
{
TantargyId: 1,
TantargyNev: mathSubject.Nev,
AlkalmazottNev: "Kovács Béla",
OsztalyCsoportNev: "11.A",
TipusId: 0,
},
},
Averages: []ClassGroupSubjectAverage{
{
Uid: "8000",
Tantargy: mathSubject,
TanuloAtlag: 4.5,
OsztalyCsoportAtlag: 3.8,
},
},
}
}
//xdd mi a faszom ez kreta

View File

@@ -1,699 +0,0 @@
function getPath(obj, path) {
return path.split(".").reduce((o, k) => (o == null ? undefined : o[k]), obj);
}
function setPath(obj, path, value) {
const keys = path.split(".");
let o = obj;
for (let i = 0; i < keys.length - 1; i++) {
if (o[keys[i]] == null || typeof o[keys[i]] !== "object") o[keys[i]] = {};
o = o[keys[i]];
}
o[keys[keys.length - 1]] = value;
}
function nowIso() {
return new Date().toISOString();
}
async function getJSON(url) {
const res = await fetch(url);
if (!res.ok) throw new Error(url + ": " + res.status);
return res.json();
}
async function putJSON(url, body) {
const res = await fetch(url, {
method: "PUT",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
if (!res.ok) throw new Error(url + ": " + res.status);
}
function flash(el, message) {
el.textContent = message;
setTimeout(() => {
if (el.textContent === message) el.textContent = "";
}, 2000);
}
function cellInput(row, field, onChange) {
const paths = field.paths || [field.path];
const value = getPath(row, paths[0]);
if (field.type === "bool") {
const input = document.createElement("input");
input.type = "checkbox";
input.checked = !!value;
input.onchange = () => {
paths.forEach((p) => setPath(row, p, input.checked));
onChange();
};
return input;
}
if (field.type === "lines") {
const textarea = document.createElement("textarea");
textarea.rows = 2;
textarea.value = Array.isArray(value) ? value.join("\n") : "";
textarea.onchange = () => {
const list = textarea.value.split("\n").map((s) => s.trim()).filter(Boolean);
paths.forEach((p) => setPath(row, p, list));
onChange();
};
return textarea;
}
const input = document.createElement("input");
input.type = field.type === "number" ? "number" : "text";
input.value = value == null ? "" : value;
input.onchange = () => {
const v = field.type === "number" ? (input.value === "" ? 0 : Number(input.value)) : input.value;
paths.forEach((p) => setPath(row, p, v));
onChange();
}; //i hate js
return input;
}
function renderTable(container, opts) {
container.innerHTML = "";
const toolbar = document.createElement("div");
toolbar.className = "toolbar";
const addBtn = document.createElement("button");
addBtn.textContent = "Add row";
const saveBtn = document.createElement("button");
saveBtn.className = "secondary";
saveBtn.textContent = "Save";
const resetBtn = document.createElement("button");
resetBtn.className = "secondary";
resetBtn.textContent = "Reload";
const status = document.createElement("span");
status.className = "status";
toolbar.append(addBtn, saveBtn, resetBtn, status);
container.appendChild(toolbar);
const table = document.createElement("table");
container.appendChild(table);
let rows = [];
function draw() {
table.innerHTML = "";
const thead = document.createElement("tr");
opts.columns.forEach((c) => {
const th = document.createElement("th");
th.textContent = c.label;
thead.appendChild(th);
});
thead.appendChild(document.createElement("th"));
table.appendChild(thead);
rows.forEach((row, idx) => {
const tr = document.createElement("tr");
opts.columns.forEach((field) => {
const td = document.createElement("td");
td.appendChild(cellInput(row, field, () => {}));
tr.appendChild(td);
});
const actionTd = document.createElement("td");
actionTd.className = "row-actions";
const delBtn = document.createElement("button");
delBtn.className = "danger";
delBtn.textContent = "Delete";
delBtn.onclick = () => {
rows.splice(idx, 1);
draw();
};
actionTd.appendChild(delBtn);
tr.appendChild(actionTd);
table.appendChild(tr);
});
}
addBtn.onclick = () => {
rows.push(JSON.parse(JSON.stringify(opts.template())));
draw();
};
saveBtn.onclick = async () => {
try {
await putJSON(opts.url, rows);
flash(status, "saved");
} catch (e) {
flash(status, "error: " + e.message);
}
};
resetBtn.onclick = load;
async function load() {
rows = await getJSON(opts.url);
draw();
}
load();
}
function renderForm(container, opts) {
container.innerHTML = "";
const status = document.createElement("span");
status.className = "status";
const grid = document.createElement("div");
grid.className = "form-grid";
container.appendChild(grid);
let data = {};
function draw() {
grid.innerHTML = "";
opts.fields.forEach((field) => {
const label = document.createElement("label");
label.textContent = field.label;
grid.appendChild(label);
grid.appendChild(cellInput(data, field, () => {}));
});
}
const toolbar = document.createElement("div");
toolbar.className = "toolbar";
const saveBtn = document.createElement("button");
saveBtn.textContent = "Save";
saveBtn.onclick = async () => {
try {
if (opts.beforeSave) opts.beforeSave(data);
await putJSON(opts.url, data);
flash(status, "saved");
} catch (e) {
flash(status, "error: " + e.message);
}
};
toolbar.append(saveBtn, status);
container.appendChild(toolbar);
container.appendChild(grid);
(async () => {
data = await getJSON(opts.url);
draw();
})();
return {
getSubArray(path) {
if (!getPath(data, path)) setPath(data, path, []);
return getPath(data, path);
},
};
}
const subjectTemplate = () => ({
Uid: "",
Nev: "",
Kategoria: { Uid: "1", Nev: "Kötelező", Leiras: "" },
SortIndex: 0,
});
const nameUidDescTemplate = () => ({ Uid: "", Nev: "", Leiras: "" });
const entities = {
classGroups: {
url: "/admin/api/classGroups",
template: () => ({
Uid: "",
Nev: "",
OsztalyFonok: { Uid: "" },
OsztalyFonokHelyettes: { Uid: "" },
OktatasNevelesiKategoria: { Uid: "1", Nev: "Gimnázium", Leiras: "" },
OktatasNevelesiKategoriaSortIndex: 0,
OktatasNevelesiFeladat: nameUidDescTemplate(),
IsAktiv: true,
Tipus: "Osztaly",
}),
columns: [
{ path: "Nev", label: "Name", type: "text" },
{ path: "Uid", label: "UID", type: "text" },
{ path: "Tipus", label: "Type", type: "text" },
{ path: "IsAktiv", label: "Active", type: "bool" },
{ path: "OktatasNevelesiKategoria.Nev", label: "Category", type: "text" },
],
},
grades: {
url: "/admin/api/grades",
template: () => ({
Uid: "",
RogzitesDatuma: nowIso(),
KeszitesDatuma: nowIso(),
LattamozasDatuma: "",
Tantargy: subjectTemplate(),
Tema: "",
Tipus: { Uid: "1", Nev: "Írásbeli", Leiras: "" },
Mod: null,
ErtekFajta: { Uid: "1", Nev: "Osztályzat", Leiras: "" },
ErtekeloTanarNeve: "",
Jelleg: "Ertekeles",
SzamErtek: 5,
SzovegesErtek: "Jeles",
SulySzazalekErteke: 100,
SzovegesErtekelesRovidNev: "",
OsztalyCsoport: { Uid: "" },
SortIndex: 0,
}),
columns: [
{ path: "Tantargy.Nev", label: "Subject", type: "text" },
{ path: "ErtekeloTanarNeve", label: "Teacher", type: "text" },
{ path: "Tipus.Nev", label: "Type", type: "text" },
{ path: "ErtekFajta.Nev", label: "Value type", type: "text" },
{ path: "SzamErtek", label: "Value (number)", type: "number" },
{ path: "SzovegesErtek", label: "Value (text)", type: "text" },
{ path: "Tema", label: "Topic", type: "text" },
{ path: "RogzitesDatuma", label: "Date", type: "text" },
],
},
homework: {
url: "/admin/api/homework",
template: () => ({
Uid: "",
Tantargy: subjectTemplate(),
TantargyNeve: "",
RogzitoTanarNeve: "",
Szoveg: "",
FeladasDatuma: nowIso(),
HataridoDatuma: nowIso(),
RogzitesIdopontja: nowIso(),
IsTanarRogzitette: true,
IsMegoldva: false,
IsBeadhato: false,
OsztalyCsoport: { Uid: "" },
IsCsatolasEngedelyezes: false,
}),
columns: [
{ paths: ["Tantargy.Nev", "TantargyNeve"], label: "Subject", type: "text" },
{ path: "RogzitoTanarNeve", label: "Teacher", type: "text" },
{ path: "Szoveg", label: "Text", type: "text" },
{ path: "FeladasDatuma", label: "Assigned", type: "text" },
{ path: "HataridoDatuma", label: "Due", type: "text" },
{ path: "IsMegoldva", label: "Done", type: "bool" },
{ path: "IsBeadhato", label: "Submittable", type: "bool" },
],
},
tests: {
url: "/admin/api/tests",
template: () => ({
Uid: "",
Datum: nowIso(),
BejelentesDatuma: nowIso(),
RogzitoTanarNeve: "",
OrarendiOraOraszama: 1,
Tantargy: subjectTemplate(),
TantargyNeve: "",
Temaja: "",
Modja: { Uid: "1", Nev: "Írásbeli", Leiras: "" },
OsztalyCsoport: { Uid: "" },
}),
columns: [
{ paths: ["Tantargy.Nev", "TantargyNeve"], label: "Subject", type: "text" },
{ path: "RogzitoTanarNeve", label: "Teacher", type: "text" },
{ path: "Temaja", label: "Topic", type: "text" },
{ path: "Modja.Nev", label: "Method", type: "text" },
{ path: "Datum", label: "Date", type: "text" },
{ path: "BejelentesDatuma", label: "Announced", type: "text" },
],
},
omissions: {
url: "/admin/api/omissions",
template: () => ({
Uid: "",
Tantargy: subjectTemplate(),
Ora: { KezdoDatum: nowIso(), VegDatum: nowIso(), Oraszam: 1 },
Datum: nowIso(),
RogzitoTanarNeve: "",
Tipus: { Uid: "1", Nev: "Hiányzás", Leiras: "" },
Mod: nameUidDescTemplate(),
KeszitesDatuma: nowIso(),
IgazolasAllapota: "Igazolt",
IgazolasTipusa: nameUidDescTemplate(),
OsztalyCsoport: { Uid: "" },
}),
columns: [
{ path: "Tantargy.Nev", label: "Subject", type: "text" },
{ path: "RogzitoTanarNeve", label: "Teacher", type: "text" },
{ path: "Tipus.Nev", label: "Type", type: "text" },
{ path: "IgazolasAllapota", label: "State (Igazolt/Igazolatlan/Igazolando)", type: "text" },
{ path: "Datum", label: "Date", type: "text" },
{ path: "Ora.KezdoDatum", label: "Lesson start", type: "text" },
{ path: "Ora.VegDatum", label: "Lesson end", type: "text" },
],
},
lessons: {
url: "/admin/api/lessons",
template: () => ({
Uid: "",
Datum: nowIso(),
KezdetIdopont: nowIso(),
VegIdopont: nowIso(),
Nev: "",
Oraszam: 1,
OraEvesSorszama: 0,
OsztalyCsoport: { Uid: "", Nev: "" },
TanarNeve: "",
Tantargy: subjectTemplate(),
Tema: "",
TeremNeve: "",
Tipus: { Uid: "1", Nev: "Tanóra", Leiras: "" },
TanuloJelenlet: nameUidDescTemplate(),
Allapot: { Uid: "1", Nev: "Megtartott", Leiras: "" },
HaziFeladatUid: "",
IsTanuloHaziFeladatEnabled: true,
IsHaziFeladatMegoldva: false,
Csatolmanyok: [],
IsDigitalisOra: false,
DigitalisTamogatoEszkozTipusList: [],
Letrehozas: nowIso(),
UtolsoModositas: nowIso(),
}),
columns: [
{ paths: ["Nev", "Tantargy.Nev"], label: "Subject / name", type: "text" },
{ path: "Datum", label: "Date", type: "text" },
{ path: "KezdetIdopont", label: "Start", type: "text" },
{ path: "VegIdopont", label: "End", type: "text" },
{ path: "Oraszam", label: "Lesson #", type: "number" },
{ path: "TanarNeve", label: "Teacher", type: "text" },
{ path: "TeremNeve", label: "Room", type: "text" },
{ path: "Tipus.Nev", label: "Type", type: "text" },
{ path: "Allapot.Nev", label: "State", type: "text" },
],
},
notices: {
url: "/admin/api/notices",
template: () => ({
Uid: "",
RogzitoNeve: "",
ErvenyessegKezdete: nowIso(),
ErvenyessegVege: nowIso(),
Cim: "",
Tartalom: "",
TartalomText: "",
}),
columns: [
{ path: "Cim", label: "Title", type: "text" },
{ path: "RogzitoNeve", label: "Author", type: "text" },
{ paths: ["Tartalom", "TartalomText"], label: "Content", type: "text" },
{ path: "ErvenyessegKezdete", label: "Valid from", type: "text" },
{ path: "ErvenyessegVege", label: "Valid to", type: "text" },
],
},
infoBoard: {
url: "/admin/api/infoBoard",
template: () => ({
Uid: "",
Cim: "",
Datum: nowIso(),
KeszitoTanarNeve: "",
KeszitesDatuma: nowIso(),
Tartalom: "",
TartalomFormazott: "",
Tipus: { Uid: "1", Nev: "Dicséret", Leiras: "" },
}),
columns: [
{ path: "Cim", label: "Title", type: "text" },
{ path: "KeszitoTanarNeve", label: "Teacher", type: "text" },
{ paths: ["Tartalom", "TartalomFormazott"], label: "Content", type: "text" },
{ path: "Tipus.Nev", label: "Type", type: "text" },
{ path: "Datum", label: "Date", type: "text" },
],
},
dktSubjects: {
url: "/admin/api/dktSubjects",
template: () => ({
tantargyId: 0,
tantargyNev: "",
alkalmazottNev: "",
csoportId: 0,
osztalyCsoportNev: "",
tipusId: 0,
nyelvId: "",
}),
columns: [
{ path: "tantargyNev", label: "Subject", type: "text" },
{ path: "alkalmazottNev", label: "Teacher", type: "text" },
{ path: "osztalyCsoportNev", label: "Group", type: "text" },
{ path: "tipusId", label: "Type ID", type: "number" },
],
},
averages: {
url: "/admin/api/averages",
template: () => ({
Uid: "",
Tantargy: subjectTemplate(),
TanuloAtlag: 0,
OsztalyCsoportAtlag: 0,
}),
columns: [
{ path: "Tantargy.Nev", label: "Subject", type: "text" },
{ path: "TanuloAtlag", label: "Student average", type: "number" },
{ path: "OsztalyCsoportAtlag", label: "Class average", type: "number" },
],
},
guardians: {
template: () => ({
Uid: "",
Nev: "",
EmailCim: "",
IsTorvenyesKepviselo: true,
Telefonszam: "",
}),
columns: [
{ path: "Nev", label: "Name", type: "text" },
{ path: "EmailCim", label: "Email", type: "text" },
{ path: "Telefonszam", label: "Phone", type: "text" },
{ path: "IsTorvenyesKepviselo", label: "Legal guardian", type: "bool" },
],
},
};
function renderStudentPanel(container) {
container.innerHTML = "<h2>Student profile</h2>";
const formHost = document.createElement("div");
container.appendChild(formHost);
const status = document.createElement("span");
status.className = "status";
let data = {};
const fields = [
{ path: "Nev", label: "Name", type: "text" },
{ path: "EmailCim", label: "Email", type: "text" },
{ path: "Telefonszam", label: "Phone", type: "text" },
{ path: "SzuletesiEv", label: "Birth year", type: "number" },
{ path: "SzuletesiHonap", label: "Birth month", type: "number" },
{ path: "SzuletesiNap", label: "Birth day", type: "number" },
{ path: "Cimek", label: "Addresses (one per line)", type: "lines" },
{ path: "TanevUid", label: "School year UID", type: "text" },
{ path: "IntezmenyAzonosito", label: "Institute code", type: "text" },
{ path: "IntezmenyNev", label: "Institute name", type: "text" },
{ path: "Intezmeny.RovidNev", label: "Institute short name", type: "text" },
];
const grid = document.createElement("div");
grid.className = "form-grid";
function drawForm() {
grid.innerHTML = "";
fields.forEach((field) => {
const label = document.createElement("label");
label.textContent = field.label;
grid.appendChild(label);
grid.appendChild(cellInput(data, field, () => {}));
});
}
const toolbar = document.createElement("div");
toolbar.className = "toolbar";
const saveBtn = document.createElement("button");
saveBtn.textContent = "Save student profile";
toolbar.append(saveBtn, status);
const guardianHost = document.createElement("div");
guardianHost.innerHTML = "<h3>Guardians</h3>";
const guardianTableHost = document.createElement("div");
guardianHost.appendChild(guardianTableHost);
container.appendChild(toolbar);
container.appendChild(grid);
container.appendChild(guardianHost);
let guardianRows = [];
function drawGuardians() {
guardianTableHost.innerHTML = "";
const table = document.createElement("table");
const thead = document.createElement("tr");
entities.guardians.columns.forEach((c) => {
const th = document.createElement("th");
th.textContent = c.label;
thead.appendChild(th);
});
thead.appendChild(document.createElement("th"));
table.appendChild(thead);
guardianRows.forEach((row, idx) => {
const tr = document.createElement("tr");
entities.guardians.columns.forEach((field) => {
const td = document.createElement("td");
td.appendChild(cellInput(row, field, () => {}));
tr.appendChild(td);
});
const actionTd = document.createElement("td");
const delBtn = document.createElement("button");
delBtn.className = "danger";
delBtn.textContent = "Delete";
delBtn.onclick = () => {
guardianRows.splice(idx, 1);
drawGuardians();
};
actionTd.appendChild(delBtn);
tr.appendChild(actionTd);
table.appendChild(tr);
});
guardianTableHost.appendChild(table);
const addBtn = document.createElement("button");
addBtn.className = "secondary";
addBtn.textContent = "Add guardian";
addBtn.onclick = () => {
guardianRows.push(entities.guardians.template());
drawGuardians();
};
guardianTableHost.appendChild(addBtn);
}
saveBtn.onclick = async () => {
data.Gondviselok = guardianRows;
try {
await putJSON("/admin/api/student", data);
flash(status, "saved");
} catch (e) {
flash(status, "error: " + e.message);
}
};
(async () => {
data = await getJSON("/admin/api/student");
guardianRows = data.Gondviselok || [];
drawForm();
drawGuardians();
})();
}
function renderServerPanel(container) {
container.innerHTML = "<h2>Server settings</h2><p>Long-press the firka logo on the app's login screen to enable mock mode and point it at this server's address, then log in with the username/password configured below.</p>";
const grid = document.createElement("div");
grid.className = "form-grid";
container.appendChild(grid);
const status = document.createElement("span");
status.className = "status";
let data = {};
const fields = [
{ path: "instituteCode", label: "Institute code", type: "text" },
{ path: "username", label: "Username", type: "text" },
{ path: "password", label: "Password", type: "text" },
{ path: "accessTokenTtlSeconds", label: "Access token TTL (seconds)", type: "number" },
];
function draw() {
grid.innerHTML = "";
fields.forEach((field) => {
const label = document.createElement("label");
label.textContent = field.label;
grid.appendChild(label);
grid.appendChild(cellInput(data, field, () => {}));
});
}
const toolbar = document.createElement("div");
toolbar.className = "toolbar";
const saveBtn = document.createElement("button");
saveBtn.textContent = "Save";
saveBtn.onclick = async () => {
try {
await putJSON("/admin/api/config", data);
flash(status, "saved");
} catch (e) {
flash(status, "error: " + e.message);
}
};
const resetBtn = document.createElement("button");
resetBtn.className = "danger";
resetBtn.textContent = "Reset all data to seed defaults";
resetBtn.onclick = async () => {
if (!confirm("This replaces every entity with the built-in seed data. Continue?")) return;
await fetch("/admin/api/reset", { method: "POST" });
location.reload();
};
toolbar.append(saveBtn, resetBtn, status);
container.appendChild(toolbar);
container.appendChild(grid);
(async () => {
data = await getJSON("/admin/api/config");
draw();
})();
}
const tabs = [
{ key: "server", label: "Server", render: renderServerPanel },
{ key: "student", label: "Student", render: renderStudentPanel },
{ key: "classGroups", label: "Class groups", render: (c) => renderTable(c, entities.classGroups) },
{ key: "grades", label: "Grades", render: (c) => renderTable(c, entities.grades) },
{ key: "homework", label: "Homework", render: (c) => renderTable(c, entities.homework) },
{ key: "tests", label: "Tests", render: (c) => renderTable(c, entities.tests) },
{ key: "omissions", label: "Omissions", render: (c) => renderTable(c, entities.omissions) },
{ key: "lessons", label: "Timetable", render: (c) => renderTable(c, entities.lessons) },
{ key: "notices", label: "Notice board", render: (c) => renderTable(c, entities.notices) },
{ key: "infoBoard", label: "Info board", render: (c) => renderTable(c, entities.infoBoard) },
{ key: "dktSubjects", label: "DKT subjects", render: (c) => renderTable(c, entities.dktSubjects) },
{ key: "averages", label: "Class averages", render: (c) => renderTable(c, entities.averages) },
];
function init() {
const nav = document.getElementById("nav");
const main = document.getElementById("main");
tabs.forEach((tab) => {
const btn = document.createElement("button");
btn.textContent = tab.label;
btn.onclick = () => selectTab(tab.key);
btn.dataset.key = tab.key;
nav.appendChild(btn);
});
function selectTab(key) {
nav.querySelectorAll("button").forEach((b) => b.classList.toggle("active", b.dataset.key === key));
const tab = tabs.find((t) => t.key === key);
main.innerHTML = "";
const panel = document.createElement("div");
panel.className = "panel active";
main.appendChild(panel);
tab.render(panel);
}
selectTab(tabs[0].key);
}
init();

View File

@@ -1,17 +0,0 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>firka mock server</title>
<link rel="stylesheet" href="style.css">
</head>
<body>
<header>
<h1>firka mock kréta server</h1>
</header>
<nav id="nav"></nav>
<main id="main"></main>
<script src="app.js"></script>
</body>
</html>

View File

@@ -1,168 +0,0 @@
:root {
color-scheme: light dark;
--bg: #16181c;
--panel: #1f2228;
--border: #33373f;
--text: #e7e9ec;
--muted: #9aa0aa;
--accent: #6fae4a;
}
* {
box-sizing: border-box;
}
body {
margin: 0;
font-family: -apple-system, "Segoe UI", Roboto, sans-serif;
background: var(--bg);
color: var(--text);
}
header {
padding: 16px 20px;
border-bottom: 1px solid var(--border);
display: flex;
align-items: baseline;
gap: 12px;
}
header h1 {
font-size: 18px;
margin: 0;
}
header span {
color: var(--muted);
font-size: 13px;
}
nav {
display: flex;
flex-wrap: wrap;
gap: 4px;
padding: 10px 16px;
border-bottom: 1px solid var(--border);
}
nav button {
background: none;
border: 1px solid var(--border);
color: var(--text);
padding: 6px 12px;
border-radius: 6px;
cursor: pointer;
font-size: 13px;
}
nav button.active {
background: var(--accent);
border-color: var(--accent);
color: #10140c;
}
main {
padding: 20px;
max-width: 1200px;
margin: 0 auto;
}
.panel {
display: none;
}
.panel.active {
display: block;
}
table {
width: 100%;
border-collapse: collapse;
margin-bottom: 12px;
font-size: 13px;
}
th, td {
border: 1px solid var(--border);
padding: 4px 6px;
text-align: left;
}
th {
background: var(--panel);
color: var(--muted);
font-weight: 500;
}
input[type=text], input[type=number], textarea, select {
width: 100%;
background: var(--panel);
border: 1px solid var(--border);
color: var(--text);
border-radius: 4px;
padding: 4px 6px;
font-size: 13px;
}
.row-actions {
white-space: nowrap;
}
.toolbar {
display: flex;
gap: 8px;
margin-bottom: 12px;
align-items: center;
}
button {
background: var(--accent);
color: #10140c;
border: none;
padding: 7px 14px;
border-radius: 6px;
cursor: pointer;
font-size: 13px;
}
button.secondary {
background: var(--panel);
color: var(--text);
border: 1px solid var(--border);
}
button.danger {
background: #b3543f;
color: #fff;
}
.form-grid {
display: grid;
grid-template-columns: 220px 1fr;
gap: 8px 12px;
max-width: 640px;
margin-bottom: 20px;
}
.form-grid label {
align-self: center;
color: var(--muted);
font-size: 13px;
}
.status {
color: var(--muted);
font-size: 12px;
margin-left: 8px;
}
h2 {
font-size: 16px;
margin-top: 0;
}
h3 {
font-size: 14px;
color: var(--muted);
margin-top: 28px;
}

View File

@@ -1,444 +0,0 @@
package main
import (
"encoding/json"
"os"
"sync"
)
type UidRef struct {
Uid string `json:"Uid"`
}
type NameUid struct {
Uid string `json:"Uid"`
Nev string `json:"Nev"`
}
type NameUidDesc struct {
Uid string `json:"Uid"`
Nev string `json:"Nev"`
Leiras string `json:"Leiras"`
}
type Subject struct {
Uid string `json:"Uid"`
Nev string `json:"Nev"`
Kategoria NameUidDesc `json:"Kategoria"`
SortIndex int `json:"SortIndex"`
}
type Guardian struct {
Uid string `json:"Uid"`
Nev string `json:"Nev"`
EmailCim string `json:"EmailCim,omitempty"`
IsTorvenyesKepviselo bool `json:"IsTorvenyesKepviselo"`
Telefonszam string `json:"Telefonszam,omitempty"`
}
type BankAccount struct {
BankszamlaSzam string `json:"BankszamlaSzam,omitempty"`
IsReadOnly bool `json:"IsReadOnly"`
BankszamlaTulajdonosNeve string `json:"BankszamlaTulajdonosNeve,omitempty"`
BankszamlaTulajdonosTipusId int `json:"BankszamlaTulajdonosTipusId"`
}
type SystemModule struct {
IsAktiv bool `json:"IsAktiv"`
Tipus string `json:"Tipus"`
Url string `json:"Url,omitempty"`
}
type CustomizationSettings struct {
ErtekelesekMegjelenitesenekKesleltetesenekMerteke int `json:"ErtekelesekMegjelenitesenekKesleltetesenekMerteke"`
IsOsztalyAtlagMegjeleniteseEllenorzoben bool `json:"IsOsztalyAtlagMegjeleniteseEllenorzoben"`
IsTanorakTemajaMegtekinthetoEllenorzoben bool `json:"IsTanorakTemajaMegtekinthetoEllenorzoben"`
KovetkezoTelepitesDatuma string `json:"KovetkezoTelepitesDatuma"`
}
type Institution struct {
Uid string `json:"Uid"`
RovidNev string `json:"RovidNev"`
TestreszabasBeallitasok CustomizationSettings `json:"TestreszabasBeallitasok"`
Rendszermodulok []SystemModule `json:"Rendszermodulok"`
}
type Student struct {
Uid string `json:"Uid"`
Nev string `json:"Nev"`
Cimek []string `json:"Cimek"`
Bankszamla BankAccount `json:"Bankszamla"`
SzuletesiEv int `json:"SzuletesiEv"`
SzuletesiHonap int `json:"SzuletesiHonap"`
SzuletesiNap int `json:"SzuletesiNap"`
EmailCim string `json:"EmailCim,omitempty"`
Telefonszam string `json:"Telefonszam,omitempty"`
TanevUid string `json:"TanevUid"`
Gondviselok []Guardian `json:"Gondviselok"`
IntezmenyAzonosito string `json:"IntezmenyAzonosito"`
IntezmenyNev string `json:"IntezmenyNev"`
Intezmeny Institution `json:"Intezmeny"`
}
type ClassGroup struct {
Uid string `json:"Uid"`
Nev string `json:"Nev"`
OsztalyFonok UidRef `json:"OsztalyFonok"`
OsztalyFonokHelyettes UidRef `json:"OsztalyFonokHelyettes"`
OktatasNevelesiKategoria NameUidDesc `json:"OktatasNevelesiKategoria"`
OktatasNevelesiKategoriaSortIndex int `json:"OktatasNevelesiKategoriaSortIndex"`
OktatasNevelesiFeladat NameUidDesc `json:"OktatasNevelesiFeladat"`
IsAktiv bool `json:"IsAktiv"`
Tipus string `json:"Tipus"`
}
type Grade struct {
Uid string `json:"Uid"`
RogzitesDatuma string `json:"RogzitesDatuma"`
KeszitesDatuma string `json:"KeszitesDatuma"`
LattamozasDatuma string `json:"LattamozasDatuma,omitempty"`
Tantargy Subject `json:"Tantargy"`
Tema string `json:"Tema,omitempty"`
Tipus NameUidDesc `json:"Tipus"`
Mod *NameUidDesc `json:"Mod,omitempty"`
ErtekFajta NameUidDesc `json:"ErtekFajta"`
ErtekeloTanarNeve string `json:"ErtekeloTanarNeve"`
Jelleg string `json:"Jelleg,omitempty"`
SzamErtek int `json:"SzamErtek,omitempty"`
SzovegesErtek string `json:"SzovegesErtek"`
SulySzazalekErteke int `json:"SulySzazalekErteke,omitempty"`
SzovegesErtekelesRovidNev string `json:"SzovegesErtekelesRovidNev,omitempty"`
OsztalyCsoport UidRef `json:"OsztalyCsoport"`
SortIndex int `json:"SortIndex"`
}
type Homework struct {
Uid string `json:"Uid"`
Tantargy Subject `json:"Tantargy"`
TantargyNeve string `json:"TantargyNeve"`
RogzitoTanarNeve string `json:"RogzitoTanarNeve"`
Szoveg string `json:"Szoveg"`
FeladasDatuma string `json:"FeladasDatuma"`
HataridoDatuma string `json:"HataridoDatuma"`
RogzitesIdopontja string `json:"RogzitesIdopontja"`
IsTanarRogzitette bool `json:"IsTanarRogzitette"`
IsMegoldva bool `json:"IsMegoldva"`
IsBeadhato bool `json:"IsBeadhato"`
OsztalyCsoport UidRef `json:"OsztalyCsoport"`
IsCsatolasEngedelyezes bool `json:"IsCsatolasEngedelyezes"`
}
type Test struct {
Uid string `json:"Uid"`
Datum string `json:"Datum"`
BejelentesDatuma string `json:"BejelentesDatuma"`
RogzitoTanarNeve string `json:"RogzitoTanarNeve"`
OrarendiOraOraszama int `json:"OrarendiOraOraszama"`
Tantargy Subject `json:"Tantargy"`
TantargyNeve string `json:"TantargyNeve"`
Temaja string `json:"Temaja,omitempty"`
Modja NameUidDesc `json:"Modja"`
OsztalyCsoport UidRef `json:"OsztalyCsoport"`
}
type OmittedLesson struct {
KezdoDatum string `json:"KezdoDatum"`
VegDatum string `json:"VegDatum"`
Oraszam int `json:"Oraszam,omitempty"`
}
type Omission struct {
Uid string `json:"Uid"`
Tantargy Subject `json:"Tantargy"`
Ora *OmittedLesson `json:"Ora,omitempty"`
Datum string `json:"Datum"`
RogzitoTanarNeve string `json:"RogzitoTanarNeve"`
Tipus NameUidDesc `json:"Tipus"`
Mod NameUidDesc `json:"Mod"`
KesesPercben int `json:"KesesPercben,omitempty"`
KeszitesDatuma string `json:"KeszitesDatuma"`
IgazolasAllapota string `json:"IgazolasAllapota"`
IgazolasTipusa NameUidDesc `json:"IgazolasTipusa"`
OsztalyCsoport UidRef `json:"OsztalyCsoport"`
}
type Lesson struct {
Uid string `json:"Uid"`
Datum string `json:"Datum"`
KezdetIdopont string `json:"KezdetIdopont"`
VegIdopont string `json:"VegIdopont"`
Nev string `json:"Nev"`
Oraszam int `json:"Oraszam,omitempty"`
OraEvesSorszama int `json:"OraEvesSorszama,omitempty"`
OsztalyCsoport NameUid `json:"OsztalyCsoport"`
TanarNeve string `json:"TanarNeve,omitempty"`
Tantargy Subject `json:"Tantargy"`
Tema string `json:"Tema,omitempty"`
TeremNeve string `json:"TeremNeve,omitempty"`
Tipus NameUidDesc `json:"Tipus"`
TanuloJelenlet NameUidDesc `json:"TanuloJelenlet"`
Allapot NameUidDesc `json:"Allapot"`
HelyettesTanarNeve string `json:"HelyettesTanarNeve,omitempty"`
HaziFeladatUid string `json:"HaziFeladatUid,omitempty"`
FeladatGroupUid string `json:"FeladatGroupUid,omitempty"`
NyelviFeladatGroupUid string `json:"NyelviFeladatGroupUid,omitempty"`
BejelentettSzamonkeresUid string `json:"BejelentettSzamonkeresUid,omitempty"`
IsTanuloHaziFeladatEnabled bool `json:"IsTanuloHaziFeladatEnabled"`
IsHaziFeladatMegoldva bool `json:"IsHaziFeladatMegoldva"`
Csatolmanyok []NameUid `json:"Csatolmanyok"`
IsDigitalisOra bool `json:"IsDigitalisOra"`
DigitalisEszkozTipus string `json:"DigitalisEszkozTipus,omitempty"`
DigitalisPlatformTipus string `json:"DigitalisPlatformTipus,omitempty"`
DigitalisTamogatoEszkozTipusList []string `json:"DigitalisTamogatoEszkozTipusList"`
Letrehozas string `json:"Letrehozas"`
UtolsoModositas string `json:"UtolsoModositas"`
}
type NoticeBoardItem struct {
Uid string `json:"Uid"`
RogzitoNeve string `json:"RogzitoNeve"`
ErvenyessegKezdete string `json:"ErvenyessegKezdete"`
ErvenyessegVege string `json:"ErvenyessegVege"`
Cim string `json:"Cim"`
Tartalom string `json:"Tartalom"`
TartalomText string `json:"TartalomText"`
}
type InfoBoardItem struct {
Uid string `json:"Uid"`
Cim string `json:"Cim"`
Datum string `json:"Datum"`
KeszitoTanarNeve string `json:"KeszitoTanarNeve"`
KeszitesDatuma string `json:"KeszitesDatuma"`
Tartalom string `json:"Tartalom"`
TartalomFormazott string `json:"TartalomFormazott"`
Tipus NameUidDesc `json:"Tipus"`
}
type DktSubject struct {
TantargyId int `json:"tantargyId"`
TantargyNev string `json:"tantargyNev"`
AlkalmazottNev string `json:"alkalmazottNev"`
CsoportId int `json:"csoportId,omitempty"`
OsztalyCsoportNev string `json:"osztalyCsoportNev"`
TipusId int `json:"tipusId"`
NyelvId string `json:"nyelvId,omitempty"`
}
type ClassGroupSubjectAverage struct {
Uid string `json:"Uid"`
Tantargy Subject `json:"Tantargy"`
TanuloAtlag float64 `json:"TanuloAtlag,omitempty"`
OsztalyCsoportAtlag float64 `json:"OsztalyCsoportAtlag,omitempty"`
}
type ServerConfig struct {
InstituteCode string `json:"instituteCode"`
Username string `json:"username"`
Password string `json:"password"`
AccessTokenTTLSeconds int `json:"accessTokenTtlSeconds"`
}
type storeData struct {
Config ServerConfig `json:"config"`
Student Student `json:"student"`
ClassGroups []ClassGroup `json:"classGroups"`
Grades []Grade `json:"grades"`
Homework []Homework `json:"homework"`
Tests []Test `json:"tests"`
Omissions []Omission `json:"omissions"`
Lessons []Lesson `json:"lessons"`
Notices []NoticeBoardItem `json:"notices"`
InfoBoard []InfoBoardItem `json:"infoBoard"`
DktSubjects []DktSubject `json:"dktSubjects"`
Averages []ClassGroupSubjectAverage `json:"averages"`
}
type Store struct {
mu sync.RWMutex
path string
data storeData
}
func NewStore(path string) *Store {
s := &Store{path: path}
if raw, err := os.ReadFile(path); err == nil {
if json.Unmarshal(raw, &s.data) == nil {
return s
}
}
s.data = seedData()
s.save()
return s
}
func (s *Store) save() {
raw, err := json.MarshalIndent(s.data, "", " ")
if err != nil {
return
}
os.WriteFile(s.path, raw, 0o644)
}
func (s *Store) Reset() {
s.mu.Lock()
defer s.mu.Unlock()
s.data = seedData()
s.save()
}
func (s *Store) GetConfig() ServerConfig {
s.mu.RLock()
defer s.mu.RUnlock()
return s.data.Config
}
func (s *Store) SetConfig(v ServerConfig) {
s.mu.Lock()
defer s.mu.Unlock()
s.data.Config = v
s.save()
}
func (s *Store) GetStudent() Student {
s.mu.RLock()
defer s.mu.RUnlock()
return s.data.Student
}
func (s *Store) SetStudent(v Student) {
s.mu.Lock()
defer s.mu.Unlock()
s.data.Student = v
s.save()
}
func (s *Store) GetClassGroups() []ClassGroup {
s.mu.RLock()
defer s.mu.RUnlock()
return s.data.ClassGroups
}
func (s *Store) SetClassGroups(v []ClassGroup) {
s.mu.Lock()
defer s.mu.Unlock()
s.data.ClassGroups = v
s.save()
}
func (s *Store) GetGrades() []Grade {
s.mu.RLock()
defer s.mu.RUnlock()
return s.data.Grades
}
func (s *Store) SetGrades(v []Grade) {
s.mu.Lock()
defer s.mu.Unlock()
s.data.Grades = v
s.save()
}
func (s *Store) GetHomework() []Homework {
s.mu.RLock()
defer s.mu.RUnlock()
return s.data.Homework
}
func (s *Store) SetHomework(v []Homework) {
s.mu.Lock()
defer s.mu.Unlock()
s.data.Homework = v
s.save()
}
func (s *Store) GetTests() []Test {
s.mu.RLock()
defer s.mu.RUnlock()
return s.data.Tests
}
func (s *Store) SetTests(v []Test) {
s.mu.Lock()
defer s.mu.Unlock()
s.data.Tests = v
s.save()
}
func (s *Store) GetOmissions() []Omission {
s.mu.RLock()
defer s.mu.RUnlock()
return s.data.Omissions
}
func (s *Store) SetOmissions(v []Omission) {
s.mu.Lock()
defer s.mu.Unlock()
s.data.Omissions = v
s.save()
}
func (s *Store) GetLessons() []Lesson {
s.mu.RLock()
defer s.mu.RUnlock()
return s.data.Lessons
}
func (s *Store) SetLessons(v []Lesson) {
s.mu.Lock()
defer s.mu.Unlock()
s.data.Lessons = v
s.save()
}
func (s *Store) GetNotices() []NoticeBoardItem {
s.mu.RLock()
defer s.mu.RUnlock()
return s.data.Notices
}
func (s *Store) SetNotices(v []NoticeBoardItem) {
s.mu.Lock()
defer s.mu.Unlock()
s.data.Notices = v
s.save()
}
func (s *Store) GetInfoBoard() []InfoBoardItem {
s.mu.RLock()
defer s.mu.RUnlock()
return s.data.InfoBoard
}
func (s *Store) SetInfoBoard(v []InfoBoardItem) {
s.mu.Lock()
defer s.mu.Unlock()
s.data.InfoBoard = v
s.save()
}
func (s *Store) GetDktSubjects() []DktSubject {
s.mu.RLock()
defer s.mu.RUnlock()
return s.data.DktSubjects
}
func (s *Store) SetDktSubjects(v []DktSubject) {
s.mu.Lock()
defer s.mu.Unlock()
s.data.DktSubjects = v
s.save()
}
func (s *Store) GetAverages() []ClassGroupSubjectAverage {
s.mu.RLock()
defer s.mu.RUnlock()
return s.data.Averages
}
func (s *Store) SetAverages(v []ClassGroupSubjectAverage) {
s.mu.Lock()
defer s.mu.Unlock()
s.data.Averages = v
s.save()
}