Connect Real API of qualify exam and cms info

This commit is contained in:
schooltechx 2023-04-09 14:39:23 +07:00
parent acfe81c58a
commit f536b6e2e9
15 changed files with 34 additions and 31 deletions

View file

@ -18,8 +18,8 @@ env:
DEPLOY_HOST: frappet.com DEPLOY_HOST: frappet.com
COMPOSE_PATH: /home/frappet/docker/bma-ehr-qualifying-cms COMPOSE_PATH: /home/frappet/docker/bma-ehr-qualifying-cms
jobs: jobs:
# act workflow_dispatch -W .github/workflows/release.yaml --input IMAGE_VER=v0.2.4-dev -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd # act workflow_dispatch --reuse -W .github/workflows/release.yaml --input IMAGE_VER=v0.2.4-dev -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd
# act --workflows .github/workflows/release.yaml --job release --input IMAGE_VER=v0.2.4-dev -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd # act --reuse --workflows .github/workflows/release.yaml --job release --input IMAGE_VER=v0.2.4-dev -s DOCKER_USER=sorawit -s DOCKER_PASS=P@ssword -s SSH_PASSWORD=P@ssw0rd
release: release:
runs-on: ubuntu-latest runs-on: ubuntu-latest
@ -59,7 +59,9 @@ jobs:
uses: docker/build-push-action@v3 uses: docker/build-push-action@v3
with: with:
context: cms context: cms
# platforms: linux/amd64,linux/arm64 cache-from: type=gha
cache-to: type=gha,mode=max
platforms: linux/amd64
push: true push: true
tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest tags: ${{env.REGISTRY}}/${{env.IMAGE_NAME}}:${{ steps.gen_ver.outputs.image_ver }},${{env.REGISTRY}}/${{env.IMAGE_NAME}}:latest
- name: Remote Deployment - name: Remote Deployment

View file

