-
Notifications
You must be signed in to change notification settings - Fork 0
feat(store): 구매자 매장 상세 조회(storeDetail)와 StoreImage 스키마 추가 #157
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
21 changes: 21 additions & 0 deletions
21
prisma/migrations/20260623175315_add_store_image_and_detail_columns/migration.sql
This file contains hidden or 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,21 @@ | ||
| -- AlterTable | ||
| ALTER TABLE `store` ADD COLUMN `access_guide_text` VARCHAR(500) NULL, | ||
| ADD COLUMN `regular_closure_text` VARCHAR(200) NULL; | ||
|
|
||
| -- CreateTable | ||
| CREATE TABLE `store_image` ( | ||
| `id` BIGINT UNSIGNED NOT NULL AUTO_INCREMENT, | ||
| `store_id` BIGINT UNSIGNED NOT NULL, | ||
| `image_url` VARCHAR(2048) NOT NULL, | ||
| `sort_order` INTEGER NOT NULL DEFAULT 0, | ||
| `created_at` DATETIME(3) NOT NULL DEFAULT CURRENT_TIMESTAMP(3), | ||
| `updated_at` DATETIME(3) NOT NULL, | ||
| `deleted_at` DATETIME(3) NULL, | ||
|
|
||
| INDEX `idx_store_image_store`(`store_id`, `sort_order`), | ||
| INDEX `idx_store_image_deleted_at`(`deleted_at`), | ||
| PRIMARY KEY (`id`) | ||
| ) DEFAULT CHARACTER SET utf8mb4 COLLATE utf8mb4_unicode_ci; | ||
|
|
||
| -- AddForeignKey | ||
| ALTER TABLE `store_image` ADD CONSTRAINT `store_image_store_id_fkey` FOREIGN KEY (`store_id`) REFERENCES `store`(`id`) ON DELETE RESTRICT ON UPDATE CASCADE; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,4 @@ | ||
| /** 매장 상세 조회 에러 메시지. */ | ||
| export const STORE_DETAIL_ERRORS = { | ||
| STORE_NOT_FOUND: '매장을 찾을 수 없습니다.', | ||
| } as const; |
This file contains hidden or 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
77 changes: 77 additions & 0 deletions
77
src/features/store/resolvers/store-detail-query.resolver.spec.ts
This file contains hidden or 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,77 @@ | ||
| import { NotFoundException } from '@nestjs/common'; | ||
| import type { PrismaClient } from '@prisma/client'; | ||
|
|
||
| import { StoreWishlistRepository } from '@/features/store/repositories/store-wishlist.repository'; | ||
| import { StoreRepository } from '@/features/store/repositories/store.repository'; | ||
| import { StoreDetailQueryResolver } from '@/features/store/resolvers/store-detail-query.resolver'; | ||
| import { StoreDetailService } from '@/features/store/services/store-detail.service'; | ||
| import { disconnectTestPrismaClient } from '@/test/db/prisma-test-client'; | ||
| import { closeTruncateConnection, truncateAll } from '@/test/db/truncate'; | ||
| import { | ||
| createAccount, | ||
| createStore, | ||
| createStoreWishlist, | ||
| } from '@/test/factories'; | ||
| import { createTestingModuleWithRealDb } from '@/test/modules/testing-module.builder'; | ||
|
|
||
| /** | ||
| * Resolver ↔ Service ↔ Repository ↔ DB 통합 경로 검증. | ||
| * 분기/집계 세부 검증은 service.spec.ts에서 담당. | ||
| */ | ||
| describe('Store Detail Query Resolver (real DB)', () => { | ||
| let resolver: StoreDetailQueryResolver; | ||
| let prisma: PrismaClient; | ||
|
|
||
| beforeAll(async () => { | ||
| const { module, prisma: p } = await createTestingModuleWithRealDb({ | ||
| providers: [ | ||
| StoreDetailQueryResolver, | ||
| StoreDetailService, | ||
| StoreRepository, | ||
| StoreWishlistRepository, | ||
| ], | ||
| }); | ||
| resolver = module.get(StoreDetailQueryResolver); | ||
| prisma = p; | ||
| }); | ||
|
|
||
| afterAll(async () => { | ||
| await closeTruncateConnection(); | ||
| await disconnectTestPrismaClient(); | ||
| }); | ||
|
|
||
| beforeEach(async () => { | ||
| await truncateAll(); | ||
| }); | ||
|
|
||
| it('storeDetail: 비로그인 사용자에게 매장 상세를 반환한다', async () => { | ||
| const store = await createStore(prisma, { store_name: '해즈케이크' }); | ||
|
|
||
| const result = await resolver.storeDetail(store.id.toString(), undefined); | ||
|
|
||
| expect(result.id).toBe(store.id.toString()); | ||
| expect(result.storeName).toBe('해즈케이크'); | ||
| expect(result.isWishlisted).toBe(false); | ||
| }); | ||
|
|
||
| it('storeDetail: 로그인 사용자(JwtUser)의 찜 여부를 채운다', async () => { | ||
| const account = await createAccount(prisma, { account_type: 'USER' }); | ||
| const store = await createStore(prisma); | ||
| await createStoreWishlist(prisma, { | ||
| account_id: account.id, | ||
| store_id: store.id, | ||
| }); | ||
|
|
||
| const result = await resolver.storeDetail(store.id.toString(), { | ||
| accountId: account.id.toString(), | ||
| }); | ||
|
|
||
| expect(result.isWishlisted).toBe(true); | ||
| }); | ||
|
|
||
| it('storeDetail: 없는 매장은 NotFoundException', async () => { | ||
| await expect( | ||
| resolver.storeDetail('999999', undefined), | ||
| ).rejects.toBeInstanceOf(NotFoundException); | ||
| }); | ||
| }); |
30 changes: 30 additions & 0 deletions
30
src/features/store/resolvers/store-detail-query.resolver.ts
This file contains hidden or 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,30 @@ | ||
| import { UseGuards } from '@nestjs/common'; | ||
| import { Args, Query, Resolver } from '@nestjs/graphql'; | ||
|
|
||
| import { StoreDetailService } from '@/features/store/services/store-detail.service'; | ||
| import type { StoreDetail } from '@/features/store/types/store-detail-output.type'; | ||
| import { | ||
| CurrentUser, | ||
| OptionalJwtAuthGuard, | ||
| parseAccountId, | ||
| type JwtUser, | ||
| } from '@/global/auth'; | ||
|
|
||
| /** | ||
| * 매장 상세 조회 resolver. 비로그인도 접근 가능한 public query. | ||
| * 옵셔널 인증으로 로그인 시에만 isWishlisted를 채운다. | ||
| */ | ||
| @Resolver('Query') | ||
| export class StoreDetailQueryResolver { | ||
| constructor(private readonly storeDetailService: StoreDetailService) {} | ||
|
|
||
| @Query('storeDetail') | ||
| @UseGuards(OptionalJwtAuthGuard) | ||
| storeDetail( | ||
| @Args('storeId') storeId: string, | ||
| @CurrentUser() user: JwtUser | undefined, | ||
| ): Promise<StoreDetail> { | ||
| const accountId = user ? parseAccountId(user) : undefined; | ||
| return this.storeDetailService.storeDetail(storeId, accountId); | ||
| } | ||
| } |
Oops, something went wrong.
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
When
yarn prisma:seedis run a second time, these newly-createdstore_imagerows remain duringresetSeedScope: that cleanup deletesstoreBusinessHourandstoreSpecialClosureand then callsprisma.store.deleteManyfor the seed stores, but it never deletesstoreImagerows. Because the new FK isON DELETE RESTRICT, the second seed run will fail with a foreign-key violation instead of staying idempotent; addprisma.storeImage.deleteMany({ where: { store_id: { in: storeIds } } })before deleting stores or make the relation cascade intentionally.Useful? React with 👍 / 👎.