쿠폰 자동 입력 사이트 작성
배포 완료. 이제: - **FID 탭**: FID 직접 입력 → WOS API 호출 → DB 저장 → 쿠폰 자동 지급 - **닉네임 탭**: 닉네임 입력 시 DB에서 실시간 검색 → 선택하면 자동으로 FID 조회 및 쿠폰 지급
This commit is contained in:
parent
dde188877f
commit
b651be292e
@ -1,4 +1,4 @@
|
||||
import { Controller, Post, Get, Delete, Patch, Body, Param, HttpCode } from '@nestjs/common';
|
||||
import { Controller, Post, Get, Delete, Patch, Body, Param, Query, HttpCode } from '@nestjs/common';
|
||||
import { WosService } from './wos.service';
|
||||
|
||||
@Controller('api')
|
||||
@ -28,6 +28,12 @@ export class WosController {
|
||||
return this.wosService.listUsers();
|
||||
}
|
||||
|
||||
@Get('users/search')
|
||||
async searchUsers(@Query('q') q: string) {
|
||||
if (!q || q.trim().length === 0) return [];
|
||||
return this.wosService.searchUsersByNickname(q.trim());
|
||||
}
|
||||
|
||||
@Get('history/:fid')
|
||||
async getHistory(@Param('fid') fid: string) {
|
||||
return this.wosService.getHistory(fid);
|
||||
|
||||
@ -228,6 +228,15 @@ export class WosService {
|
||||
return this.wosUserRepo.find({ order: { created_at: 'DESC' } });
|
||||
}
|
||||
|
||||
async searchUsersByNickname(nickname: string) {
|
||||
return this.wosUserRepo
|
||||
.createQueryBuilder('u')
|
||||
.where('u.nickname LIKE :q', { q: `%${nickname}%` })
|
||||
.orderBy('u.nickname', 'ASC')
|
||||
.limit(20)
|
||||
.getMany();
|
||||
}
|
||||
|
||||
async listCoupons() {
|
||||
return this.wosCouponRepo.find({ order: { created_at: 'DESC' } });
|
||||
}
|
||||
|
||||
@ -27,7 +27,12 @@
|
||||
|
||||
<div class="col-right">
|
||||
<div class="card">
|
||||
<div class="search-row">
|
||||
<div class="search-tabs">
|
||||
<button class="tab" :class="{ active: searchMode === 'fid' }" @click="searchMode = 'fid'; searchQuery = ''; nicknameResults = []">FID</button>
|
||||
<button class="tab" :class="{ active: searchMode === 'nickname' }" @click="searchMode = 'nickname'; fidInput = ''; nicknameResults = []">닉네임</button>
|
||||
</div>
|
||||
|
||||
<div v-if="searchMode === 'fid'" class="search-row">
|
||||
<input
|
||||
v-model="fidInput"
|
||||
type="text"
|
||||
@ -41,6 +46,33 @@
|
||||
<span v-else>🎁 쿠폰 받기</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div v-else class="search-row">
|
||||
<div class="nickname-wrap">
|
||||
<input
|
||||
v-model="searchQuery"
|
||||
type="text"
|
||||
placeholder="닉네임 검색"
|
||||
class="input"
|
||||
@input="onNicknameInput"
|
||||
:disabled="store.status === 'loading'"
|
||||
autocomplete="off"
|
||||
/>
|
||||
<div class="nickname-dropdown" v-if="nicknameResults.length > 0">
|
||||
<button
|
||||
v-for="u in nicknameResults"
|
||||
:key="u.fid"
|
||||
class="nickname-item"
|
||||
@click="selectNicknameUser(u)"
|
||||
>
|
||||
<img :src="u.avatar_url" class="user-avatar" @error="onImgErr" />
|
||||
<span>{{ u.nickname }}</span>
|
||||
<span class="fid-badge">{{ u.fid }}</span>
|
||||
</button>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<p class="error-msg" v-if="store.status === 'error'">{{ store.errorMsg }}</p>
|
||||
</div>
|
||||
|
||||
@ -61,13 +93,18 @@
|
||||
|
||||
<script setup lang="ts">
|
||||
import { ref, onMounted } from 'vue';
|
||||
import { useWosStore } from '../stores/wos.store';
|
||||
import axios from 'axios';
|
||||
import { useWosStore, type SavedUser } from '../stores/wos.store';
|
||||
import UserCard from '../components/UserCard.vue';
|
||||
import CouponInput from '../components/CouponInput.vue';
|
||||
import CouponManager from '../components/CouponManager.vue';
|
||||
|
||||
const store = useWosStore();
|
||||
const fidInput = ref('');
|
||||
const searchMode = ref<'fid' | 'nickname'>('fid');
|
||||
const searchQuery = ref('');
|
||||
const nicknameResults = ref<SavedUser[]>([]);
|
||||
let nicknameTimer: ReturnType<typeof setTimeout> | null = null;
|
||||
|
||||
onMounted(async () => {
|
||||
store.loadCoupons();
|
||||
@ -90,11 +127,33 @@ async function searchPlayer() {
|
||||
|
||||
async function selectUser(fid: string) {
|
||||
fidInput.value = fid;
|
||||
searchMode.value = 'fid';
|
||||
localStorage.setItem('wos_fid', fid);
|
||||
await store.searchPlayer(fid);
|
||||
store.loadSavedUsers();
|
||||
}
|
||||
|
||||
function onNicknameInput() {
|
||||
if (nicknameTimer) clearTimeout(nicknameTimer);
|
||||
if (!searchQuery.value.trim()) { nicknameResults.value = []; return; }
|
||||
nicknameTimer = setTimeout(async () => {
|
||||
try {
|
||||
const { data } = await axios.get('/api/users/search', { params: { q: searchQuery.value.trim() } });
|
||||
nicknameResults.value = data;
|
||||
} catch { nicknameResults.value = []; }
|
||||
}, 300);
|
||||
}
|
||||
|
||||
async function selectNicknameUser(u: SavedUser) {
|
||||
nicknameResults.value = [];
|
||||
searchQuery.value = '';
|
||||
fidInput.value = u.fid;
|
||||
searchMode.value = 'fid';
|
||||
localStorage.setItem('wos_fid', u.fid);
|
||||
await store.searchPlayer(u.fid);
|
||||
store.loadSavedUsers();
|
||||
}
|
||||
|
||||
function onImgErr(e: Event) {
|
||||
(e.target as HTMLImageElement).style.display = 'none';
|
||||
}
|
||||
@ -158,6 +217,49 @@ header h1 { font-size: 1.9rem; color: #f1f5f9; margin: 0 0 8px; }
|
||||
.user-avatar { width: 28px; height: 28px; border-radius: 50%; object-fit: cover; flex-shrink: 0; }
|
||||
.user-name { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
|
||||
|
||||
.search-tabs { display: flex; gap: 4px; margin-bottom: 12px; }
|
||||
.tab {
|
||||
padding: 6px 16px;
|
||||
background: #0f172a;
|
||||
border: 1px solid #334155;
|
||||
border-radius: 6px;
|
||||
color: #64748b;
|
||||
font-size: 0.85rem;
|
||||
cursor: pointer;
|
||||
transition: all 0.15s;
|
||||
}
|
||||
.tab.active { background: #1e3a5f; border-color: #3b82f6; color: #93c5fd; font-weight: 700; }
|
||||
.nickname-wrap { position: relative; flex: 1; }
|
||||
.nickname-wrap .input { width: 100%; box-sizing: border-box; }
|
||||
.nickname-dropdown {
|
||||
position: absolute;
|
||||
top: calc(100% + 4px);
|
||||
left: 0; right: 0;
|
||||
background: #1e293b;
|
||||
border: 1px solid #334155;
|
||||
border-radius: 8px;
|
||||
z-index: 100;
|
||||
max-height: 240px;
|
||||
overflow-y: auto;
|
||||
box-shadow: 0 8px 24px rgba(0,0,0,0.4);
|
||||
}
|
||||
.nickname-item {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
width: 100%;
|
||||
padding: 8px 12px;
|
||||
background: transparent;
|
||||
border: none;
|
||||
border-bottom: 1px solid #334155;
|
||||
color: #cbd5e1;
|
||||
font-size: 0.9rem;
|
||||
cursor: pointer;
|
||||
text-align: left;
|
||||
}
|
||||
.nickname-item:last-child { border-bottom: none; }
|
||||
.nickname-item:hover { background: #0f172a; color: #f1f5f9; }
|
||||
.fid-badge { margin-left: auto; font-size: 0.75rem; color: #475569; }
|
||||
.search-row { display: flex; gap: 10px; }
|
||||
.input {
|
||||
flex: 1;
|
||||
|
||||
Loading…
Reference in New Issue
Block a user