diff --git a/BE/src/mates/mates.controller.ts b/BE/src/mates/mates.controller.ts index ea59de8..18db036 100644 --- a/BE/src/mates/mates.controller.ts +++ b/BE/src/mates/mates.controller.ts @@ -7,6 +7,7 @@ import { Body, UseGuards, Query, + Patch, } from '@nestjs/common'; import { ApiBearerAuth, @@ -154,4 +155,37 @@ export class MatesController { message: '성공적으로 삭제되었습니다.', }; } + + @Patch('fixation') + @UseGuards(AccessTokenGuard) + @ApiBearerAuth() + @ApiOperation({ summary: '친구 목록에서 고정/고정 해제' }) + @ApiBody({ + schema: { + properties: { + following_id: { + type: 'number', + description: '친구의 id', + example: '1', + }, + fixation: { + type: 'boolean', + description: '고정/고정 해제 여부', + example: 'true', + }, + }, + }, + }) + async fixationMate( + @User('id') id: number, + @Body('following_id') following_id: number, + @Body('is_fixed') is_fixed: boolean, + ): Promise { + await this.matesService.fixationMate(id, following_id, is_fixed); + + return { + statusCode: 200, + message: '수정 완료', + }; + } } diff --git a/BE/src/mates/mates.entity.ts b/BE/src/mates/mates.entity.ts index b3058ba..2a327aa 100644 --- a/BE/src/mates/mates.entity.ts +++ b/BE/src/mates/mates.entity.ts @@ -1,4 +1,10 @@ -import { Entity, PrimaryGeneratedColumn, ManyToOne, JoinColumn } from 'typeorm'; +import { + Entity, + PrimaryGeneratedColumn, + ManyToOne, + JoinColumn, + Column, +} from 'typeorm'; import { UsersModel } from 'src/users/entity/users.entity'; @Entity() @@ -19,4 +25,7 @@ export class Mates { }) @JoinColumn({ name: 'following_id' }) following_id: UsersModel; + + @Column({ type: 'boolean', default: false }) + is_fixed: boolean; } diff --git a/BE/src/mates/mates.service.spec.ts b/BE/src/mates/mates.service.spec.ts index 65f4c03..8334c6a 100644 --- a/BE/src/mates/mates.service.spec.ts +++ b/BE/src/mates/mates.service.spec.ts @@ -78,11 +78,13 @@ describe('MatesService', () => { id: 2, follower_id: { id: 1 }, following_id: { id: 3 }, + fixation: false, } as never); jest.spyOn(repository, 'save').mockResolvedValueOnce({ id: 2, follower_id: { id: 1 } as UsersModel, following_id: { id: 3 } as UsersModel, + is_fixed: false, }); const result = await service.addMate(user, '어린콩3'); expect(result).toStrictEqual({ @@ -133,6 +135,7 @@ describe('MatesService', () => { id: 1, follower_id: { id: 1 } as UsersModel, following_id: { id: 3 } as UsersModel, + is_fixed: false, }); expect(service.addMate(user, '어린콩2')).rejects.toThrow( BadRequestException, @@ -176,6 +179,7 @@ describe('MatesService', () => { id: 1, follower_id: { id: 1 } as UsersModel, following_id: { id: 2 } as UsersModel, + is_fixed: false, }, ]); jest @@ -198,7 +202,7 @@ describe('MatesService', () => { jest .spyOn(redisService, 'hget') .mockResolvedValueOnce('2023-11-29 16:00:00'); - const result = await service.getMates(1, '2023-11-29', '09:00'); + const result = await service.getMates(1, '2023-11-29 00:00:00', ' 09:00'); expect(result).toStrictEqual([ { id: 2, @@ -211,7 +215,7 @@ describe('MatesService', () => { }); it('친구가 없는 유저는 빈 배열을 가져온다.', async () => { jest.spyOn(service, 'getMatesStudyTime').mockResolvedValueOnce([]); - const result = await service.getMates(3, '2023-11-29', '09:00'); + const result = await service.getMates(3, '2023-11-29 00:00:00', '09:00'); expect(result).toStrictEqual([]); }); }); @@ -271,6 +275,7 @@ describe('MatesService', () => { id: 1, follower_id: { id: 1 } as UsersModel, following_id: { id: 2 } as UsersModel, + is_fixed: false, }); const result = await service.findMate(user, '어린콩2'); expect(result).toStrictEqual({ diff --git a/BE/src/mates/mates.service.ts b/BE/src/mates/mates.service.ts index ece14a2..4887876 100644 --- a/BE/src/mates/mates.service.ts +++ b/BE/src/mates/mates.service.ts @@ -106,8 +106,8 @@ export class MatesService { LEFT JOIN mates m ON m.following_id = u.id LEFT JOIN study_logs s ON s.user_id = u.id AND s.date = DATE(CONVERT_TZ(?, ?, u.timezone)) WHERE m.follower_id = ? - GROUP BY u.id - ORDER BY total_time DESC + GROUP BY u.id, m.fixation + ORDER BY m.fixation DESC, total_time DESC `, [followerDate, followerTimezone, followerId], ); @@ -221,6 +221,24 @@ export class MatesService { } } + async fixationMate( + id, + following_id: number, + is_fixed: boolean, + ): Promise { + const result = await this.matesRepository.update( + { + follower_id: { id: id }, + following_id: { id: following_id }, + }, + { is_fixed: is_fixed }, + ); + + if (!result) { + throw new NotFoundException('해당 친구 관계는 존재하지 않습니다.'); + } + } + entityToDto(mate: Mates): MatesDto { const { id, follower_id, following_id } = mate; const mateDto = {