Update API from meeting

This commit is contained in:
schooltechx 2023-04-07 22:59:53 +07:00
parent 40f7e878c9
commit b2083ebae2
13 changed files with 125 additions and 67 deletions

View file

@ -1,8 +0,0 @@
export interface CalendarEvent {
id:string;
title:string;
start:Date|string;
end?:Date|string;
url?:string;
backgroundColor?:string;
}

View file

@ -1,11 +0,0 @@
export interface Exam {
id:string;
title:string;
start?:Date|string;
end?:Date|string;
exam_date?:Date|string;
announcement_date?:Date|string;
category_id?:string
category?:string
img?:string;
}

View file

@ -0,0 +1,28 @@
export interface Exam {
id:string;
title:string;
date:string;
start?:Date|string;
end?:Date|string;
exam_date?:Date|string;
announcement_date?:Date|string;
category_id?:string
category?:string
img?:string;
}
export interface CalendarEvent {
id:string;
title:string;
start:Date|string;
end?:Date|string;
url?:string;
backgroundColor?:string;
}
export interface CMSInfo{
logo_url:string;
organization:string;
supervised:Date|string;
address:Date|string;
divisions:{title:string,url:string}[];
institutes:{title:string,url:string}[];
}

View file

@ -0,0 +1,14 @@
import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types'
export const load: PageServerLoad = async ({fetch}) => {
const res = await fetch("/api/info")
if(res.ok){
const info = await res.json()
return info
}else{
throw error(500, 'ไม่สามารถอ่านข้อมูลตั้งต้นของเวปได้');
}
}

View file

@ -1,7 +1,15 @@
<script> <script lang="ts">
import '../app.postcss'; import '../app.postcss';
import Header from '$lib/components/Header.svelte'; import Header from '$lib/components/Header.svelte';
import Footer from '$lib/components/Footer.svelte'; import Footer from '$lib/components/Footer.svelte';
import 'dayjs/locale/th'
import dayjs from 'dayjs'
dayjs.locale('th')
import buddhistEra from 'dayjs/plugin/buddhistEra'
dayjs.extend(buddhistEra)
import type { LayoutData } from './$types';
export let data: LayoutData;
console.log(data)
</script> </script>
<Header /> <Header />

View file

