First Commit (API Project)

This commit is contained in:
2025-07-17 10:05:47 +09:00
commit ad702d5ccf
371 changed files with 141373 additions and 0 deletions

View File

@@ -0,0 +1,37 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Helpers\ApiResponse;
use App\Models\SiteAdmin;
class AdminApiController extends Controller
{
/* /**
* @OA\Post(
* path="/api/admin/list",
* summary="관리자 리스트",
* tags={"Admin"},
* security={{"ApiKeyAuth":{}}},
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(
* required={"user_token"},
* @OA\Property(property="user_token", type="string", example="XXXXXXX")
* )
* ),
* @OA\Response(response=200, description="성공"),
* @OA\Response(response=401, description="실패")
* )
*/
public function list(Request $request)
{
return ApiResponse::handle(function () use ($request) {
$admins = new SiteAdmin;
return ApiResponse::response('get', $admins, $request->debug);
}, '관리자 목록 조회 성공', '관리자 목록 조회 실패');
}
}

View File

@@ -0,0 +1,144 @@
<?php
namespace App\Http\Controllers\Api;
use App\Models\Member;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Hash;
use Illuminate\Support\Str;
use App\Http\Controllers\Controller;
use App\Models\User;
/**
* @OA\Info(
* version="1.0.0",
* title="SAM API Documentation",
* description="SAM(Semi-Automatics Management) API 입니다.",
* @OA\Contact(
* email="shine1324@gmail.com"
* )
* )
*
* @OA\Server(
* url="https://api.5130.co.kr",
* description="SAM API 서버"
* )
*/
class ApiController extends Controller
{
/**
* @OA\Get(
* path="/api/debug-apikey",
* tags={"API Key 인증"},
* summary="API Key 인증 확인",
* security={{"ApiKeyAuth":{}}},
* @OA\Response(
* response=200,
* description="API Key 인증 성공"
* ),
* @OA\Response(
* response=401,
* description="인증 실패"
* )
* )
*/
public function debugApikey()
{
return response()->json(['message' => 'API Key 인증 성공']);
}
/**
* @OA\Post(
* path="/api/login",
* summary="회원 토큰 정보확인",
* tags={"Auth"},
* @OA\RequestBody(
* required=true,
* @OA\JsonContent(
* required={"USER_ID", "USER_PWD"},
* @OA\Property(property="USER_ID", type="string", example="admin"),
* @OA\Property(property="USER_PWD", type="string", example="1234")
* )
* ),
* @OA\Response(
* response=200,
* description="로그인 성공",
* @OA\JsonContent(
* @OA\Property(property="message", type="string"),
* @OA\Property(property="USER_TOKEN", type="string")
* )
* ),
* @OA\Response(response=401, description="로그인 실패")
* )
*/
public function login(Request $request)
{
$userId = $request->input('user_id');
$userPwd = $request->input('user_pwd');
if (!$userId || !$userPwd) {
return response()->json(['error' => '아이디 또는 비밀번호 누락'], 400);
}
$user = Member::where('mb_id', $userId)->first();
if (!$user) {
return response()->json(['error' => '사용자를 찾을 수 없습니다.'], 404);
}
$isValid = false;
if (Str::startsWith($user->mb_pass, '$2y$')) {
// bcrypt로 해싱된 경우
$isValid = Hash::check($userPwd, $user->mb_pass);
} else {
// sha256으로 해싱된 경우
$isValid = strtoupper(hash('sha256', $userPwd)) === strtoupper($user->mb_pass);
}
if (!$isValid) {
return response()->json(['error' => '아이디 또는 비밀번호가 올바르지 않습니다.'], 401);
}
// 선택: DB에 신규 token 저장
$USER_TOKEN = hash('sha256', $user->mb_id.date('YmdHis'));
$user->remember_token = $USER_TOKEN;
$user->save();
return response()->json([
'message' => '로그인 성공',
'USER_TOKEN' => $user->USER_TOKEN,
]);
}
/**
* @OA\Post(
* path="/api/logout",
* summary="로그아웃 (Access 및 Token 무효화)",
* tags={"Auth"},
* security={{"ApiKeyAuth":{}}},
* @OA\Response(response=200, description="로그아웃 성공"),
* @OA\Response(response=401, description="인증 실패")
* )
*/
public function logout(Request $request)
{
$token = $request->header('X-API-KEY'); // 또는 Authorization 헤더
// 회원 테이블에서 해당 토큰으로 유저 찾기
$user = User::where('remember_token', $token)->first();
if ($user) {
$user->USER_TOKEN = null;
$user->save();
}
return response()->json(['message' => '로그아웃 완료']);
}
}

