From cc92fbccc900a1c45a7c1258c4996c9483ed3e44 Mon Sep 17 00:00:00 2001 From: Tsah Date: Tue, 4 Aug 2026 17:44:08 +0300 Subject: [PATCH 1/2] feat: add string helpers and cats count/findOne endpoints --- python/strings.py | 14 ++++++++++++++ typescript/nestjs/src/cats/cats.controller.ts | 19 +++++++++++++++---- 2 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 python/strings.py diff --git a/python/strings.py b/python/strings.py new file mode 100644 index 0000000..0ddefc7 --- /dev/null +++ b/python/strings.py @@ -0,0 +1,14 @@ +def slugify(text): + return "-".join(text.lower().split()) + + +def truncate(text, limit): + if limit < 0: + raise ValueError("limit must be non-negative") + if len(text) <= limit: + return text + return text[:limit].rstrip() + "..." + + +def initials(full_name): + return "".join(part[0].upper() for part in full_name.split() if part) diff --git a/typescript/nestjs/src/cats/cats.controller.ts b/typescript/nestjs/src/cats/cats.controller.ts index 0d02279..31339c4 100644 --- a/typescript/nestjs/src/cats/cats.controller.ts +++ b/typescript/nestjs/src/cats/cats.controller.ts @@ -1,4 +1,4 @@ -import { Body, Controller, Get, Param, Post, UseGuards } from '@nestjs/common'; +import { Body, Controller, Get, NotFoundException, Param, Post, UseGuards } from '@nestjs/common'; import { Roles } from '../common/decorators/roles.decorator'; import { RolesGuard } from '../common/guards/roles.guard'; import { ParseIntPipe } from '../common/pipes/parse-int.pipe'; @@ -22,11 +22,22 @@ export class CatsController { return this.catsService.findAll(); } + @Get('count') + async count(): Promise { + const cats = await this.catsService.findAll(); + return cats.length; + } + @Get(':id') - findOne( + async findOne( @Param('id', new ParseIntPipe()) id: number, - ) { - // get by ID logic + ): Promise { + const cats = await this.catsService.findAll(); + const cat = cats[id]; + if (!cat) { + throw new NotFoundException(`No cat at index ${id}`); + } + return cat; } } From 2e6bdc7e003cda6752d9ae92dd06b4221baf4d5e Mon Sep 17 00:00:00 2001 From: Tsah Date: Tue, 4 Aug 2026 17:47:53 +0300 Subject: [PATCH 2/2] feat: add title_case string helper --- python/strings.py | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/python/strings.py b/python/strings.py index 0ddefc7..8187d34 100644 --- a/python/strings.py +++ b/python/strings.py @@ -12,3 +12,7 @@ def truncate(text, limit): def initials(full_name): return "".join(part[0].upper() for part in full_name.split() if part) + + +def title_case(text): + return " ".join(word.capitalize() for word in text.split())