Last active
March 12, 2021 22:53
-
-
Save QuadradS/5017baa48043ec088e0d473870ec0f1e to your computer and use it in GitHub Desktop.
Пример контроллера:
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
@RestController | |
export default class VehicleMakeController extends BaseController { | |
private vehicleMakeService: VehicleMakeService | |
@Autowired(Injectables.services.vehicleMake) | |
setVehicleMakeService(vehicleMakeService: VehicleMakeService) { | |
this.vehicleMakeService = vehicleMakeService | |
} | |
@PostMapping(Paths.vehicleMake.create) | |
async createOne(@RequestBody(CreateVehicleMakeDTO) dto: CreateVehicleMakeDTO): Promise<VehicleMakeResponseDTO> { | |
return await this.vehicleMakeService.createOne(dto) | |
} | |
@GetMapping(Paths.vehicleMake.getAll) | |
async getAll(): Promise<VehicleMakeResponseDTO[]> { | |
return await this.vehicleMakeService.getAll() | |
} | |
@GetMapping(Paths.vehicleMake.getModels) | |
async getOneWithModels(@PathVariable('id', String) id: string): Promise<VehicleMakeResponseDTO> { | |
return await this.vehicleMakeService.getOneWithModels(id) | |
} | |
@DeleteMapping(Paths.vehicleMake.remove) | |
async removeOne(@PathVariable('id', String) id: string): Promise<void> { | |
await this.vehicleMakeService.removeOne(id) | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export interface VehicleMakeService extends BaseService { | |
createOne(dto: CreateVehicleMakeDTO, entityManager?: EntityManager): Promise<VehicleMakeResponseDTO> | |
getAll(): Promise<VehicleMakeResponseDTO[]> | |
getOneWithModels(id: string): Promise<VehicleMakeResponseDTO> | |
removeOne(id: string, entityManager?: EntityManager): Promise<void> | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { Form, FormikProps } from 'formik' | |
import * as React from 'react' | |
import TextField from '../../ui/TextField' | |
export interface IEditOrgInnerFormValues { | |
orgName: string | |
state: string | |
email: string | |
phone: string | |
timeZone: string | |
website: string | |
} | |
const EditForm = (props: FormikProps<IEditOrgInnerFormValues>) => { | |
return ( | |
<Form> | |
<div className="flex"> | |
<TextField | |
title="Organization Name" | |
name="orgName" | |
optional={false} | |
error={props.errors.orgName} | |
classNameContainer={'mr1'} | |
isTouched={props.touched.orgName} | |
onChange={props.handleChange} | |
value={props.values.orgName} | |
className="mt1 p1 border-light-grey4 rounded" | |
placeholder="First Name" | |
/> | |
<TextField | |
title={'State'} | |
name={'state'} | |
optional={false} | |
error={props.errors.state} | |
classNameContainer={'ml1'} | |
isTouched={props.touched.state} | |
onChange={props.handleChange} | |
value={props.values.state} | |
className="mt1 p1 border-light-grey4 rounded" | |
placeholder="State" | |
/> | |
</div> | |
<div className="flex"> | |
<TextField | |
title={'Email'} | |
name={'email'} | |
optional={true} | |
error={''} | |
classNameContainer={'mr1'} | |
isTouched={props.touched.email} | |
onChange={props.handleChange} | |
value={props.values.email} | |
className="mt1 p1 border-light-grey4 rounded" | |
placeholder="Email" | |
/> | |
<TextField | |
title={'Phone Number'} | |
name={'phone'} | |
optional={true} | |
error={''} | |
classNameContainer={'ml1'} | |
isTouched={props.touched.phone} | |
onChange={props.handleChange} | |
value={props.values.phone} | |
className="mt1 p1 border-light-grey4 rounded" | |
placeholder="Phone Number" | |
/> | |
</div> | |
<div className="flex"> | |
<TextField | |
title={'Time Zone'} | |
name={'timeZone'} | |
optional={false} | |
error={props.errors.timeZone} | |
classNameContainer={'mr1'} | |
isTouched={props.touched.timeZone} | |
onChange={props.handleChange} | |
value={props.values.timeZone} | |
className="mt1 p1 border-light-grey4 rounded" | |
placeholder="Time Zone" | |
/> | |
<TextField | |
title={'Website'} | |
name={'website'} | |
optional={true} | |
error={''} | |
classNameContainer={'ml1'} | |
isTouched={props.touched.website} | |
onChange={props.handleChange} | |
value={props.values.website} | |
className="mt1 p1 border-light-grey4 rounded" | |
placeholder="domain.com" | |
/> | |
</div> | |
</Form> | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Class MockApi{ | |
public getAllOrg(userID:string) Promise<IOrgObject | string>{ | |
return new Promise((res,rej)=>{ | |
if(!userID){ | |
setTimeOut(()=>( rej('User ID is required!') ), 1000) | |
} | |
res([{...}]) | |
}) | |
} | |
} | |
const sockApiService = new MockApi(); | |
export default sockApiService |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment