Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
M
meanspec-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Operate
Environments
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
MeanSpec (SCE338 2024-2 Group 1)
meanspec-backend
Commits
613d8e4b
Commit
613d8e4b
authored
6 months ago
by
Lee WooChang
Browse files
Options
Downloads
Patches
Plain Diff
feat: combination 반환 api 추가
parent
34be008f
No related branches found
No related tags found
1 merge request
!11
조합 API 추가
Pipeline
#10662
passed
6 months ago
Stage: test
Changes
3
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
src/repositories/partRepository.js
+30
-0
30 additions, 0 deletions
src/repositories/partRepository.js
src/routes/parts.js
+19
-0
19 additions, 0 deletions
src/routes/parts.js
src/services/partService.js
+32
-0
32 additions, 0 deletions
src/services/partService.js
with
81 additions
and
0 deletions
src/repositories/partRepository.js
+
30
−
0
View file @
613d8e4b
...
...
@@ -57,6 +57,36 @@ const PartRepository = {
const
result
=
await
pool
.
query
(
query
,
queryValues
);
return
result
.
rows
;
},
async
getAllCombinations
()
{
const
query
=
`
SELECT array_agg(r.part_id) AS partIds
FROM combinations c
LEFT JOIN relations r ON c.id = r.combination_id
GROUP BY c.id;
`
;
const
result
=
await
pool
.
query
(
query
);
return
result
.
rows
;
},
async
getFilteredCombinations
(
queryValues
)
{
const
query
=
`
SELECT
c.id AS combination_id,
array_agg(r.part_id) AS partIds
FROM combinations c
LEFT JOIN relations r ON c.id = r.combination_id
WHERE r.combination_id IN (
SELECT DISTINCT combination_id
FROM relations
WHERE part_id = ANY($1::int[])
)
GROUP BY c.id;
`
;
const
result
=
await
pool
.
query
(
query
,
queryValues
);
return
result
.
rows
;
},
};
export
default
PartRepository
;
This diff is collapsed.
Click to expand it.
src/routes/parts.js
+
19
−
0
View file @
613d8e4b
...
...
@@ -33,4 +33,23 @@ partRouter.get(
})
);
partRouter
.
get
(
'
/combination/all
'
,
wrapAsync
(
async
(
req
,
res
)
=>
{
const
allCombinations
=
await
PartService
.
getCombinations
();
res
.
sendResponse
(
''
,
200
,
{
combination
:
allCombinations
});
})
);
partRouter
.
get
(
'
/combination/filtered
'
,
wrapAsync
(
async
(
req
,
res
)
=>
{
const
filters
=
req
.
query
;
const
filteredCombinations
=
await
PartService
.
getFilteredCombinations
(
filters
);
res
.
sendResponse
(
''
,
200
,
{
combination
:
filteredCombinations
});
})
);
export
default
partRouter
;
This diff is collapsed.
Click to expand it.
src/services/partService.js
+
32
−
0
View file @
613d8e4b
...
...
@@ -74,6 +74,38 @@ const PartService = {
);
return
parts
;
},
async
getCombinations
()
{
const
allCombinations
=
await
PartRepository
.
getAllCombinations
();
return
allCombinations
;
},
async
getFilteredCombinations
(
filters
)
{
if
(
typeof
filters
.
partId
===
'
string
'
)
{
filters
.
partId
=
filters
.
partId
.
split
(
'
,
'
).
map
((
id
)
=>
id
.
trim
());
}
if
(
!
filters
||
!
Array
.
isArray
(
filters
.
partId
)
||
filters
.
partId
.
length
===
0
)
{
throw
new
ReportableError
(
400
,
'
유효한 partId 값이 필요합니다.
'
);
}
const
validFilters
=
filters
.
partId
.
filter
((
value
)
=>
value
!=
null
);
if
(
validFilters
.
length
===
0
)
{
throw
new
ReportableError
(
400
,
'
유효한 partId 값이 없습니다.
'
);
}
const
queryValues
=
[
validFilters
];
const
filteredCombinations
=
await
PartRepository
.
getFilteredCombinations
(
queryValues
);
return
filteredCombinations
.
map
((
combination
)
=>
({
partIds
:
combination
.
partids
,
}));
},
};
export
default
PartService
;
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment