feat : 내 정보 조회 API 추가

This commit is contained in:
2025-07-22 16:45:11 +09:00
parent 4c2ce55afb
commit 9f1e74159f
5 changed files with 115 additions and 2 deletions

View File

@@ -165,6 +165,77 @@ public function show(Request $request, $userNo)
}
}
/**
* @OA\Get(
* path="/api/v1/me",
* summary="내 정보 조회",
* description="
**[인증 안내]**
이 API는 인증을 위해 `X-API-KEY`와 `Authorization: Bearer {token}` 두 가지 헤더를 모두 함께 보내주셔야 합니다.
- `X-API-KEY`: API 키 (필수)
- `Authorization: Bearer {token}`: 사용자 인증 토큰 (필수)
두 헤더 모두 올바르게 전달되면,
현재 로그인한 회원 및 소속 회사 정보를 반환합니다.
",
* tags={"Member"},
* security={
* {"ApiKeyAuth":{}},
* {"BearerAuth":{}}
* },
* @OA\Response(
* response=200,
* description="성공: 회원/회사 정보 반환",
* @OA\JsonContent(
* type="object",
* @OA\Property(property="success", type="boolean", example=true),
* @OA\Property(property="message", type="string", example="나의 정보 조회 성공"),
* @OA\Property(property="data", type="object",
* @OA\Property(property="member", type="object",
* @OA\Property(property="mb_num", type="integer", example=1),
* @OA\Property(property="tn_num", type="integer", example=1),
* @OA\Property(property="mb_id", type="string", example="hamss"),
* @OA\Property(property="mb_name", type="string", example="권혁성"),
* @OA\Property(property="mb_phone", type="string", example="010-4820-9104"),
* @OA\Property(property="mb_mail", type="string", example="shine1324@gmail.com"),
* @OA\Property(property="email_verified_at", type="string", example=null, nullable=true),
* @OA\Property(property="mb_type", type="string", example=null, nullable=true),
* @OA\Property(property="mb_level", type="integer", example=1),
* @OA\Property(property="last_login", type="string", example=null, nullable=true),
* @OA\Property(property="reg_date", type="string", format="date-time", example="2025-07-16T09:28:41.000000Z"),
* @OA\Property(property="created_at", type="string", example=null, nullable=true),
* @OA\Property(property="updated_at", type="string", format="date-time", example="2025-07-22T07:16:16.000000Z")
* ),
* @OA\Property(property="company", type="object",
* @OA\Property(property="mc_num", type="integer", example=1),
* @OA\Property(property="mc_name", type="string", example="(주)경동기업"),
* @OA\Property(property="mc_code", type="string", example="KDCOM"),
* @OA\Property(property="mc_business_num", type="string", example="1398700333"),
* @OA\Property(property="mc_owner_name", type="string", example="이경호"),
* @OA\Property(property="mc_phone", type="string", example="01083935130"),
* @OA\Property(property="mc_mail", type="string", example="kd5130@naver.com"),
* @OA\Property(property="mc_addr", type="string", example="경기도 김포시 통진읍 옹정로 45-22"),
* @OA\Property(property="use_yn", type="string", example="Y"),
* @OA\Property(property="reg_date", type="string", example="2025-07-08 14:25:16")
* )
* )
* )
* ),
* @OA\Response(
* response=401,
* description="인증 실패 (헤더 누락, 유효하지 않은 토큰/키 등)"
* )
* )
*/
public function me(Request $request)
{
return ApiResponse::handle(function () use ($request) {
return MemberService::getMyInfo($request);
}, '나의 정보 조회 성공', '나의 정보 조회 실패');
}
/**
* Show the form for editing the specified resource.
*/

View File

@@ -11,7 +11,7 @@ class Member extends Authenticatable
{
use HasApiTokens, Notifiable, TwoFactorAuthenticatable;
protected $primaryKey = 'mb_id'; // 기본 키 변경
protected $primaryKey = 'mb_num'; // 기본 키 변경
protected $fillable = [
'mb_id', 'mb_pass', 'mb_name', 'mb_phone', 'mb_mail',
@@ -36,4 +36,10 @@ public function getAuthIdentifierName()
{
return 'mb_id'; // 기본 로그인 필드를 mb_id로 변경
}
public function company()
{
return $this->belongsTo(MemberCompany::class, 'tn_num', 'mc_num');
// members.tn_num = member_company.mc_num
}
}

View File

@@ -0,0 +1,17 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class MemberCompany extends Model
{
protected $table = 'member_company';
protected $primaryKey = 'mc_num'; // 기본 키 변경
public function members()
{
return $this->hasMany(Member::class, 'tn_num', 'mc_num');
// member_company.mc_num = members.tn_num
}
}

View File

@@ -4,6 +4,7 @@
use App\Helpers\ApiResponse;
use App\Models\Member;
use App\Models\MemberCompany;
use Illuminate\Support\Facades\DB;
class MemberService
@@ -12,7 +13,7 @@ class MemberService
/**
* 회원 조회(리스트)
*/
public static function getMembers(string $userToken, string $type = 'default', bool $debug = false, bool $status = false)
public static function getMembers(string $userToken, bool $debug = false)
{
$query = new Member();
@@ -32,6 +33,23 @@ public static function getMember(int $userNo, bool $debug = false)
return ApiResponse::response('first', $query, $debug);
}
/**
* 내정보 확인
*/
public static function getMyInfo($request, bool $debug = false)
{
$member = $request->user();
$company = MemberCompany::where('mc_num',$member->tn_num)->first();
$data=[
'member' => $member,
'company' => $company
];
return ApiResponse::response('result', $data, $debug);
}
/**
* 회원 등록 또는 수정
*/

View File

@@ -34,6 +34,7 @@
// Member API
Route::prefix('member')->group(function () {
Route::get('/me', [MemberController::class, 'me'])->name('member.me'); // 회원 목록 조회
Route::get('/index', [MemberController::class, 'index'])->name('member.index'); // 회원 목록 조회
Route::get('/show/{user_no}', [MemberController::class, 'show'])->name('member.show'); // 회원 상세 조회
Route::post('/store', [MemberController::class, 'store'])->name('member.store')->middleware('permission:AC'); // 회원 저장 (등록/수정)