View File

@@ -0,0 +1,16 @@
<?php
namespace App\Http\Controllers\Api;
use App\Helpers\ApiResponse;
use Illuminate\Support\Facades\DB;
class CommonController
{
public static function getComeCode()
{
$query = DB::table('COM_CODE')
->select(['CODE_TP_ID', 'CODE_ID', 'CODE_VAL', 'CODE_DESC', 'USE_YN']);
return ApiResponse::response('get', $query);
}
}

View File

@@ -0,0 +1,43 @@
<?php
namespace App\Http\Controllers\Api;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Services\FileService;
use App\Helpers\ApiResponse;
class FileController extends Controller
{
// 파일 업로드
public function upload(Request $request)
{
return ApiResponse::handle(function () use ($request) {
return FileService::uploadFiles($request->all());
}, '파일 업로드 성공', '파일 업로드 실패');
}
// 파일 목록 조회
public function list(Request $request)
{
return ApiResponse::handle(function () use ($request) {
return FileService::getFiles($request->all());
}, '파일 목록조회 성공', '파일 목록조회 실패');
}
// 파일 삭제
public function delete(Request $request)
{
return ApiResponse::handle(function () use ($request) {
return FileService::deleteFiles($request->all());
}, '파일 삭제 성공', '파일 삭제 실패');
}
// 파일 정보 조회 (단건)
public function findFile(Request $request)
{
return ApiResponse::handle(function () use ($request) {
return FileService::findFile($request->all());
}, '파일 정보 조회 성공', '파일 정보 조회 실패');
}
}

View File

