Skip to content

Commit

Permalink
added endpoints for image annotations to backend
Browse files Browse the repository at this point in the history
  • Loading branch information
omersafakbebek committed Dec 24, 2023
1 parent b02364d commit 8a712e0
Show file tree
Hide file tree
Showing 13 changed files with 101 additions and 30 deletions.
38 changes: 35 additions & 3 deletions ludos/backend/src/controllers/annotation.controller.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
import { Body, Controller, Delete, Get, HttpCode, Param, Post } from '@nestjs/common';
import {
Body,
Controller,
Delete,
Get,
HttpCode,
Param,
Post,
Query,
} from '@nestjs/common';
import {
ApiNotFoundResponse,
ApiOkResponse,
Expand Down Expand Up @@ -126,6 +135,27 @@ export class AnnotationController {
): Promise<AnnotationResponseDto> {
return await this.annotationService.createAnnotationForPost(input, postId);
}
@ApiOperation({ summary: 'Create Annotation For Image Endpoint' })
@ApiOkResponse({
description: 'Annotation created successfully',
type: AnnotationResponseDto,
})
@Post('image')
public async createAnnotationForImage(
@Body() input: CreateAnnotationDto,
): Promise<AnnotationResponseDto> {
return await this.annotationService.createAnnotationForImage(input);
}
@ApiOperation({ summary: 'Get Annotations For Image Endpoint' })
@ApiOkResponse({
type: [AnnotationResponseDto],
})
@Get('image')
public async getAnnotationsForImage(
@Query('imageUrl') imageUrl: string,
): Promise<AnnotationResponseDto[]> {
return await this.annotationService.getAnnotationsForImage(imageUrl);
}
@ApiOperation({ summary: 'Get Annotations For Game Bio of Game Endpoint' })
@ApiOkResponse({
type: [AnnotationResponseDto],
Expand Down Expand Up @@ -225,7 +255,6 @@ export class AnnotationController {
return this.annotationService.deleteAnnotationById(annotationId);
}


@ApiOperation({ summary: 'Create Annotation For Comment Endpoint' })
@ApiOkResponse({
description: 'Annotation created successfully',
Expand All @@ -239,7 +268,10 @@ export class AnnotationController {
@Body() input: CreateAnnotationDto,
@Param('commentId') commentId: string,
): Promise<AnnotationResponseDto> {
return await this.annotationService.createAnnotationForComment(input, commentId);
return await this.annotationService.createAnnotationForComment(
input,
commentId,
);
}

@ApiOperation({ summary: 'Get Annotations For Comment Endpoint' })
Expand Down
5 changes: 4 additions & 1 deletion ludos/backend/src/controllers/comment.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ export class CommentController {
@Req() req: AuthorizedRequest,
@Param('parentId') parentId: string,
) {
return await this.commentService.getCommentsByParent(req.user?.id, parentId);
return await this.commentService.getCommentsByParent(
req.user?.id,
parentId,
);
}

@ApiOperation({ summary: 'Comment on a post/comment/review' })
Expand Down
1 change: 0 additions & 1 deletion ludos/backend/src/controllers/review.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -140,5 +140,4 @@ export class ReviewController {
);
return reviews;
}

}
1 change: 0 additions & 1 deletion ludos/backend/src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -192,5 +192,4 @@ export class UserController {
public async getUserIdByUsername(@Param('userId') username: string) {
return await this.userService.getUserIdByUsername(username);
}

}
30 changes: 27 additions & 3 deletions ludos/backend/src/dtos/annotation/request/create.dto.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,11 @@
import { ApiProperty } from '@nestjs/swagger';
import { Expose, Type } from 'class-transformer';
import { IsString, ValidateNested, IsNumber } from 'class-validator';
import {
IsString,
ValidateNested,
IsNumber,
IsOptional,
} from 'class-validator';

class AnnotationTargetSelectorDto {
@ApiProperty()
Expand All @@ -19,11 +24,30 @@ class AnnotationTargetDto {
@IsString()
source: string;

@ApiProperty()
@ApiProperty({ required: false })
@Expose()
@Type(() => AnnotationTargetSelectorDto)
@ValidateNested()
selector: AnnotationTargetSelectorDto;
@IsOptional()
selector?: AnnotationTargetSelectorDto;

@ApiProperty({ required: false })
@Expose()
@IsString()
@IsOptional()
type?: string;

@ApiProperty({ required: false })
@Expose()
@IsString()
@IsOptional()
id?: string;

@ApiProperty({ required: false })
@Expose()
@IsString()
@IsOptional()
format?: string;
}
export class CreateAnnotationDto {
@ApiProperty()
Expand Down
1 change: 0 additions & 1 deletion ludos/backend/src/dtos/post/request/create.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,6 @@ export class PostCreateDto {
@IsOptional()
tags: string[];


@ApiProperty({
description: 'Upcoming Title',
})
Expand Down
2 changes: 1 addition & 1 deletion ludos/backend/src/dtos/post/upcomingTitle.dto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,4 @@ export class UpcomingTitleDto {

@IsString()
demoLink: string;
}
}
10 changes: 6 additions & 4 deletions ludos/backend/src/repositories/post.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,10 +90,12 @@ export class PostRepository extends Repository<Post> {
queryBuilder.andWhere('posts.userId = :ownerUserId', { ownerUserId });
}
if (isUpcomingTitle) {
console.log("seeeennnn");
queryBuilder.andWhere('posts."upcomingTitle"->>\'isUpcomingTitle\' = :isUpcomingTitle', {
isUpcomingTitle: isUpcomingTitle.toString(),
});
queryBuilder.andWhere(
'posts."upcomingTitle"->>\'isUpcomingTitle\' = :isUpcomingTitle',
{
isUpcomingTitle: isUpcomingTitle.toString(),
},
);
}
if (userId && isLiked) {
const subQuery = this.createQueryBuilder()
Expand Down
18 changes: 17 additions & 1 deletion ludos/backend/src/services/annotation.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,20 @@ export class AnnotationService {
);
return response.data;
}
async createAnnotationForImage(
input: CreateAnnotationDto,
): Promise<AnnotationResponseDto> {
const response = await axios.post(`http://35.157.67.64:8090/image`, input);
return response.data;
}
async getAnnotationsForImage(
imageUrl: string,
): Promise<AnnotationResponseDto[]> {
const response = await axios.get(
`http://35.157.67.64:8090/image?imageUrl=${imageUrl}`,
);
return response.data;
}
async getAnnotationsForGameBio(
gameId: string,
): Promise<AnnotationResponseDto[]> {
Expand Down Expand Up @@ -209,7 +223,9 @@ export class AnnotationService {
throw new NotFoundException(`comment with id ${commentId} not found`);
}

const response = await axios.get(`http://35.157.67.64:8090/comment/${commentId}`);
const response = await axios.get(
`http://35.157.67.64:8090/comment/${commentId}`,
);
return response.data;
}
}
2 changes: 0 additions & 2 deletions ludos/backend/src/services/comment.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@ export class CommentService {
userId: string | null,
commentId: string,
): Promise<GetCommentResponseDto> {

if (!userId) {
const user = await this.userRepository.findUserById(userId);

Expand Down Expand Up @@ -75,7 +74,6 @@ export class CommentService {
userId: string | null,
parentId: string,
): Promise<GetCommentResponseDto[]> {

if (!userId) {
const user = await this.userRepository.findUserById(userId);

Expand Down
13 changes: 8 additions & 5 deletions ludos/backend/src/services/review.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -245,8 +245,10 @@ export class ReviewService {
likedUserCount: likedUserCount,
dislikedUserCount: dislikedUserCount,
isBelongToUser: userId && review.user.id == userId,
isLikedByUser: userId && review.likedUsers.some((user) => user.id === userId),
isDislikedByUser: userId && review.dislikedUsers.some((user) => user.id === userId),
isLikedByUser:
userId && review.likedUsers.some((user) => user.id === userId),
isDislikedByUser:
userId && review.dislikedUsers.some((user) => user.id === userId),
};
}

Expand All @@ -259,7 +261,6 @@ export class ReviewService {
throw new NotFoundException('Game Not Found!');
}


const reviews = await this.reviewRepository.findReviewsByGame(game);

const mappedReviews: ReviewGetInfoResponseDto[] = reviews.map((review) => ({
Expand All @@ -273,8 +274,10 @@ export class ReviewService {
likedUserCount: review.likedUsers.length,
dislikedUserCount: review.dislikedUsers.length,
isBelongToUser: userId && review.user.id == userId,
isLikedByUser: userId && review.likedUsers.some((user) => user.id === userId),
isDislikedByUser: userId && review.dislikedUsers.some((user) => user.id === userId),
isLikedByUser:
userId && review.likedUsers.some((user) => user.id === userId),
isDislikedByUser:
userId && review.dislikedUsers.some((user) => user.id === userId),
}));
return mappedReviews;
}
Expand Down
2 changes: 1 addition & 1 deletion ludos/backend/src/services/search.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@ export class SearchService {
undefined,
undefined,
userId,
)
);
return {
users: users.items,
games: games.items,
Expand Down
8 changes: 2 additions & 6 deletions ludos/backend/src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -210,9 +210,7 @@ export class UserService {
return response;
}

public async getSuggestedGames(
userId: string,
): Promise<Game[]> {
public async getSuggestedGames(userId: string): Promise<Game[]> {
const suggestedGames = await this.userRepository.getSuggestedGames(userId);
return suggestedGames;
}
Expand All @@ -223,9 +221,7 @@ export class UserService {
if (user) {
return user.id;
}

return null;
}


}

0 comments on commit 8a712e0

Please sign in to comment.