@ -9,7 +9,7 @@
- [GitHub Actions](https://github.com/features/actions) ทำ CI/CD ในระบบทดสอบ - [GitHub Actions](https://github.com/features/actions) ทำ CI/CD ในระบบทดสอบ
- [nektos/act](https://github.com/nektos/act) ใช้ GitHub Actions บนเครื่องของเราเอง - [nektos/act](https://github.com/nektos/act) ใช้ GitHub Actions บนเครื่องของเราเอง
- [Argo CD](https://argo-cd.readthedocs.io/en/stable/) deploy ขึ้นระบบ Production (K8s) - [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 ไทยรองรับ พ.ศ. - [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 ให้เหมาะสม ถ้าไม่ 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 ## Browser Testing

View file

@ -33,7 +33,7 @@
<div class="w-full lg:w-6/12 px-4"> <div class="w-full lg:w-6/12 px-4">
<div class=" mb-4"> <div class=" mb-4">
<div class="w-12 rounded-full"> <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>
</div> </div>
<h5 class="text-2xl font-semibold">{title}</h5> <h5 class="text-2xl font-semibold">{title}</h5>

View file

@ -2,7 +2,6 @@
export let logo_url:string = "/images/logo.png" export let logo_url:string = "/images/logo.png"
export let title:string = "ใส่ชื่อองค์กรที่นี้" export let title:string = "ใส่ชื่อองค์กรที่นี้"
export let supervised:string = "ใส่สังกัดที่นี้" export let supervised:string = "ใส่สังกัดที่นี้"
</script> </script>
<div class="navbar bg-white w-full top-0 z-50 fixed flex-wrap items-center justify-between px-4 "> <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="content-center grid">
<div class="avatar"> <div class="avatar">
<div class="w-10 rounded-full"> <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> </div>
</div> </div>

View file

@ -30,4 +30,6 @@ export interface CMSInfo{
divisions:{title:string,url:string}[]; divisions:{title:string,url:string}[];
institutes:{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"

View file

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

View file

@ -10,7 +10,6 @@
import type { LayoutData } from './$types'; import type { LayoutData } from './$types';
export let data: LayoutData; export let data: LayoutData;
let {logo_url,supervised,divisions,institutes,address,title,subtitle} = data let {logo_url,supervised,divisions,institutes,address,title,subtitle} = data
</script> </script>
<Header {logo_url} {title} {supervised} /> <Header {logo_url} {title} {supervised} />

View file

@ -1,18 +1,19 @@
import {apibase} from '$lib/data/CMSDataType' import {cmsBase,qualifyingBase,competitiveBase} from '$lib/data/CMSDataType'
import { error } from '@sveltejs/kit'; import { error } from '@sveltejs/kit';
import type { PageServerLoad } from './$types'; import type { PageServerLoad } from './$types';
import type {Exam} from '$lib/data/CMSDataType' import type {Exam} from '$lib/data/CMSDataType'
import dayjs from 'dayjs' import dayjs from 'dayjs'
export const load: PageServerLoad = async ({fetch}) => { export const load: PageServerLoad = async ({fetch}) => {
let res = await fetch(apibase+"/info") let res = await fetch("/api/info")
if(!res.ok) if(!res.ok)
throw error(500, 'ไม่สามารถอ่านข้อมูลตั้งต้นของหน้าหลักได้'); throw error(500, 'ไม่สามารถอ่านข้อมูลตั้งต้นของหน้าหลักได้');
const {title,subtitle} = await res.json() const {title,subtitle} = await res.json()
res = await fetch(apibase+"/content?page=home") res = await fetch(cmsBase+"/content/home")
if(!res.ok) if(!res.ok)
throw error(500, 'ไม่สามารถอ่านเนื้อหาหน้าหลักได้'); throw error(500, 'ไม่สามารถอ่านเนื้อหาหน้าหลักได้');
const {content,image} = await res.json() const {content,image} = await res.json()
console.log("xxx",image)
//Inner function reduce code and able to throw here //Inner function reduce code and able to throw here
async function loadExam(api_path:string,err_msg:string){ async function loadExam(api_path:string,err_msg:string){
const res = await fetch(api_path) const res = await fetch(api_path)
@ -21,16 +22,16 @@ export const load: PageServerLoad = async ({fetch}) => {
const exams:Exam[] = await res.json() const exams:Exam[] = await res.json()
exams.forEach((e)=>{ exams.forEach((e)=>{
e.date = e.start? dayjs(e.start).format("DD MMM BBBB"):"" 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 //This page layout require 3 item, patch with empty
for(let i=exams.length;i<3;i++){ 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 qualify_exams = loadExam(qualifyingBase+"/qualifying?limit=3",'ไม่สามารถอ่านรายการสอบคัดเลือกได้')
const competitive_exams = loadExam(apibase+"/competitive",'ไม่สามารถอ่านรายการสอบแข่งขันได้') const competitive_exams = loadExam(competitiveBase+"/competitive?limit=3",'ไม่สามารถอ่านรายการสอบแข่งขันได้')
return {title,subtitle,content,image, qualify_exams,competitive_exams }; return {title,subtitle,content,image, qualify_exams,competitive_exams };
}; };

View file

@ -36,7 +36,7 @@
</div> </div>
<img <img
class="absolute top-0 b-auto right-0 sm:w-5/12 sm:mt-32 pr-10 hidden md:flex" 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="..." alt="..."
/> />
</section> </section>

View file

@ -1,8 +1,8 @@
import {apibase} from '$lib/data/CMSDataType' import {cmsBase} from '$lib/data/CMSDataType'
import type { PageServerLoad } from './$types'; import type { PageServerLoad } from './$types';
import { error } from '@sveltejs/kit'; import { error } from '@sveltejs/kit';
export const load = (async ({fetch}) => { export const load = (async ({fetch}) => {
const res = await fetch(apibase+"/content?page=about") const res = await fetch(cmsBase+"/content/about")
if(!res.ok) if(!res.ok)
throw error(500, 'ไม่สามารถอ่านเนื้อหาหน้าเกี่ยวกับได้'); throw error(500, 'ไม่สามารถอ่านเนื้อหาหน้าเกี่ยวกับได้');
const {content} = await res.json() const {content} = await res.json()

View file

@ -1,11 +1,11 @@
import {apibase} from '$lib/data/CMSDataType' import {competitiveBase} from '$lib/data/CMSDataType'
import { error } from '@sveltejs/kit'; import { error } from '@sveltejs/kit';
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType' import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import type { PageServerLoad } from './$types' import type { PageServerLoad } from './$types'
export const load: PageServerLoad = async ({fetch}) => { export const load: PageServerLoad = async ({fetch}) => {
let exams:Exam[] = [] let exams:Exam[] = []
const res = await fetch(apibase+"/competitive") const res = await fetch(competitiveBase+"/competitive")
if(!res.ok) if(!res.ok)
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้'); throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
exams = await res.json() exams = await res.json()

View file

@ -1,10 +1,10 @@
import {apibase} from '$lib/data/CMSDataType' import {competitiveBase} from '$lib/data/CMSDataType'
import { error } from '@sveltejs/kit' import { error } from '@sveltejs/kit'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import type { PageServerLoad } from './$types' import type { PageServerLoad } from './$types'
export const load: PageServerLoad = async ({params,fetch}) => { export const load: PageServerLoad = async ({params,fetch}) => {
const id = params.id+"" const id = params.id+""
const res = await fetch(apibase+"/competitive/"+id) const res = await fetch(competitiveBase+"/competitive/"+id)
if(res.status==404){ if(res.status==404){
throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`}) throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
} }

View file

@ -1,11 +1,11 @@
import {apibase} from '$lib/data/CMSDataType' import {qualifyingBase} from '$lib/data/CMSDataType'
import { error } from '@sveltejs/kit'; import { error } from '@sveltejs/kit';
import type {CalendarEvent,Exam} from '$lib/data/CMSDataType' import type {CalendarEvent,Exam} from '$lib/data/CMSDataType'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import type { PageServerLoad } from './$types' import type { PageServerLoad } from './$types'
export const load: PageServerLoad = async ({fetch}) => { export const load: PageServerLoad = async ({fetch}) => {
let exams:Exam[] = [] let exams:Exam[] = []
const res = await fetch(apibase+"/qualifying") const res = await fetch(qualifyingBase+"/qualifying")
if(!res.ok) if(!res.ok)
throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้'); throw error(res.status, 'ไม่สามารถอ่านข้อมูลการสอบได้');
exams = await res.json() exams = await res.json()

View file

@ -1,10 +1,10 @@
import {apibase} from '$lib/data/CMSDataType' import {qualifyingBase} from '$lib/data/CMSDataType'
import { error } from '@sveltejs/kit' import { error } from '@sveltejs/kit'
import dayjs from 'dayjs' import dayjs from 'dayjs'
import type { PageServerLoad } from './$types' import type { PageServerLoad } from './$types'
export const load: PageServerLoad = async ({params,fetch}) => { export const load: PageServerLoad = async ({params,fetch}) => {
const id = params.id+"" const id = params.id+""
const res = await fetch(apibase+"/qualifying/"+id) const res = await fetch(qualifyingBase+"/qualifying/"+id)
if(res.status==404){ if(res.status==404){
throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`}) throw error(404,{message:`ค้นหาข้อมูลสอบคัดเลือก ${id}ไม่พบ`})
} }

Binary file not shown.

After

Width:  |  Height:  |  Size: 9.1 KiB