@@ -0,0 +1,235 @@
<?php
namespace App\Http\Controllers\Api;
use Illuminate\Http\Request;
use App\Http\Controllers\Controller;
use App\Services\MemberService;
use App\Helpers\ApiResponse;
class MemberController extends Controller
{
/**
* @OA\Get(
* path="/api/member/index",
* summary="회원 목록 조회",
* description="회원 목록을 조회합니다.",
* tags={"Member"},
* security={{"ApiKeyAuth":{}}},
*
* @OA\Parameter(
* name="user_token",
* in="query",
* required=true,
* description="회원 인증용 토큰",
* @OA\Schema(type="string", example="abc123token")
* ),
* @OA\Parameter(
* name="type",
* in="query",
* required=false,
* description="조회 타입: 기본(default), 상세(info)",
* @OA\Schema(type="string", enum={"default", "info"}, example="default")
* ),
* @OA\Parameter(
* name="debug",
* in="query",
* required=false,
* description="디버그 모드 여부 (쿼리 로그 포함 여부)",
* @OA\Schema(type="boolean", example=true)
* ),
* @OA\Parameter(
* name="status",
* in="query",
* required=false,
* description="상태 필터링 (01,02,03 사용자만 조회)",
* @OA\Schema(type="boolean", example=true)
* ),
*
* @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="1",
* type="object",
* @OA\Property(property="mb_num", type="integer", example=1),
* @OA\Property(property="tn_num", type="string", example=null),
* @OA\Property(property="mb_id", type="string", example="admin"),
* @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", format="date-time", example=null),
* @OA\Property(property="mb_type", type="string", example=null),
* @OA\Property(property="mb_level", type="integer", example=1),
* @OA\Property(property="last_login", type="string", format="date-time", example=null),
* @OA\Property(property="reg_date", type="string", format="date-time", example="2025-07-16T09:28:41.000000Z"),
* @OA\Property(property="created_at", type="string", format="date-time", example=null),
* @OA\Property(property="updated_at", type="string", format="date-time", example="2025-07-16T09:30:56.000000Z")
* )
* ),
* @OA\Property(
* property="query",
* type="array",
* @OA\Items(type="string", example="select * from `members`")
* )
* )
* ),
*
* @OA\Response(response=401, description="인증 실패"),
* @OA\Response(response=403, description="권한 없음")
* )
*/
public function index(Request $request)
{
try {
$type = $request->input('type', 'default');
$userToken = $request->input('user_token', '');
$debug = $request->boolean('debug', false);
$result = MemberService::getMembers($userToken, $type, $debug);
return ApiResponse::success($result['data'], '회원목록 조회 성공',$result['query']);
} catch (\Throwable $e) {
return ApiResponse::error('회원목록 조회 실패', 500, [
'details' => $e->getMessage(),
]);
}
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
//
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
return ApiResponse::handle(function () use ($request) {
return MemberService::setMember($request->all());
}, '회원등록 성공', '회원등록 실패');
}
/**
* @OA\Get (
* path="/api/member/show/{user_no}",
* summary="회원 상세조회",
* description="user_no 기준으로 회원 상세 정보를 조회합니다.",
* tags={"Member"},
* security={{"ApiKeyAuth":{}}},
*
* @OA\Parameter(
* name="user_no",
* in="path",
* required=true,
* description="회원 번호 (USER_NO)",
* @OA\Schema(type="integer", example=1)
* ),
* @OA\Parameter(
* name="debug",
* in="query",
* required=false,
* description="디버그 모드 여부 (쿼리 확인용)",
* @OA\Schema(type="boolean", example=true)
* ),
*
* @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="mb_num", type="integer", example=1),
* @OA\Property(property="tn_num", type="string", example=null),
* @OA\Property(property="mb_id", type="string", example="admin"),
* @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", format="date-time", example=null),
* @OA\Property(property="mb_type", type="string", example=null),
* @OA\Property(property="mb_level", type="integer", example=1),
* @OA\Property(property="last_login", type="string", format="date-time", example=null),
* @OA\Property(property="reg_date", type="string", format="date-time", example="2025-07-16T09:28:41.000000Z"),
* @OA\Property(property="created_at", type="string", format="date-time", example=null),
* @OA\Property(property="updated_at", type="string", format="date-time", example="2025-07-16T09:30:56.000000Z")
* ),
* @OA\Property(
* property="query",
* type="array",
* @OA\Items(type="string", example="select * from `members` where `mb_num` = 1 limit 1")
* )
* )
* ),
*
* @OA\Response(response=404, description="회원 정보 없음"),
* @OA\Response(response=401, description="인증 실패")
* )
*/
public function show(Request $request, $userNo)
{
try {
$debug = $request->boolean('debug', false);
$result = MemberService::getMember($userNo, $debug);
return ApiResponse::success($result['data'], '회원 상세조회 성공',$result['query']);
} catch (\Throwable $e) {
return ApiResponse::error('회원 상세조회 실패', 500, [
'details' => $e->getMessage(),
]);
}
}
/**
* Show the form for editing the specified resource.
*/
public function edit(string $id)
{
//
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, string $id)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function delAdmin($userNo, Request $request)
{
return ApiResponse::handle(function () use ($userNo, $request) {
return MemberService::delAdmin($userNo);
}, '관리자 제외 성공', '관리자 제외 실패');
}
/**
* 관리자 설정
*/
public function setAdmin($userNo, Request $request)
{
return ApiResponse::handle(function () use ($userNo, $request) {
return MemberService::setAdmin($userNo);
}, '관리자 설정 성공', '관리자 설정 실패');
}
}

View File

@@ -0,0 +1,8 @@
<?php
namespace App\Http\Controllers;
abstract class Controller
{
//
}