import { Count, CountSchema, Filter, FilterExcludingWhere, repository, Where, } from '@loopback/repository'; import {post, param, get, patch, put, del, requestBody} from '@loopback/rest'; import {Currency} from '../models'; import {CurrencyRepository} from '../repositories'; import {authorize} from 'loopback4-authorization'; import {authenticate, STRATEGY} from 'loopback4-authentication'; import {PermissionKey} from '../permissions'; import { OPERATION_SECURITY_SPEC, STATUS_CODE, getModelSchemaRefSF, } from '@sourceloop/core'; const basePath = '/currencies'; export class CurrencyController { constructor( @repository(CurrencyRepository) public currencyRepository: CurrencyRepository, ) {} @authorize({ permissions: [PermissionKey.CreateCurrency], }) @authenticate(STRATEGY.BEARER, { passReqToCallback: true, }) @post(basePath, { security: OPERATION_SECURITY_SPEC, responses: { [STATUS_CODE.OK]: { description: 'Currency model instance', content: { 'application/json': {schema: getModelSchemaRefSF(Currency)}, }, }, }, }) async create( @requestBody({ content: { 'application/json': { schema: getModelSchemaRefSF(Currency, { title: 'NewCurrency', exclude: ['id'], }), }, }, }) currency: Omit, ): Promise { return this.currencyRepository.create(currency); } @authorize({ permissions: [PermissionKey.ViewCurrency], }) @authenticate(STRATEGY.BEARER, { passReqToCallback: true, }) @get(`${basePath}/count`, { security: OPERATION_SECURITY_SPEC, responses: { [STATUS_CODE.OK]: { description: 'Currency model count', content: {'application/json': {schema: CountSchema}}, }, }, }) async count(@param.where(Currency) where?: Where): Promise { return this.currencyRepository.count(where); } @authorize({ permissions: [PermissionKey.ViewCurrency], }) @authenticate(STRATEGY.BEARER, { passReqToCallback: true, }) @get(basePath, { security: OPERATION_SECURITY_SPEC, responses: { [STATUS_CODE.OK]: { description: 'Array of Currency model instances', content: { 'application/json': { schema: { type: 'array', items: getModelSchemaRefSF(Currency, {includeRelations: true}), }, }, }, }, }, }) async find( @param.filter(Currency) filter?: Filter, ): Promise { return this.currencyRepository.find(filter); } @authorize({ permissions: [PermissionKey.UpdateCurrency], }) @authenticate(STRATEGY.BEARER, { passReqToCallback: true, }) @patch(basePath, { security: OPERATION_SECURITY_SPEC, responses: { [STATUS_CODE.OK]: { description: 'Currency PATCH success count', content: {'application/json': {schema: CountSchema}}, }, }, }) async updateAll( @requestBody({ content: { 'application/json': { schema: getModelSchemaRefSF(Currency, {partial: true}), }, }, }) currency: Currency, @param.where(Currency) where?: Where, ): Promise { return this.currencyRepository.updateAll(currency, where); } @authorize({ permissions: [PermissionKey.ViewCurrency], }) @authenticate(STRATEGY.BEARER, { passReqToCallback: true, }) @get(`${basePath}/{id}`, { security: OPERATION_SECURITY_SPEC, responses: { [STATUS_CODE.OK]: { description: 'Currency model instance', content: { 'application/json': { schema: getModelSchemaRefSF(Currency, {includeRelations: true}), }, }, }, }, }) async findById( @param.path.string('id') id: string, @param.filter(Currency, {exclude: 'where'}) filter?: FilterExcludingWhere, ): Promise { return this.currencyRepository.findById(id, filter); } @authorize({ permissions: [PermissionKey.UpdateCurrency], }) @authenticate(STRATEGY.BEARER, { passReqToCallback: true, }) @patch(`${basePath}/{id}`, { security: OPERATION_SECURITY_SPEC, responses: { [STATUS_CODE.NO_CONTENT]: { description: 'Currency PATCH success', }, }, }) async updateById( @param.path.string('id') id: string, @requestBody({ content: { 'application/json': { schema: getModelSchemaRefSF(Currency, {partial: true}), }, }, }) currency: Currency, ): Promise { await this.currencyRepository.updateById(id, currency); } @authorize({ permissions: [PermissionKey.UpdateCurrency], }) @authenticate(STRATEGY.BEARER, { passReqToCallback: true, }) @put(`${basePath}/{id}`, { security: OPERATION_SECURITY_SPEC, responses: { [STATUS_CODE.NO_CONTENT]: { description: 'Currency PUT success', }, }, }) async replaceById( @param.path.string('id') id: string, @requestBody() currency: Currency, ): Promise { await this.currencyRepository.replaceById(id, currency); } @authorize({ permissions: [PermissionKey.DeleteCurrency], }) @authenticate(STRATEGY.BEARER, { passReqToCallback: true, }) @del(`${basePath}/{id}`, { security: OPERATION_SECURITY_SPEC, responses: { [STATUS_CODE.NO_CONTENT]: { description: 'Currency DELETE success', }, }, }) async deleteById(@param.path.string('id') id: string): Promise { await this.currencyRepository.deleteById(id); } }