Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
B
BookingMyHrManagement
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Registry
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Chanachai
BookingMyHrManagement
Commits
73acfaa5
Commit
73acfaa5
authored
Mar 18, 2025
by
Ooh-Ao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
ยืม
parent
fafe75a4
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
69 additions
and
2 deletions
+69
-2
launch.json
.vscode/launch.json
+20
-0
borrow_controller.cpython-312.pyc
...controllers/__pycache__/borrow_controller.cpython-312.pyc
+0
-0
borrow_controller.py
API-Fast/src/controllers/borrow_controller.py
+31
-0
borrow_routes.cpython-312.pyc
...Fast/src/routes/__pycache__/borrow_routes.cpython-312.pyc
+0
-0
borrow_routes.py
API-Fast/src/routes/borrow_routes.py
+18
-2
No files found.
.vscode/launch.json
0 → 100644
View file @
73acfaa5
{
//
Use
IntelliSense
to
learn
about
possible
attributes.
//
Hover
to
view
descriptions
of
existing
attributes.
//
For
more
information
,
visit
:
https
:
//go.microsoft.com/fwlink/?linkid=
830387
"version"
:
"0.2.0"
,
"configurations"
:
[
{
"name"
:
"Python Debugger: FastAPI"
,
"type"
:
"debugpy"
,
"request"
:
"launch"
,
"module"
:
"uvicorn"
,
"args"
:
[
"main:app"
,
"--reload"
],
"jinja"
:
true
}
]
}
\ No newline at end of file
API-Fast/src/controllers/__pycache__/borrow_controller.cpython-312.pyc
View file @
73acfaa5
No preview for this file type
API-Fast/src/controllers/borrow_controller.py
View file @
73acfaa5
# myproject/controllers/borrow_controller.py
from
typing
import
List
,
Optional
from
uuid
import
UUID
from
datetime
import
datetime
from
fastapi
import
HTTPException
...
...
@@ -174,3 +175,32 @@ async def delete_borrow_transaction(db: AsyncSession, borrow_id: UUID):
raise
HTTPException
(
status_code
=
400
,
detail
=
str
(
e
.
orig
))
return
{
"message"
:
"BorrowTransaction deleted"
}
# NEW API: Search BorrowTransactions by query parameters
async
def
search_borrow_transactions
(
db
:
AsyncSession
,
member_id
:
Optional
[
UUID
]
=
None
,
peId
:
Optional
[
UUID
]
=
None
,
status
:
Optional
[
str
]
=
None
,
date_from
:
Optional
[
datetime
]
=
None
,
date_to
:
Optional
[
datetime
]
=
None
)
->
List
[
BorrowTransaction
]:
"""
ค้นหา BorrowTransaction โดยสามารถกรองตาม:
- member_id: รหัสสมาชิกที่เบิกอุปกรณ์
- status: สถานะของการเบิก (requested, approved, returned, rejected, etc.)
- date_from และ date_to: ช่วงวันของ created_at
"""
query
=
select
(
BorrowTransaction
)
if
member_id
:
query
=
query
.
where
(
BorrowTransaction
.
memberId
==
member_id
)
if
peId
:
query
=
query
.
where
(
BorrowTransaction
.
peId
==
peId
)
if
status
:
query
=
query
.
where
(
BorrowTransaction
.
status
==
status
)
if
date_from
:
query
=
query
.
where
(
BorrowTransaction
.
created_at
>=
date_from
)
if
date_to
:
query
=
query
.
where
(
BorrowTransaction
.
created_at
<=
date_to
)
result
=
await
db
.
execute
(
query
)
return
result
.
scalars
()
.
all
()
\ No newline at end of file
API-Fast/src/routes/__pycache__/borrow_routes.cpython-312.pyc
View file @
73acfaa5
No preview for this file type
API-Fast/src/routes/borrow_routes.py
View file @
73acfaa5
# myproject/routes/borrow_routes.py
from
datetime
import
datetime
from
fastapi
import
APIRouter
,
Depends
,
HTTPException
,
status
from
typing
import
List
from
typing
import
List
,
Optional
from
uuid
import
UUID
from
sqlalchemy.ext.asyncio
import
AsyncSession
...
...
@@ -11,7 +12,8 @@ from ..controllers.borrow_controller import (
update_borrow_transaction
,
get_all_borrow_transactions
,
get_borrow_transaction_by_id
,
delete_borrow_transaction
delete_borrow_transaction
,
search_borrow_transactions
)
from
..schemas.borrow_schema
import
(
BorrowTransactionBase
,
...
...
@@ -62,3 +64,16 @@ async def delete_borrow_endpoint(
db
:
AsyncSession
=
Depends
(
get_db
)
):
return
await
delete_borrow_transaction
(
db
,
borrowId
)
# NEW API: Search BorrowTransactions by query parameters
@router.get
(
"/search/borrow"
,
response_model
=
List
[
BorrowTransactionResponse
])
async
def
search_borrow_endpoint
(
member_id
:
Optional
[
UUID
]
=
None
,
peId
:
Optional
[
UUID
]
=
None
,
status
:
Optional
[
str
]
=
None
,
date_from
:
Optional
[
datetime
]
=
None
,
date_to
:
Optional
[
datetime
]
=
None
,
db
:
AsyncSession
=
Depends
(
get_db
)
):
results
=
await
search_borrow_transactions
(
db
,
member_id
,
peId
,
status
,
date_from
,
date_to
)
return
results
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment