Skip to content
This repository has been archived by the owner on Apr 20, 2023. It is now read-only.

Commit

Permalink
Merge pull request #65 from SrdjanStankov/student-1
Browse files Browse the repository at this point in the history
Added `[Authorize]` attributes to controllers
  • Loading branch information
DaniloNovakovic committed Jun 13, 2020
2 parents 417c532 + 1124f79 commit 341cd61
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions PUSGS_Project/PUSGS_Project/Controllers/AviationController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
using Core.Interfaces.Services;
using Core.ViewModels.Aviation;
using Core.ViewModels.Aviation.Requests;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using System.Collections.Generic;
using System.Linq;
Expand Down Expand Up @@ -44,13 +46,15 @@ public async Task<object> Get(int id)

// POST api/<controller>
[HttpPost]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public Task<long> Post([FromBody]AddOrUpdateAviationCompanyRequestModel model)
{
return _aviationService.AddAviationCompanyAsync(model);
}

// PUT api/<controller>/5
[HttpPut("{id}")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public Task Put(long id, [FromBody]AddOrUpdateAviationCompanyRequestModel model)
{
model.Id = id;
Expand All @@ -59,6 +63,7 @@ public Task Put(long id, [FromBody]AddOrUpdateAviationCompanyRequestModel model)

// DELETE api/<controller>/5
[HttpDelete("{id}")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public Task Delete(long id)
{
return _aviationService.DeleteAviationCompanyAsync(id);
Expand Down
12 changes: 12 additions & 0 deletions PUSGS_Project/PUSGS_Project/Controllers/FlightController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,14 @@
using Core.Interfaces.Services;
using Core.ViewModels.Aviation;
using Core.ViewModels.Aviation.Requests;
using Microsoft.AspNetCore.Authentication.JwtBearer;
using Microsoft.AspNetCore.Authorization;
using Microsoft.AspNetCore.Mvc;
using Microsoft.EntityFrameworkCore.Metadata.Internal;
using Microsoft.Extensions.Options;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Threading.Tasks;

namespace PUSGS_Project.Controllers
Expand All @@ -30,6 +33,7 @@ public FlightController(IFlightService flightService, IEmailService emailService

// DELETE api/<controller>/5
[HttpDelete("{id}")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public Task Delete(long id)
{
return _flightService.RemoveAsync(id);
Expand All @@ -56,12 +60,14 @@ public async Task<object> Get(long id)

// POST api/<controller>
[HttpPost]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public Task<long> Post([FromBody]AddFlightRequestModel model)
{
return _flightService.AddAsync(model);
}

[HttpPut("{id}")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public Task Put(long id, [FromBody] UpdateFlightRequestModel model)
{
return _flightService.UpdateAsync(id, model);
Expand All @@ -78,12 +84,14 @@ public Task AcceptReservation(long id)
}

[HttpDelete("ticket/{id}")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public Task CancelReservation(long id)
{
return _flightService.CancelReservationAsync(id);
}

[HttpPost("ticket")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public async Task<long> MakeReservation([FromBody]FlightTicketModel model)
{
var ticketId = await _flightService.MakeReservationAsync(model);
Expand All @@ -104,6 +112,7 @@ private Task SendTicketSuccessNotificationAsync(string email, FlightTicketModel
}

[HttpPost("ticket-invitation")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public async Task InviteFriends([FromBody]InviteFriendsRequestModel request)
{
var friendTickets = await _flightService.MakeFriendReservations(request.FlightTickets);
Expand All @@ -124,18 +133,21 @@ private Task SendInvitationAsync(FlightTicket ticket)
}

[HttpPost("quick-reservation")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public Task MakeQuickReservation([FromBody]QuickReservationRequestModel model)
{
return _flightService.MakeQuickReservationAsync(model);
}

[HttpDelete("quick-reservation/{id}")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public Task CancelQuickReservation(long id)
{
return _flightService.CancelQuickReservationAsync(id);
}

[HttpPost("rate")]
[Authorize(AuthenticationSchemes = JwtBearerDefaults.AuthenticationScheme)]
public Task RateFlight([FromBody]RateFlightRequestModel model)
{
return _flightService.RateAsync(model);
Expand Down

0 comments on commit 341cd61

Please sign in to comment.