-
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
1 parent
c1f5a45
commit b685644
Showing
7 changed files
with
125 additions
and
11 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
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,9 +1,42 @@ | ||
import { Controller, Get } from '@nestjs/common'; | ||
import { | ||
Body, | ||
Controller, | ||
Delete, | ||
Get, | ||
Param, | ||
Post, | ||
Put, | ||
} from '@nestjs/common'; | ||
import { CountriesService } from './countries.service'; | ||
import { Country } from '@shared/dto/countries/country.entity'; | ||
import { CreateCountryDto } from '@shared/dto/countries/create-country.dto'; | ||
|
||
@Controller() | ||
@Controller('countries') | ||
export class CountriesController { | ||
@Get('countries') | ||
createCountry() { | ||
return 'This action adds a new country'; | ||
constructor(private countriesService: CountriesService) {} | ||
|
||
@Post() | ||
async create(@Body() createCountryDto: CreateCountryDto) { | ||
this.countriesService.create(createCountryDto); | ||
} | ||
|
||
@Get() | ||
async findAll(): Promise<Country[]> { | ||
return this.countriesService.findAll(); | ||
} | ||
|
||
@Get(':id') | ||
async findOne(@Param('id') id: string) { | ||
return this.countriesService.findOne(+id); | ||
} | ||
|
||
@Put(':id') | ||
async update(@Param('id') id: string) { | ||
return this.countriesService.update(+id); | ||
} | ||
|
||
@Delete(':id') | ||
async remove(@Param('id') id: string) { | ||
return this.countriesService.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 |
---|---|---|
@@ -1,4 +1,37 @@ | ||
import { Injectable } from '@nestjs/common'; | ||
import { Country } from '@shared/dto/countries/country.entity'; | ||
|
||
@Injectable() | ||
export class CountriesService {} | ||
export class CountriesService { | ||
private readonly country: Country[] = []; | ||
|
||
create(country: Country) { | ||
this.country.push(country); | ||
} | ||
|
||
findAll(): Country[] { | ||
return this.country; | ||
} | ||
|
||
findOne(id: number) { | ||
return this.country.find((country) => country.id === id); | ||
} | ||
|
||
update(id: number) { | ||
const index = this.country.findIndex((country) => country.id === id); | ||
if (index === -1) { | ||
return 'Country not found'; | ||
} | ||
this.country[index] = { ...this.country[index], name: 'Country updated' }; | ||
return 'Country updated'; | ||
} | ||
|
||
remove(id: number) { | ||
const index = this.country.findIndex((country) => country.id === id); | ||
if (index === -1) { | ||
return 'Country not found'; | ||
} | ||
this.country.splice(index, 1); | ||
return 'Country removed'; | ||
} | ||
} |
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,9 +1,29 @@ | ||
import { Controller, Get } from '@nestjs/common'; | ||
import { Controller, Delete, Get, Param, Post, Put } from '@nestjs/common'; | ||
|
||
@Controller() | ||
export class UsersController { | ||
@Get('users') | ||
createUser() { | ||
@Post('users') | ||
create(): string { | ||
return 'This action adds a new user'; | ||
} | ||
|
||
@Get('users') | ||
findAll(): string { | ||
return 'This action returns all users'; | ||
} | ||
|
||
@Get('users/:id') | ||
findOne(@Param('id') id: string): string { | ||
return `This action returns a #${id} user`; | ||
} | ||
|
||
@Put('users/:id') | ||
update(@Param('id') id: string) { | ||
return `This action updates a #${id} user`; | ||
} | ||
|
||
@Delete('users/:id') | ||
remove(@Param('id') id: string) { | ||
return `This action removes a #${id} user`; | ||
} | ||
} |
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
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,22 @@ | ||
import { IsNotEmpty, IsNumber, IsString } from 'class-validator'; | ||
import { User } from '../users/user.entity'; | ||
|
||
export class CreateCountryDto { | ||
@IsNumber() | ||
@IsNotEmpty() | ||
id: number; | ||
|
||
@IsString({ message: 'Name must be a string' }) | ||
@IsNotEmpty() | ||
name: string; | ||
|
||
@IsNotEmpty() | ||
iso: string; | ||
|
||
users: User[]; | ||
|
||
@IsNotEmpty() | ||
createdAt: Date; | ||
@IsNotEmpty() | ||
updatedAt: Date; | ||
} |
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