Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
T
tsi1-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
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
Rodrigo Sastre Marotta
tsi1-backend
Merge requests
!26
Develop
Code
Review changes
Check out branch
Download
Patches
Plain diff
Merged
Develop
develop
into
master
Overview
0
Commits
44
Pipelines
1
Changes
111
Merged
Lucca Santangelo Dodera
requested to merge
develop
into
master
4 years ago
Overview
0
Commits
44
Pipelines
1
Changes
111
Expand
0
0
Merge request reports
Compare
master
master (base)
and
latest version
latest version
2b5140a7
44 commits,
4 years ago
111 files
+
9622
−
242
Inline
Compare changes
Side-by-side
Inline
Show whitespace changes
Show one file at a time
Files
111
Search (e.g. *.vue) (Ctrl+P)
Tsi1.Api/Tsi1.Api/Controllers/CommunicationController.cs
0 → 100644
+
99
−
0
Options
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Security.Claims
;
using
System.Threading.Tasks
;
using
Microsoft.AspNetCore.Authorization
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.AspNetCore.Mvc
;
using
Tsi1.BusinessLayer.Dtos
;
using
Tsi1.BusinessLayer.Helpers
;
using
Tsi1.BusinessLayer.Interfaces
;
namespace
Tsi1.Api.Controllers
{
[
Route
(
"api/[controller]"
)]
[
ApiController
]
public
class
CommunicationController
:
ControllerBase
{
private
readonly
ICommunicationService
_communicationService
;
public
CommunicationController
(
ICommunicationService
communicationService
)
{
_communicationService
=
communicationService
;
}
[
Authorize
(
Roles
=
UserTypes
.
FacultyAdmin
+
", "
+
UserTypes
.
UdelarAdmin
)]
[
HttpPost
(
"CreateCourseCommunication/{courseId}"
)]
public
async
Task
<
IActionResult
>
CreateCourseCommunication
(
CommunicationCreateDto
newCommunication
,
int
courseId
)
{
var
tenantId
=
int
.
Parse
(
HttpContext
.
User
.
Claims
.
FirstOrDefault
(
x
=>
x
.
Type
==
"TenantId"
).
Value
);
var
validationResult
=
await
_communicationService
.
TenantValidation
(
tenantId
,
courseId
);
if
(
validationResult
.
HasError
)
{
return
BadRequest
(
validationResult
.
Message
);
}
var
result
=
await
_communicationService
.
Create
(
newCommunication
,
courseId
);
if
(
result
.
HasError
)
{
return
BadRequest
(
result
.
Message
);
}
return
Ok
();
}
[
Authorize
(
Roles
=
UserTypes
.
FacultyAdmin
+
", "
+
UserTypes
.
UdelarAdmin
)]
[
HttpPost
(
"CreateTenantCommunication"
)]
public
async
Task
<
IActionResult
>
CreateTenantCommunication
(
CommunicationCreateDto
newCommunication
,
int
tenantId
)
{
var
userType
=
HttpContext
.
User
.
Claims
.
FirstOrDefault
(
x
=>
x
.
Type
==
ClaimTypes
.
Role
).
Value
;
if
(
userType
==
UserTypes
.
FacultyAdmin
)
{
tenantId
=
int
.
Parse
(
HttpContext
.
User
.
Claims
.
FirstOrDefault
(
x
=>
x
.
Type
==
"TenantId"
).
Value
);
}
newCommunication
.
IsGlobal
=
true
;
var
result
=
await
_communicationService
.
Create
(
newCommunication
,
tenantId
);
if
(
result
.
HasError
)
{
return
BadRequest
(
result
.
Message
);
}
return
Ok
();
}
[
Authorize
(
Roles
=
UserTypes
.
Student
)]
[
HttpGet
(
"GetMyCommunications"
)]
public
async
Task
<
IActionResult
>
GetMyCommunications
()
{
var
userId
=
int
.
Parse
(
HttpContext
.
User
.
Claims
.
FirstOrDefault
(
x
=>
x
.
Type
==
"Id"
).
Value
);
var
result
=
await
_communicationService
.
GetMyCommunications
(
userId
);
if
(
result
.
HasError
)
{
return
BadRequest
(
result
.
Message
);
}
return
Ok
(
result
.
Data
);
}
[
Authorize
(
Roles
=
UserTypes
.
FacultyAdmin
+
", "
+
UserTypes
.
UdelarAdmin
)]
[
HttpDelete
(
"Delete/{communicationId}"
)]
public
async
Task
<
IActionResult
>
Delete
(
int
communicationId
)
{
var
result
=
await
_communicationService
.
Delete
(
communicationId
);
if
(
result
.
HasError
)
{
return
BadRequest
(
result
.
Message
);
}
return
Ok
();
}
}
}
Loading