Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/529talp'
Browse files Browse the repository at this point in the history
  • Loading branch information
talp-525 committed Apr 2, 2022
2 parents f48b708 + c25648e commit ba21120
Show file tree
Hide file tree
Showing 8 changed files with 445 additions and 29 deletions.
106 changes: 106 additions & 0 deletions altrpnjs/app/Controllers/Http/admin/FontSettingsController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import FontSetting from 'App/Models/FontSetting';

export default class FontSettingSettingsController {

public async store({request, response}: HttpContextContract) {

let fontSetting = new FontSetting()
fontSetting.fill(request.all())

try {
await fontSetting.save()
} catch (e) {
return response.json({
'success':
false,
'message':
'Font Setting don\'t saved',
'throw message': e.message,
'trace': e.stack.split('\n'),
},
)
}
return response.json({
'success': true,
'data': fontSetting
},
)
}

public async show({params, response}: HttpContextContract) {
let fontSetting = await FontSetting.find(params.id)
if (!fontSetting) {
return response.json({
'success': false,
'message': 'Font Setting not found'
},
)
}
return response.json({
'success': true,
'data': fontSetting
},)
}

public async update({params, request, response}: HttpContextContract) {
let fontSetting = await FontSetting.find(params.id)
if (!fontSetting) {
return response.json({
'success': false,
'message': 'Font Setting not found'
},
)
}
fontSetting.merge(request.all())
try {
await fontSetting.save()
} catch (e) {
response.status(500)
return response.json({
'success': false,
'message': 'Font Setting could not be saved',
'throw message': e.message,
'trace': e.stack.split('\n'),
},
)
}
return response.json({
'success': true,
'data': fontSetting.serialize()
})
}

public async index({params, response}: HttpContextContract) {

let fontSettings = FontSetting.query().where('font_guid', params.guid)

return response.json({
'success': true,
'data': fontSettings
})
}

public async destroy({params, response}: HttpContextContract) {
let fontSetting = await FontSetting.find(params.id)
if (!fontSetting) {
return response.json({
'success': false,
'message': 'FontSetting not found'
},)
}
try {
await fontSetting.delete()
} catch (e) {
return response.json({
'success': false,
'throw message': e.message,
'trace': e.stack.split('\n'),
'message': 'Font Setting could not be deleted'
},
)
}
return response.json({'success': true,})
}

}
146 changes: 146 additions & 0 deletions altrpnjs/app/Controllers/Http/admin/FontsController.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
import { HttpContextContract } from '@ioc:Adonis/Core/HttpContext'
import Font from 'App/Models/Font';
import validGuid from '../../../../helpers/validGuid';
import guid from "../../../../helpers/guid";

export default class FontsController {

public async store({request, response}: HttpContextContract) {

let font = new Font()
font.fill(request.all())
font.guid = guid()

try {
await font.save()
} catch (e) {
return response.json({
'success':
false,
'message':
'Font don\'t saved',
'throw message': e.message,
'trace': e.stack.split('\n'),
},
)
}
return response.json({
'success': true,
'data': font
},
)
}

public async show({params, response}: HttpContextContract) {
let font
if (validGuid(params.id)) {
font = await font.query().where('guid', params.id).first()
} else {
font = await Font.find(params.id)
}
await font.load('fontSettings')
if (!font) {
return response.json({
'success': false,
'message': 'Font not found'
},
)
}
return response.json({
'success': true,
'data': font
},)
}

public async update({params, request, response}: HttpContextContract) {
let font = await Font.find(params.id)
if (!font) {
return response.json({
'success': false,
'message': 'Font not found'
},
)
}
font.merge(request.all())
try {
await font.save()
} catch (e) {
console.trace(e);
response.status(500)
return response.json({
'success': false,
'message': 'Font could not be saved',
'throw message': e.message,
'trace': e.stack.split('\n'),
},
)
}
return response.json({
'success': true,
'data': font.serialize()
})
}

public async index({request, response}: HttpContextContract) {

let search = request.qs().s || ''
let categories = request.qs() || ''
let orderColumn = request.qs().order_by || 'font_family'
let orderType: 'asc' | 'desc' = request.qs()?.order ? request.qs().order.toLowerCase() : 'asc'

let fonts = Font.query().preload('categories')
if (fonts && _.isString(categories)) {
categories = categories.split(',')
fonts.leftJoin('altrp_category_objects',
'altrp_category_objects.object_guid',
'=',
'altrp_fonts.guid')
// @ts-ignore
fonts.whereIn('altrp_category_objects.category_guid', categories)
}

if (search) {
fonts.where(function (query) {
query.where('altrp_fonts.font_family', 'like', '%' + search + '%')
.orWhere('altrp_fonts.id', 'like', '%' + search + '%')
})
}
fonts.orderBy(orderColumn, orderType)
const result = await fonts.select('altrp_fonts.*')

return response.json({
'success':
true,
'data':
result,
})
}

public async destroy({params, response}: HttpContextContract) {
let font
if (validGuid(params.id)) {
font = await Font.query().where('guid', params.id).first()
} else {
font = await Font.find(params.id)
}
if (!font) {
return response.json({
'success': false,
'message': 'Font not found'
},)
}
try {
await font.delete()
} catch (e) {
return response.json({
'success': false,
'throw message': e.message,
'trace': e.stack.split('\n'),
'message': 'Font could not be deleted'
},
)
}
return response.json({'success': true,},)
}

}
Loading

0 comments on commit ba21120

Please sign in to comment.