-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
11 changed files
with
256 additions
and
300 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,5 +4,4 @@ public class Credentials | |
{ | ||
public string TokenJson { get; set; } | ||
public string CredentialsJson { get; set; } | ||
|
||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,39 +1,33 @@ | ||
using Google.Apis.Calendar.v3.Data; | ||
using GoogleCalendarApi.Common.Model; | ||
using GoogleCalendarApi.Services; | ||
using Microsoft.AspNetCore.Mvc; | ||
namespace GoogleCalendarApi.Controllers; | ||
|
||
namespace GoogleCalendarApi.Controllers | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class GoogleCalendarController : ControllerBase | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class GoogleCalendarController : ControllerBase | ||
{ | ||
private readonly IGoogleCalendarService _service; | ||
private const string MessagePattern = "Event created for the calendar {0}"; | ||
private readonly IGoogleCalendarService _service; | ||
private const string MessagePattern = "Event created for the calendar {0}"; | ||
|
||
public GoogleCalendarController(IGoogleCalendarService service) | ||
{ | ||
_service = service; | ||
} | ||
public GoogleCalendarController(IGoogleCalendarService service) | ||
{ | ||
_service = service; | ||
} | ||
|
||
[HttpPost] | ||
public async Task<string> CreateEvent([FromBody] EventModel model) | ||
{ | ||
var createdEvent = await _service.CreateEventAsync(model); | ||
return string.Format(MessagePattern, createdEvent.Id); | ||
} | ||
[HttpPost] | ||
public async Task<string> CreateEvent([FromBody] EventModel model) | ||
{ | ||
var createdEvent = await _service.CreateEventAsync(model); | ||
return string.Format(MessagePattern, createdEvent.Id); | ||
} | ||
|
||
[HttpGet("Revoke")] | ||
public async Task<bool> Revoke() | ||
{ | ||
return await _service.RevokeTokenAsync(); | ||
} | ||
[HttpGet("Revoke")] | ||
public async Task<bool> Revoke() | ||
{ | ||
return await _service.RevokeTokenAsync(); | ||
} | ||
|
||
[HttpPut("/{eventId}")] | ||
public async Task<Event?> UpdateEvent(string eventId, [FromBody] EventModel eventModel) | ||
{ | ||
return await _service.UpdateEventAsync(eventId, eventModel); | ||
} | ||
[HttpPut("/{eventId}")] | ||
public async Task<Event?> UpdateEvent(string eventId, [FromBody] EventModel eventModel) | ||
{ | ||
return await _service.UpdateEventAsync(eventId, eventModel); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,46 +1,39 @@ | ||
using GoogleCalendarApi.Services; | ||
using GoogleCalendarApi.Settings; | ||
using Microsoft.AspNetCore.Mvc; | ||
using Microsoft.Extensions.Options; | ||
namespace GoogleCalendarApi.Controllers; | ||
|
||
|
||
namespace GoogleCalendarApi.Controllers | ||
[ApiController] | ||
public class OAuthController : ControllerBase | ||
{ | ||
[ApiController] | ||
public class OAuthController : ControllerBase | ||
{ | ||
private readonly IGoogleCalendarService _service; | ||
private readonly IGoogleCalendarService _service; | ||
|
||
public OAuthController(IGoogleCalendarService service) | ||
{ | ||
_service = service; | ||
} | ||
public OAuthController(IGoogleCalendarService service) | ||
{ | ||
_service = service; | ||
} | ||
|
||
[HttpGet] | ||
[Route("oauth/callback")] | ||
public async Task<bool> Callback(string code, string? error, string state) | ||
{ | ||
if (string.IsNullOrWhiteSpace(error)) | ||
return await _service.GetTokenAsync(code); | ||
return false; | ||
} | ||
[HttpGet] | ||
[Route("oauth/callback")] | ||
public async Task<bool> Callback(string code, string? error, string state) | ||
{ | ||
if (string.IsNullOrWhiteSpace(error)) | ||
return await _service.GetTokenAsync(code); | ||
return false; | ||
} | ||
|
||
[HttpPost] | ||
[Route("/refreshToken")] | ||
public async Task<bool> GenerateRefreshToken() | ||
{ | ||
return await _service.RefreshAccessTokenAsync(); | ||
} | ||
[HttpPost] | ||
[Route("/refreshToken")] | ||
public async Task<bool> GenerateRefreshToken() | ||
{ | ||
return await _service.RefreshAccessTokenAsync(); | ||
} | ||
|
||
[HttpGet] | ||
[Route("/oauth/getoauthcode")] | ||
public IActionResult GetOauthCode() | ||
{ | ||
var uri = _service.GetAuthCode(); | ||
if (!String.IsNullOrEmpty(uri)) | ||
return Redirect(uri); | ||
else | ||
return BadRequest("creating Uri redirect was failed!!"); | ||
} | ||
[HttpGet] | ||
[Route("/oauth/getoauthcode")] | ||
public IActionResult GetOauthCode() | ||
{ | ||
var uri = _service.GetAuthCode(); | ||
if (!String.IsNullOrEmpty(uri)) | ||
return Redirect(uri); | ||
else | ||
return BadRequest("creating Uri redirect was failed!!"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
global using Google.Apis.Calendar.v3.Data; | ||
global using GoogleCalendarApi.Common.Model; | ||
global using GoogleCalendarApi.Settings; | ||
global using Newtonsoft.Json.Linq; | ||
global using RestSharp; | ||
global using Newtonsoft.Json; | ||
global using Microsoft.Extensions.Options; | ||
global using Method = GoogleCalendarApi.Common.Method; | ||
global using Google.Apis.Calendar.v3; | ||
global using Google.Apis.Auth.OAuth2; | ||
global using Google.Apis.Auth.OAuth2.Flows; | ||
global using Google.Apis.Auth.OAuth2.Responses; | ||
global using Google.Apis.Services; | ||
global using GoogleCalendarApi.Services; | ||
global using Microsoft.AspNetCore.Mvc; | ||
global using System.Text; | ||
global using NodaTime.TimeZones; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.