Skip to content

Commit

Permalink
[feature] 모델 변경 및 연동
Browse files Browse the repository at this point in the history
- vm 모델 추가
- stat 모델 추가
추가 된 모델들은 리스트의 개별 객체를 할당받아
메인 모델 배열에 추가 하기 위한 용도의 개벌 모델임.
(GET) 기준
- 대시보드 연동 완료
- CloudPC 연동 진행 중
  • Loading branch information
jeidjin committed May 31, 2022
1 parent abd87da commit a59ae10
Show file tree
Hide file tree
Showing 9 changed files with 153 additions and 45 deletions.
72 changes: 72 additions & 0 deletions src/mocks/db/resource.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,72 @@
import { factory, primaryKey, nullable, manyOf } from '@mswjs/data'
import { faker } from '@faker-js/faker'
import resourceList from '../json/resourceList.json'
import userResourceImage from '../json/userResourceImage.json'
import userResourceUse from '../json/userResourceUse.json'

export const db_resource = factory({
resources: {
id: primaryKey(faker.datatype.uuid),
data: manyOf('vm')
},
vm: {
id: primaryKey(faker.datatype.uuid),
vm_ip: String,
vm_nm: String,
vm_auth_id: String,
vm_als: String,
vm_state: String,
vcpu_cnt: String,
vmm_capa: String,
vhd_capa: String,
img_id: String,
acct_conn_id: String,
acct_id: String,
usr_vm_ctrl_tm: String,
os_typ_cd_nm: String,
vm_on_ctrl_tm: String,
vm_vlid_stt_dt: String,
vm_vlid_end_dt: String,
tnt_mtd_cd_nm: String,
secu_plcy_id: String
},
images: {
id: primaryKey(faker.datatype.uuid),
img_id: String,
img_nm: String,
img_descp: nullable(String),
sw_nm: String
},
monitor: {
id: primaryKey(faker.datatype.uuid),
data: manyOf('stat')
},
stat: {
id: primaryKey(faker.datatype.uuid),
cpu_usage: Number,
mem_total: Number,
mem_used: Number,
disk_total: Number,
disk_used: Number,
vm_auth_id: String,
reason: nullable(String)
}
})

const vm_list_init = [
db_resource.vm.create({ ...resourceList['data'][0] }),
db_resource.vm.create({ ...resourceList['data'][1] }),
db_resource.vm.create({ ...resourceList['data'][2] })
]

const stat_init = [
db_resource.stat.create({ ...userResourceUse['data'][0] }),
db_resource.stat.create({ ...userResourceUse['data'][1] }),
db_resource.stat.create({ ...userResourceUse['data'][2] })
]

export const resourceInit = () => {
db_resource.resources.create({ data: vm_list_init })
db_resource.images.create(userResourceImage['data'])
db_resource.monitor.create({ data: stat_init })
}
2 changes: 1 addition & 1 deletion src/mocks/db/user.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ export const db_user = factory({
}
})

