Connect Real API of qualify exam and cms info
This commit is contained in:
parent
acfe81c58a
commit
f536b6e2e9
15 changed files with 34 additions and 31 deletions
|
|
@ -9,7 +9,7 @@
|
|||
- [GitHub Actions](https://github.com/features/actions) ทำ CI/CD ในระบบทดสอบ
|
||||
- [nektos/act](https://github.com/nektos/act) ใช้ GitHub Actions บนเครื่องของเราเอง
|
||||
- [Argo CD](https://argo-cd.readthedocs.io/en/stable/) deploy ขึ้นระบบ Production (K8s)
|
||||
- [FullCalendar](https://github.com/schooltechx/youtube/blob/main/svelte/component/FullCalendar.md) รองรับพ.ศ. ใช้แค่ฟีเจอร์[ฟรีก็น่าจะพอ](https://fullcalendar.io/license#:~:text=or%20FullCalendar%20Premium.-,FullCalendar%20Standard,all%20copyright%20headers%20are%20preserved.)
|
||||
- [FullCalendar](https://github.com/schooltechx/youtube/blob/main/svelte/component/Calendar/FullCalendar.md) รองรับพ.ศ. ใช้แค่ฟีเจอร์[ฟรีก็น่าจะพอ](https://fullcalendar.io/license#:~:text=or%20FullCalendar%20Premium.-,FullCalendar%20Standard,all%20copyright%20headers%20are%20preserved.)
|
||||
- [Day.js](https://day.js.org/) ในฟอร์แม็ตวันในรูปแบบ local ไทยรองรับ พ.ศ.
|
||||
|
||||
## วีดีโอแสดงการทำงานทั้งหมด
|
||||
|
|
@ -70,7 +70,7 @@ npx vite preview --port=4000 --host=0.0.0.0
|
|||
|
||||
ถ้าไม่ build เอง ตอนนี้มี demo อยู่ที่ [https://bma-qualifying.frappet.synology.me/](https://bma-qualifying.frappet.synology.me/) ให้เปลี่ยน base url ให้เหมาะสม
|
||||
|
||||
Data Type ที่ใช้ดูในไฟล์ [CMSDataType.ts](./src/lib/data/CMSDataType.ts)
|
||||
การกำหนด path ของ API และ Data Type ที่ใช้ดูในไฟล์ [CMSDataType.ts](./src/lib/data/CMSDataType.ts)
|
||||
|
||||
|
||||
## Browser Testing
|
||||
|
|
|
|||
|
|
@ -33,7 +33,7 @@
|
|||
<div class="w-full lg:w-6/12 px-4">
|
||||
<div class=" mb-4">
|
||||
<div class="w-12 rounded-full">
|
||||
<img src="{logo_url}" alt="logo">
|
||||
<img src={logo_url?logo_url:'/images/logo.png'} alt="logo">
|
||||
</div>
|
||||
</div>
|
||||
<h5 class="text-2xl font-semibold">{title}</h5>
|
||||
|
|
|
|||
|
|
@ -2,7 +2,6 @@
|
|||
export let logo_url:string = "/images/logo.png"
|
||||
export let title:string = "ใส่ชื่อองค์กรที่นี้"
|
||||
export let supervised:string = "ใส่สังกัดที่นี้"
|
||||
|
||||
</script>
|
||||
|
||||
<div class="navbar bg-white w-full top-0 z-50 fixed flex-wrap items-center justify-between px-4 ">
|
||||
|
|
@ -14,7 +13,7 @@
|
|||
<div class="content-center grid">
|
||||
<div class="avatar">
|
||||
<div class="w-10 rounded-full">
|
||||
<img src="{logo_url}" alt="logo">
|
||||
<img src={logo_url?logo_url:'/images/logo.png'} alt="logo">
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -30,4 +30,6 @@ export interface CMSInfo{
|
|||
divisions:{title:string,url:string}[];
|
||||
institutes:{title:string,url:string}[];
|
||||
}
|
||||
export const apibase="/api"
|
||||
export const cmsBase="https://bma-ehr-exam.frappet.synology.me/api/v1/cms"
|
||||
export const competitiveBase="/api"
|
||||
export const qualifyingBase="https://bma-ehr-exam.frappet.synology.me/api/v1/cms"
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import {apibase} from '$lib/data/CMSDataType'
|
||||
import {cmsBase} from '$lib/data/CMSDataType'
|
||||
import { error } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from './$types'
|
||||
export const load: PageServerLoad = async ({fetch}) => {
|
||||
const res = await fetch(apibase+"/info")
|
||||
const res = await fetch(cmsBase+"/home")
|
||||
if(!res.ok)
|
||||
throw error(500, 'ไม่สามารถอ่านข้อมูลตั้งต้นของเวปได้');
|
||||
|
||||
|
|
|
|||
|
|
@ -10,7 +10,6 @@
|
|||
import type { LayoutData } from './$types';
|
||||
export let data: LayoutData;
|
||||
let {logo_url,supervised,divisions,institutes,address,title,subtitle} = data
|
||||
|
||||
</script>
|
||||
|
||||
<Header {logo_url} {title} {supervised} />
|
||||
|
|
|
|||
|
|
@ -1,18 +1,19 @@
|
|||
import {apibase} from '$lib/data/CMSDataType'
|
||||
import {cmsBase,qualifyingBase,competitiveBase} from '$lib/data/CMSDataType'
|
||||
import { error } from '@sveltejs/kit';
|
||||
import type { PageServerLoad } from './$types';
|
||||
import type {Exam} from '$lib/data/CMSDataType'
|
||||
import dayjs from 'dayjs'
|
||||
export const load: PageServerLoad = async ({fetch}) => {
|
||||
let res = await fetch(apibase+"/info")
|
||||
let res = await fetch("/api/info")
|
||||
if(!res.ok)
|
||||
throw error(500, 'ไม่สามารถอ่านข้อมูลตั้งต้นของหน้าหลักได้');
|
||||
const {title,subtitle} = await res.json()
|
||||
|
||||
res = await fetch(apibase+"/content?page=home")
|
||||
res = await fetch(cmsBase+"/content/home")
|
||||
if(!res.ok)
|
||||
throw error(500, 'ไม่สามารถอ่านเนื้อหาหน้าหลักได้');
|
||||
const {content,image} = await res.json()
|
||||
console.log("xxx",image)
|
||||
//Inner function reduce code and able to throw here
|
||||
async function loadExam(api_path:string,err_msg:string){
|
||||
const res = await fetch(api_path)
|
||||
|
|
@ -21,16 +22,16 @@ export const load: PageServerLoad = async ({fetch}) => {
|
|||
const exams:Exam[] = await res.json()
|
||||
exams.forEach((e)=>{
|
||||
e.date = e.start? dayjs(e.start).format("DD MMM BBBB"):""
|
||||
e.image = e.image?e.image:"/images/exam_place_holder.png"
|
||||
})
|
||||
//This page layout require 3 item, patch with empty
|
||||
for(let i=exams.length;i<3;i++){
|
||||
exams.push({id:"0",title:"",date:"",image:""})
|
||||
exams.push({id:"0",title:"",date:"",image:"/images/exam_place_holder.png"})
|
||||
}
|
||||
return exams
|
||||
|
||||
return exams
|
||||
}
|
||||
const qualify_exams = loadExam(apibase+"/qualifying",'ไม่สามารถอ่านรายการสอบคัดเลือกได้')
|
||||
const competitive_exams = loadExam(apibase+"/competitive",'ไม่สามารถอ่านรายการสอบแข่งขันได้')
|
||||
const qualify_exams = loadExam(qualifyingBase+"/qualifying?limit=3",'ไม่สามารถอ่านรายการสอบคัดเลือกได้')
|
||||
const competitive_exams = loadExam(competitiveBase+"/competitive?limit=3",'ไม่สามารถอ่านรายการสอบแข่งขันได้')
|
||||
|
||||
return {title,subtitle,content,image, qualify_exams,competitive_exams };
|
||||
};
|
||||
|
|
|
|||
|
|
@ -36,7 +36,7 @@
|
|||
</div>
|
||||
<img
|
||||
class="absolute top-0 b-auto right-0 sm:w-5/12 sm:mt-32 pr-10 hidden md:flex"
|
||||
src="{image}"
|
||||
src={image?image:'/images/pattern.png'}
|
||||
alt="..."
|
||||
/>
|
||||
</section>
|
||||
|
|
|
|||
|
|
@ -1,8 +1,8 @@
|
|||
import {apibase} from '$lib/data/CMSDataType'
|
||||
import {cmsBase} from '$lib/data/CMSDataType'
|
||||
import type { PageServerLoad } from './$types';
|
||||
import { error } from '@sveltejs/kit';
|
||||
export const load = (async ({fetch}) => {
|
||||
const res = await fetch(apibase+"/content?page=about")
|
||||
const res = await fetch(cmsBase+"/content/about")
|
||||
if(!res.ok)
|
||||
throw error(500, 'ไม่สามารถอ่านเนื้อหาหน้าเกี่ยวกับได้');
|
||||
const {content} = await res.json()
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import {apibase} from '$lib/data/CMSDataType'
|
||||
import {competitiveBase} from '$lib/data/CMSDataType'
|
||||
import { error } from '@sveltejs/kit';
|
||||
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
|
||||
import dayjs from 'dayjs'
|
||||
import type { PageServerLoad } from './$types'
|
||||
export const load: PageServerLoad = async ({fetch}) => {
|
||||
let exams:Exam[] = []
|
||||
const res = await fetch(apibase+"/competitive")
|
||||
const res = await fetch(competitiveBase+"/competitive")
|
||||
if(!res.ok)
|
||||
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
|
||||
exams = await res.json()
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import {apibase} from '$lib/data/CMSDataType'
|
||||
import {competitiveBase} from '$lib/data/CMSDataType'
|
||||
import { error } from '@sveltejs/kit'
|
||||
import dayjs from 'dayjs'
|
||||
import type { PageServerLoad } from './$types'
|
||||
export const load: PageServerLoad = async ({params,fetch}) => {
|
||||
const id = params.id+""
|
||||
const res = await fetch(apibase+"/competitive/"+id)
|
||||
const res = await fetch(competitiveBase+"/competitive/"+id)
|
||||
if(res.status==404){
|
||||
throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
|
||||
}
|
||||
|
|
|
|||
|
|
@ -1,11 +1,11 @@
|
|||
import {apibase} from '$lib/data/CMSDataType'
|
||||
import {qualifyingBase} from '$lib/data/CMSDataType'
|
||||
import { error } from '@sveltejs/kit';
|
||||
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
|
||||
import dayjs from 'dayjs'
|
||||
import type { PageServerLoad } from './$types'
|
||||
export const load: PageServerLoad = async ({fetch}) => {
|
||||
let exams:Exam[] = []
|
||||
const res = await fetch(apibase+"/qualifying")
|
||||
const res = await fetch(qualifyingBase+"/qualifying")
|
||||
if(!res.ok)
|
||||
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
|
||||
exams = await res.json()
|
||||
|
|
|
|||
|
|
@ -1,10 +1,10 @@
|
|||
import {apibase} from '$lib/data/CMSDataType'
|
||||
import {qualifyingBase} from '$lib/data/CMSDataType'
|
||||
import { error } from '@sveltejs/kit'
|
||||
import dayjs from 'dayjs'
|
||||
import type { PageServerLoad } from './$types'
|
||||
export const load: PageServerLoad = async ({params,fetch}) => {
|
||||
const id = params.id+""
|
||||
const res = await fetch(apibase+"/qualifying/"+id)
|
||||
const res = await fetch(qualifyingBase+"/qualifying/"+id)
|
||||
if(res.status==404){
|
||||
throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
|
||||
}
|
||||
|
|
|
|||
BIN
cms/static/images/exam_place_holder.png
Normal file
BIN
cms/static/images/exam_place_holder.png
Normal file
Binary file not shown.
|
After Width: | Height: | Size: 9.1 KiB |
Loading…
Add table
Add a link
Reference in a new issue