Skip to content

Commit

Permalink
added logo to create group endpoint (backend)
Browse files Browse the repository at this point in the history
  • Loading branch information
omersafakbebek committed Dec 18, 2023
1 parent 13bbd69 commit 14df8fc
Show file tree
Hide file tree
Showing 9 changed files with 45 additions and 39 deletions.
1 change: 0 additions & 1 deletion ludos/backend/src/controllers/game.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -264,7 +264,6 @@ export class GameController {
return HttpStatus.OK;
}


@ApiOperation({ summary: 'Get Related Games Endpoint' })
@ApiNotFoundResponse({ description: 'Game is not found!' })
@Get(':gameId/related')
Expand Down
4 changes: 3 additions & 1 deletion ludos/backend/src/controllers/user.controller.ts
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,9 @@ export class UserController {
@ApiNotFoundResponse({ description: 'User is not found!' })
@Get('/suggested')
public async getSuggestedGames(@Req() req: AuthorizedRequest) {
const suggestedGames = await this.userService.getSuggestedGames(req.user.id);
const suggestedGames = await this.userService.getSuggestedGames(
req.user.id,
);
return suggestedGames;
}
}
2 changes: 1 addition & 1 deletion ludos/backend/src/entities/group.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ export class Group {
@JoinTable()
members: User[];

@OneToMany("Post","group")
@OneToMany('Post', 'group')
posts: Post[];

@Column()
Expand Down
2 changes: 1 addition & 1 deletion ludos/backend/src/entities/post.entity.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ export class Post {
})
numberOfDislikes: number;

@ManyToOne("Group")
@ManyToOne('Group')
group: Group;

@Column('text', { array: true, default: [] })
Expand Down
9 changes: 5 additions & 4 deletions ludos/backend/src/repositories/game.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -128,10 +128,11 @@ export class GameRepository extends Repository<Game> {
return this.metadata.relations.map((relation) => relation.propertyName);
}


public async getRelatedGames(gameId: string, tags: string[]): Promise<Game[]> {

const tagArray = tags.map(tag => `'${tag}'`).join(',');
public async getRelatedGames(
gameId: string,
tags: string[],
): Promise<Game[]> {
const tagArray = tags.map((tag) => `'${tag}'`).join(',');
const query = `
SELECT *,
(SELECT COUNT(*) FROM UNNEST(games.tags) tag WHERE tag = ANY(ARRAY[${tagArray}])) AS match_count
Expand Down
4 changes: 1 addition & 3 deletions ludos/backend/src/repositories/user.repository.ts
Original file line number Diff line number Diff line change
Expand Up @@ -71,8 +71,7 @@ export class UserRepository extends Repository<User> {
return paginationResult;
}

public async getSuggestedGames (userId: string): Promise<Game[]> {

public async getSuggestedGames(userId: string): Promise<Game[]> {
const query = `
WITH user_followed_games AS (
SELECT
Expand Down Expand Up @@ -101,5 +100,4 @@ export class UserRepository extends Repository<User> {

return suggestedGames;
}

}
31 changes: 17 additions & 14 deletions ludos/backend/src/services/game.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -193,26 +193,29 @@ export class GameService {
}

public async getRelatedGames(gameId: string): Promise<GameGetResponseDto[]> {

const game = await this.gameRepository.findGameById(gameId);
if (!game) {
throw new NotFoundException('Game not found');
}

const relatedGames = await this.gameRepository.getRelatedGames(gameId, game.tags);

const relatedGamesResponse: GameGetResponseDto[] = relatedGames.map((relatedGame : Game) => ({
id: relatedGame.id,
title: relatedGame.title,
coverLink : relatedGame.coverLink,
gameBio : relatedGame.gameBio,
releaseDate : relatedGame.releaseDate,
developer : relatedGame.developer,
userCompletionDuration : relatedGame.userCompletionDuration,
averageCompletionDuration : relatedGame.averageCompletionDuration
}));
const relatedGames = await this.gameRepository.getRelatedGames(
gameId,
game.tags,
);

const relatedGamesResponse: GameGetResponseDto[] = relatedGames.map(
(relatedGame: Game) => ({
id: relatedGame.id,
title: relatedGame.title,
coverLink: relatedGame.coverLink,
gameBio: relatedGame.gameBio,
releaseDate: relatedGame.releaseDate,
developer: relatedGame.developer,
userCompletionDuration: relatedGame.userCompletionDuration,
averageCompletionDuration: relatedGame.averageCompletionDuration,
}),
);

return relatedGamesResponse;
}

}
1 change: 1 addition & 0 deletions ludos/backend/src/services/group.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,7 @@ export class GroupService {
name: input.name,
description: input.description,
tags: input.tags,
logo: input.logo,
});
return group;
}
Expand Down
30 changes: 16 additions & 14 deletions ludos/backend/src/services/user.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -211,21 +211,23 @@ export class UserService {
return response;
}


public async getSuggestedGames(userId: string): Promise<GameGetResponseDto[]> {

public async getSuggestedGames(
userId: string,
): Promise<GameGetResponseDto[]> {
const suggestedGames = await this.userRepository.getSuggestedGames(userId);

const suggestedGamesResponse: GameGetResponseDto[] = suggestedGames.map((relatedGame : Game) => ({
id: relatedGame.id,
title: relatedGame.title,
coverLink : relatedGame.coverLink,
gameBio : relatedGame.gameBio,
releaseDate : relatedGame.releaseDate,
developer : relatedGame.developer,
userCompletionDuration : relatedGame.userCompletionDuration,
averageCompletionDuration : relatedGame.averageCompletionDuration
}));

const suggestedGamesResponse: GameGetResponseDto[] = suggestedGames.map(
(relatedGame: Game) => ({
id: relatedGame.id,
title: relatedGame.title,
coverLink: relatedGame.coverLink,
gameBio: relatedGame.gameBio,
releaseDate: relatedGame.releaseDate,
developer: relatedGame.developer,
userCompletionDuration: relatedGame.userCompletionDuration,
averageCompletionDuration: relatedGame.averageCompletionDuration,
}),
);

return suggestedGamesResponse;
}
Expand Down

0 comments on commit 14df8fc

Please sign in to comment.