Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
D
DojoBackendAPI
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
External wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Package registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Dojo Project (HES-SO)
Projects
Backend
DojoBackendAPI
Commits
1192955b
Commit
1192955b
authored
1 year ago
by
michael.minelli
Browse files
Options
Downloads
Patches
Plain Diff
ExerciceRoutes => Add route to get exerciceEnonce with immutable files
parent
c123ad9e
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
ExpressAPI/src/routes/ExerciceRoutes.ts
+43
-0
43 additions, 0 deletions
ExpressAPI/src/routes/ExerciceRoutes.ts
with
43 additions
and
0 deletions
ExpressAPI/src/routes/ExerciceRoutes.ts
+
43
−
0
View file @
1192955b
...
@@ -20,6 +20,11 @@ import { Prisma } from '@prisma/client';
...
@@ -20,6 +20,11 @@ import { Prisma } from '@prisma/client';
import
{
Enonce
,
Exercice
}
from
'
../types/DatabaseTypes
'
;
import
{
Enonce
,
Exercice
}
from
'
../types/DatabaseTypes
'
;
import
db
from
'
../helpers/DatabaseHelper
'
;
import
db
from
'
../helpers/DatabaseHelper
'
;
import
SecurityCheckType
from
'
../types/SecurityCheckType
'
;
import
SecurityCheckType
from
'
../types/SecurityCheckType
'
;
import
GitlabTreeFile
from
'
../shared/types/Gitlab/GitlabTreeFile
'
;
import
GitlabFile
from
'
../shared/types/Gitlab/GitlabFile
'
;
import
YAML
from
'
yaml
'
;
import
EnonceFile
from
'
../shared/types/Dojo/EnonceFile
'
;
import
GitlabTreeFileType
from
'
../shared/types/Gitlab/GitlabTreeFileType
'
;
class
ExerciceRoutes
implements
RoutesManager
{
class
ExerciceRoutes
implements
RoutesManager
{
...
@@ -33,6 +38,8 @@ class ExerciceRoutes implements RoutesManager {
...
@@ -33,6 +38,8 @@ class ExerciceRoutes implements RoutesManager {
registerOnBackend
(
backend
:
Express
)
{
registerOnBackend
(
backend
:
Express
)
{
backend
.
post
(
'
/enonces/:enonceNameOrUrl/exercices
'
,
SecurityMiddleware
.
check
(
true
,
SecurityCheckType
.
ENONCE_IS_PUBLISHED
),
ParamsValidatorMiddleware
.
validate
(
this
.
exerciceValidator
),
this
.
createExercice
.
bind
(
this
));
backend
.
post
(
'
/enonces/:enonceNameOrUrl/exercices
'
,
SecurityMiddleware
.
check
(
true
,
SecurityCheckType
.
ENONCE_IS_PUBLISHED
),
ParamsValidatorMiddleware
.
validate
(
this
.
exerciceValidator
),
this
.
createExercice
.
bind
(
this
));
backend
.
get
(
'
/exercices/:exerciceId/enonce
'
,
SecurityMiddleware
.
check
(
false
,
SecurityCheckType
.
EXERCICE_SECRET
),
this
.
getEnonce
.
bind
(
this
));
}
}
private
getExerciceName
(
enonce
:
Enonce
,
members
:
Array
<
GitlabUser
>
,
suffix
:
number
):
string
{
private
getExerciceName
(
enonce
:
Enonce
,
members
:
Array
<
GitlabUser
>
,
suffix
:
number
):
string
{
...
@@ -127,6 +134,42 @@ class ExerciceRoutes implements RoutesManager {
...
@@ -127,6 +134,42 @@ class ExerciceRoutes implements RoutesManager {
return
res
.
status
(
StatusCodes
.
INTERNAL_SERVER_ERROR
).
send
();
return
res
.
status
(
StatusCodes
.
INTERNAL_SERVER_ERROR
).
send
();
}
}
}
}
private
async
getEnonce
(
req
:
ApiRequest
,
res
:
express
.
Response
)
{
const
repoTree
:
Array
<
GitlabTreeFile
>
=
await
GitlabManager
.
getRepositoryTree
(
req
.
boundParams
.
exercice
.
gitlabId
);
let
enonceYamlFile
:
GitlabFile
;
let
immutableFiles
:
Array
<
GitlabFile
>
=
await
Promise
.
all
(
Config
.
enonce
.
baseFiles
.
map
(
async
(
baseFile
:
string
)
=>
{
let
file
=
await
GitlabManager
.
getFile
(
req
.
boundParams
.
exercice
.
gitlabId
,
baseFile
);
if
(
baseFile
===
Config
.
enonce
.
filename
)
{
enonceYamlFile
=
file
;
}
return
file
;
}));
const
dojoEnonceFile
:
EnonceFile
=
YAML
.
parse
(
atob
(
enonceYamlFile
.
content
));
const
immutablePaths
=
dojoEnonceFile
.
immutable
.
map
(
fileDescriptor
=>
fileDescriptor
.
path
);
await
Promise
.
all
(
repoTree
.
map
(
async
gitlabTreeFile
=>
{
if
(
gitlabTreeFile
.
type
==
GitlabTreeFileType
.
BLOB
)
{
for
(
const
immutablePath
of
immutablePaths
)
{
if
(
gitlabTreeFile
.
path
.
startsWith
(
immutablePath
)
)
{
immutableFiles
.
push
(
await
GitlabManager
.
getFile
(
req
.
boundParams
.
exercice
.
gitlabId
,
gitlabTreeFile
.
path
));
break
;
}
}
}
}));
return
req
.
session
.
sendResponse
(
res
,
StatusCodes
.
OK
,
{
enonce
:
(
req
.
boundParams
.
exercice
as
Exercice
).
enonce
,
enonceFile
:
dojoEnonceFile
,
immutable
:
immutableFiles
});
}
}
}
...
...
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