export const init = () => {
export const userInit = () => {
db_user.static.create(staticPublic['data'])
db_user.auth.create(userAuth['data'])
db_user.account.create(userAccount['data'])
Expand Down
48 changes: 32 additions & 16 deletions src/mocks/handlers/resource.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,52 @@
import { rest } from 'msw'
import resourceListData from '../json/resourceList.json'
import userResourceData from '../json/userResource.json'
import userResourceImage from '../json/userResourceImage.json'
import userResourceUse from '../json/userResourceUse.json'
import { db_resource as db } from '../db/resource'

export const mock_resource = () => {
return rest.get('/v1/resource/vpcs/resources', (_, res, ctx) => {
return res(ctx.json(resourceListData))
return res(ctx.json(db.resources.getAll().pop()))
})
}

export const mock_userResource = () => {
return rest.get('/v1/resource/vpcs/resources/:vm_auth_id', (_, res, ctx) => {
return res(ctx.json(userResourceData))
})
}

export const mock_userResourceImage = () => {
return rest.get('/v1/resource/images/:image_id', (_, res, ctx) => {
return res(ctx.json(userResourceImage))
})
return rest.get(
'/v1/resource/vpcs/resources/:vm_auth_id',
(req, res, ctx) => {
const { vm_auth_id } = req.params
const data = db.vm.findFirst({
where: {
vm_auth_id: {
equals: vm_auth_id
}
}
})
return res(ctx.json(data))
}
)
}

export const mock_userResourceUse = () => {
return rest.get(
'/v1/management/dashboard/user/:vm_auth_id/stat',
(_, res, ctx) => {
return res(ctx.json(userResourceUse))
(req, res, ctx) => {
const { vm_auth_id } = req.params
const data = db.stat.findFirst({
where: {
vm_auth_id: {
equals: vm_auth_id
}
}
})
return res(ctx.json(data))
}
)
}

export const mock_userResourceImage = () => {
return rest.get('/v1/resource/images/:image_id', (_, res, ctx) => {
return res(ctx.json(db.images.getAll().pop()))
})
}

export const mock_changeVmAlais = () => {
return rest.put(
'/v1/resource/vpcs/resources/:vm_auth_id/user',
Expand Down
11 changes: 5 additions & 6 deletions src/mocks/handlers/user.js
Original file line number Diff line number Diff line change
@@ -1,32 +1,31 @@
import { rest } from 'msw'
import vmPeriodHistory from '../json/vmPeriodHistory.json'

import { db_user } from '../db/user'
import { db_user as db } from '../db/user'

export const mock_staticPublic = () => {
return rest.get(
'/v1/nauth/system/portals/ui/BBB/public/:type',
(_, res, ctx) => {
return res(ctx.json(db_user.static.getAll().pop()))
return res(ctx.json(db.static.getAll().pop()))
}
)
}

export const mock_userAuth = () => {
return rest.post('/v1/gw/authentications/', (req, res, ctx) => {
return res(ctx.json(db_user.auth.getAll().pop()))
return res(ctx.json(db.auth.getAll().pop()))
})
}

export const mock_userAccount = () => {
return rest.get('/v1/user/accounts/:acct_id', (req, res, ctx) => {
return res(ctx.json(db_user.account.getAll().pop()))
return res(ctx.json(db.account.getAll().pop()))
})
}

export const mock_userPcPeriodHistory = () => {
return rest.get('/v1/user/work/request', (req, res, ctx) => {
return res(ctx.json(vmPeriodHistory))
return res(ctx.json(db.periodHistory.getAll().pop()))
})
}

Expand Down
12 changes: 4 additions & 8 deletions src/mocks/json/userResourceImage.json
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,10 @@
"img_sts_cd": "T003CC",
"img_sts_cd_nm": "생성 완료",
"init_cre_yn": "Y",
"img_sw_l": [
{
"seq_no": "1",
"sw_nm": "Windows 10 Enter",
"sw_typ_cd": "T001OS",
"sw_typ_cd_nm": "Operating System"
}
],
"seq_no": "1",
"sw_nm": "Windows 10 Enter",
"sw_typ_cd": "T001OS",
"sw_typ_cd_nm": "Operating System",
"reg_id": "787a12f6-d7e5-11ec-9d66-56f465f67b97",
"reg_nm": "SuperAdmin",
"reg_conn_id": "superadmin",
Expand Down
42 changes: 32 additions & 10 deletions src/mocks/json/userResourceUse.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,34 @@
{
"data": {
"time": "2022-05-30 17:33:38",
"cpu_usage": 0.0,
"mem_total": 8191.0,
"mem_used": 1535.0,
"disk_total": 40408.0,
"disk_used": 12894.0,
"vm_auth_id": "DEE-303540",
"reason": null
}
"data": [
{
"time": "2022-05-30 17:33:38",
"cpu_usage": 15.0,
"mem_total": 8191.0,
"mem_used": 1535.0,
"disk_total": 40408.0,
"disk_used": 12894.0,
"vm_auth_id": "DEE-303540",
"reason": null
},
{
"time": "2022-05-30 17:33:38",
"cpu_usage": 35.0,
"mem_total": 8191.0,
"mem_used": 3735.0,
"disk_total": 40408.0,
"disk_used": 22000.0,
"vm_auth_id": "DEE-319869",
"reason": null
},
{
"time": "2022-05-30 17:33:38",
"cpu_usage": 70.0,
"mem_total": 8191.0,
"mem_used": 4002.0,
"disk_total": 40408.0,
"disk_used": 15000.0,
"vm_auth_id": "DEE-332989",
"reason": null
}
]
}
7 changes: 5 additions & 2 deletions src/mocks/server.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
import { setupWorker } from 'msw'
import module from './handlers'
import { init } from './db/user'

import { userInit } from './db/user'
import { resourceInit } from './db/resource'

export function setupBrowserMock() {
init()
userInit()
resourceInit()
setupWorker(...module).start()
}
2 changes: 1 addition & 1 deletion src/views/cloudPcInfo/CloudPcDetail.js
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ const CloudPcDetail = ({ meta }) => {
<Col offset={2}>
<ContainerWrapper {...wrapperProps}>
{cloudPcList.map((item) => (
<Row style={style.divRow} key={item.vm_id}>
<Row style={style.divRow} key={item.id}>
<Col span={8}>
{/* 좌측 CloudPc 정보 */}
<CloudPcPeriod {...userPcPeriodFactory(item)} />
Expand Down
2 changes: 1 addition & 1 deletion src/views/dashboard/Dashboard.js
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ function Dashboard() {
//* 3. VM의 이미지 아이디로 이미지 정보 조회
const resourceImageData = await call_imageInfo(userResourceData.img_id)
//* 4. 이미지내 소프트 웨어 이름을 1번에서 조회했던 VM데이터에 추가한다.
userResourceData.sw_nm = resourceImageData.img_sw_l[0].sw_nm
userResourceData.sw_nm = resourceImageData.sw_nm
//* 5. 사용자 VM 상태 갱신
await fetchUsageResource(userResourceData, key)
} catch (error) {
Expand Down

0 comments on commit a59ae10

Please sign in to comment.