@ -1,7 +1,8 @@
//import content from "$lib/data/content/home.html?raw" //import content from "$lib/data/content/home.html?raw"
//import { getQualifyExams,getCompetitiveExams } from '$lib/data/info'; //import { getQualifyExams,getCompetitiveExams } from '$lib/data/info';
import type { PageServerLoad } from './$types'; import type { PageServerLoad } from './$types';
import type {Exam} from '$lib/components/Exam' import type {Exam} from '$lib/components/Exam'
import dayjs from 'dayjs'
export const load: PageServerLoad = async ({fetch}) => { export const load: PageServerLoad = async ({fetch}) => {
let qualify_exams: Exam[] = [] let qualify_exams: Exam[] = []
let competitive_exams: Exam[] = [] let competitive_exams: Exam[] = []
@ -13,10 +14,16 @@ export const load: PageServerLoad = async ({fetch}) => {
res = await fetch("/api/qualifying") res = await fetch("/api/qualifying")
if(res.ok){ if(res.ok){
qualify_exams = await res.json() qualify_exams = await res.json()
qualify_exams.forEach((e)=>{
e.start? dayjs(e.start).format("DD MMM BBBB"):""
})
} }
res = await fetch("/api/competitive") res = await fetch("/api/competitive")
if(res.ok){ if(res.ok){
competitive_exams = await res.json() competitive_exams = await res.json()
competitive_exams.forEach((e)=>{
e.start? dayjs(e.start).format("DD MMM BBBB"):""
})
} }
return { content , qualify_exams,competitive_exams }; return { content , qualify_exams,competitive_exams };
}; };

View file

@ -1,8 +1,9 @@
import ver from "$lib/ver.json" import ver from "$lib/ver.json"
import {json} from '@sveltejs/kit' import {json} from '@sveltejs/kit'
import info from "$lib/data/info.json"
import type { RequestHandler } from './$types' import type { RequestHandler } from './$types'
export const GET: RequestHandler = async () => { export const GET: RequestHandler = async () => {
const version = ver.version const version = ver.version
const builddate = ver.builddate const builddate = ver.builddate
return json({version,builddate}) return json({...info,version,builddate})
} }

View file

@ -1,7 +1,6 @@
import type { PageServerLoad } from './$types' import type { PageServerLoad } from './$types'
import type {CalendarEvent} from '$lib/components/CalendarEvent' import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
import type {Exam} from '$lib/components/Exam' import dayjs from 'dayjs'
export const load: PageServerLoad = async ({fetch}) => { export const load: PageServerLoad = async ({fetch}) => {
let content = "" let content = ""
let exams:Exam[] = [] let exams:Exam[] = []
@ -16,8 +15,19 @@ export const load: PageServerLoad = async ({fetch}) => {
} }
const events:CalendarEvent[]=[] const events:CalendarEvent[]=[]
exams.forEach(({id,title,start})=>{ exams.forEach((e)=>{
const backgroundColor ="#9999FF" if(!e.start){
e.date=""
return
}
e.date= dayjs(e.start).format("DD MMM BBBB")
const {id,title,start,category_id} = e
let backgroundColor ="#9999FF"
if(category_id)
backgroundColor ="#99FFEE"
const url = "/competitive/"+id const url = "/competitive/"+id
events.push({id,title,start,url,backgroundColor}) events.push({id,title,start,url,backgroundColor})
}) })

View file

@ -1,18 +1,16 @@
//import type {Exam} from '$lib/data/CMSDataType'
import type { PageServerLoad } from './$types'
import { error } from '@sveltejs/kit' import { error } from '@sveltejs/kit'
import exams from "$lib/data/competitive-exam.json" import type { PageServerLoad } from './$types'
export const load: PageServerLoad = async ({params}) => { export const load: PageServerLoad = async ({params,fetch}) => {
const id = params.id+"" const id = params.id+""
//const exams = await getCompetitiveExams() const res = await fetch("/api/compettive/"+id)
const post = exams.find((q)=>{ if(res.status==404){
return q.id===id throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
}) }
if(!res.ok){
if(post) throw error(500,{message:`พบข้อผิดพลาดเกี่ยวกับข้อมูลสอบคัดเลือก ${id}`})
return post }
else const post = await res.json()
throw error(404,{message:"ค้นหาโพสเกี่ยวกับการคัดเลือกไม่พบ"}) return post
} }

View file

@ -1,6 +1,8 @@
import type {CalendarEvent} from '$lib/data/CMSDataType'
import type {Exam} from '$lib/data/CMSDataType'
import dayjs from 'dayjs'
import type { PageServerLoad } from './$types' import type { PageServerLoad } from './$types'
import type {CalendarEvent} from '$lib/components/CalendarEvent'
import type {Exam} from '$lib/components/Exam'
export const load: PageServerLoad = async ({fetch}) => { export const load: PageServerLoad = async ({fetch}) => {
let content = "" let content = ""
let exams:Exam[] = [] let exams:Exam[] = []
@ -13,23 +15,36 @@ export const load: PageServerLoad = async ({fetch}) => {
exams = await res.json() exams = await res.json()
} }
const events:CalendarEvent[]=[] const events:CalendarEvent[]=[]
exams.forEach(({id,title,start,institute_id})=>{ exams.forEach((e)=>{
if(!e.start){
e.date=""
return
}
e.date= dayjs(e.start).format("DD MMM BBBB")
const {id,title,start,end,category_id} = e
let backgroundColor ="" let backgroundColor =""
switch (institute_id) { switch (category_id) {
case 1: case "1":
backgroundColor="rgba(251,64,75,.2)" backgroundColor="rgba(251,64,75,.2)"
break; break;
case 2: case "2":
backgroundColor="#23ccef" backgroundColor="#23ccef"
break; break;
case 3: case "3":
backgroundColor="rgba(68,125,247,.2)" backgroundColor="rgba(68,125,247,.2)"
break; break;
default: default:
break; break;
} }
const url = "/qualifying/"+id const url = "/qualifying/"+id
events.push({id,title,start,url,backgroundColor}) events.push({id,title,start,end,url,backgroundColor})
if(e.exam_date){
events.push({id,"title":"สอบ","start":e.exam_date,url,backgroundColor})
}
if(e.announcement_date){
events.push({id,"title":"ผลสอบสอบ","start":e.announcement_date,url,backgroundColor})
}
}) })
return {exams,events,content} return {exams,events,content}
} }

View file

@ -53,7 +53,7 @@
<tr> <tr>
<th class="px-6 align-middle border border-solid py-3 text-xs uppercase border-l-0 border-r-0 whitespace-nowrap font-semibold text-left bg-blueGray-50 text-blueGray-500 border-blueGray-100">วันที่</th> <th class="px-6 align-middle border border-solid py-3 text-xs uppercase border-l-0 border-r-0 whitespace-nowrap font-semibold text-left bg-blueGray-50 text-blueGray-500 border-blueGray-100">วันที่</th>
<th class="px-6 align-middle border border-solid py-3 text-xs uppercase border-l-0 border-r-0 whitespace-nowrap font-semibold text-left bg-blueGray-50 text-blueGray-500 border-blueGray-100">การสอบ</th> <th class="px-6 align-middle border border-solid py-3 text-xs uppercase border-l-0 border-r-0 whitespace-nowrap font-semibold text-left bg-blueGray-50 text-blueGray-500 border-blueGray-100">การสอบ</th>
<th class="px-6 align-middle border border-solid py-3 text-xs uppercase border-l-0 border-r-0 whitespace-nowrap font-semibold text-left bg-blueGray-50 text-blueGray-500 border-blueGray-100">หน่วยงาน</th> <th class="px-6 align-middle border border-solid py-3 text-xs uppercase border-l-0 border-r-0 whitespace-nowrap font-semibold text-left bg-blueGray-50 text-blueGray-500 border-blueGray-100">ประเภท</th>
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
@ -61,7 +61,7 @@
<tr> <tr>
<th class="border-t-0 px-6 align-middle border-l-0 border-r-0 text-xs whitespace-nowrap p-4 text-left"><a href={"/qualifying/"+exam.id}>{exam.date}</a></th> <th class="border-t-0 px-6 align-middle border-l-0 border-r-0 text-xs whitespace-nowrap p-4 text-left"><a href={"/qualifying/"+exam.id}>{exam.date}</a></th>
<td class="border-t-0 px-6 align-middle border-l-0 border-r-0 text-xs whitespace-nowrap p-4 text-left"><a href={"/qualifying/"+exam.id}>{exam.title}</a></td> <td class="border-t-0 px-6 align-middle border-l-0 border-r-0 text-xs whitespace-nowrap p-4 text-left"><a href={"/qualifying/"+exam.id}>{exam.title}</a></td>
<td class="border-t-0 px-6 align-middle border-l-0 border-r-0 text-xs whitespace-nowrap p-4 text-left">{exam.institute}</td> <td class="border-t-0 px-6 align-middle border-l-0 border-r-0 text-xs whitespace-nowrap p-4 text-left">{exam.category}</td>
{/each} {/each}
</tbody> </tbody>
</table> </table>

View file

@ -1,17 +1,16 @@
//import type {Exam} from '$lib/data/CMSDataType'
import type { PageServerLoad } from './$types'
import { error } from '@sveltejs/kit' import { error } from '@sveltejs/kit'
import exams from "$lib/data/qualify-exam.json" import type { PageServerLoad } from './$types'
export const load: PageServerLoad = async ({params}) => { export const load: PageServerLoad = async ({params,fetch}) => {
const id = params.id+"" const id = params.id+""
const post = exams.find((q)=>{ const res = await fetch("/api/qualifying/"+id)
return q.id===id if(res.status==404){
}) throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
}
if(post) if(!res.ok){
return post throw error(500,{message:`พบข้อผิดพลาดเกี่ยวกับข้อมูลสอบคัดเลือก ${id}`})
else }
throw error(404,{message:"ค้นหาโพสเกี่ยวกับการคัดเลือกไม่พบ"}) const post = await res.json()
return post
} }

View file

@ -1,9 +1,6 @@
<script lang="ts"> <script lang="ts">
import ver from "$lib/ver.json"
import type { PageData } from './$types' import type { PageData } from './$types'
export let data: PageData; export let data: PageData;
</script> </script>
<section> <section>
<div class="p-one parallax-inner"> <div class="p-one parallax-inner">