-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
127 additions
and
52 deletions.
There are no files selected for viewing
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
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ServerModule } from './server/server.module'; | ||
import { ClientModule } from './client/client.module'; | ||
import { HttpInterfaceModule } from '@r2don/nest-http-interface'; | ||
|
||
@Module({ | ||
imports: [ServerModule], | ||
imports: [HttpInterfaceModule.forRoot(), ServerModule, ClientModule], | ||
}) | ||
export class AppModule {} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
import { | ||
Controller, | ||
Post, | ||
Body, | ||
Delete, | ||
Get, | ||
Param, | ||
Patch, | ||
} from '@nestjs/common'; | ||
import { ClientHttpService } from './client.http.service'; | ||
import { CreateServerDto } from '../server/dto/create-server.dto'; | ||
import { UpdateServerDto } from '../server/dto/update-server.dto'; | ||
import { Server } from '../server/entities/server.entity'; | ||
|
||
@Controller('client') | ||
export class ClientController { | ||
constructor(private readonly clientService: ClientHttpService) {} | ||
|
||
@Post() | ||
async create(@Body() createClientDto: CreateServerDto): Promise<Server> { | ||
return await this.clientService.create(createClientDto); | ||
} | ||
|
||
@Get() | ||
findAll(): Promise<Server[]> { | ||
return this.clientService.findAll(); | ||
} | ||
|
||
@Get(':id') | ||
findOne(@Param('id') id: string): Promise<Server> { | ||
return this.clientService.findOne(+id); | ||
} | ||
|
||
@Patch(':id') | ||
update( | ||
@Param('id') id: string, | ||
@Body() updateServerDto: UpdateServerDto, | ||
): Promise<void> { | ||
return this.clientService.update(+id, updateServerDto); | ||
} | ||
|
||
@Delete(':id') | ||
remove(@Param('id') id: string): Promise<void> { | ||
return this.clientService.remove(+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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,49 @@ | ||
import { | ||
DeleteExchange, | ||
GetExchange, | ||
HttpInterface, | ||
imitation, | ||
PatchExchange, | ||
PathVariable, | ||
PostExchange, | ||
RequestBody, | ||
ResponseBody, | ||
} from '@r2don/nest-http-interface'; | ||
import { CreateServerDto } from '../server/dto/create-server.dto'; | ||
import { Server } from '../server/entities/server.entity'; | ||
import { UpdateServerDto } from '../server/dto/update-server.dto'; | ||
|
||
@HttpInterface('http://localhost:3000') | ||
export class ClientHttpService { | ||
@PostExchange('/api/servers') | ||
@ResponseBody(Server) // you don't need to use this decorator if cli plugin is configured (see nest-cli.json) | ||
async create( | ||
@RequestBody() createServerDto: CreateServerDto, | ||
): Promise<Server> { | ||
return imitation(createServerDto); | ||
} | ||
|
||
@GetExchange('/api/servers') | ||
async findAll(): Promise<Server[]> { | ||
return imitation(); | ||
} | ||
|
||
@GetExchange('/api/servers/{id}') | ||
async findOne(@PathVariable('id') id: number): Promise<Server> { | ||
return imitation(id); | ||
} | ||
|
||
@PatchExchange('/api/servers/{id}') | ||
async update( | ||
@PathVariable('id') id: number, | ||
@RequestBody() | ||
updateServerDto: UpdateServerDto, | ||
): Promise<void> { | ||
return imitation(id, updateServerDto); | ||
} | ||
|
||
@DeleteExchange('/api/servers/{id}') | ||
async remove(@PathVariable('id') id: number): Promise<void> { | ||
return imitation(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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
import { Module } from '@nestjs/common'; | ||
import { ClientHttpService } from './client.http.service'; | ||
import { ClientController } from './client.controller'; | ||
|
||
@Module({ | ||
controllers: [ClientController], | ||
providers: [ClientHttpService], | ||
}) | ||
export class ClientModule {} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
import { PartialType } from '@nestjs/mapped-types'; | ||
import { CreateServerDto } from './create-server.dto'; | ||
|
||
export class UpdateServerDto extends PartialType(CreateServerDto) {} | ||
export class UpdateServerDto { | ||
name?: string; | ||
isOnline?: boolean; | ||
} |