Skip to content

Commit

Permalink
Adding global using file
Browse files Browse the repository at this point in the history
  • Loading branch information
Edrisym committed Nov 3, 2024
1 parent 557fa6e commit 3bdbebe
Show file tree
Hide file tree
Showing 11 changed files with 256 additions and 300 deletions.
12 changes: 2 additions & 10 deletions Common/Method.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
using System.Text;
using NodaTime.TimeZones;

namespace GoogleCalendarApi.Common;

public class Method
Expand All @@ -22,25 +19,20 @@ public static string UrlEncodeForGoogle(string url)
}

return result.ToString();

}

public static string WindowsToIana(string windowsTimeZoneId)
{
// Special case for UTC
if (windowsTimeZoneId.Equals("UTC", StringComparison.OrdinalIgnoreCase))
return "Etc/UTC";

// Check if the provided Windows time zone identifier is for Tehran
if (windowsTimeZoneId.Equals("Iran Standard Time", StringComparison.OrdinalIgnoreCase))
return "Asia/Tehran";

// For other Windows time zones, use the Noda Time library to find the mapping
var tzdbSource = TzdbDateTimeZoneSource.Default;
var windowsMapping = tzdbSource.WindowsMapping.PrimaryMapping
.FirstOrDefault(mapping => mapping.Key.Equals(windowsTimeZoneId, StringComparison.OrdinalIgnoreCase));

return windowsMapping.Value; // Return the corresponding IANA time zone identifier, if found
return windowsMapping.Value;
}

}
}
3 changes: 1 addition & 2 deletions Common/Model/Credentials.cs
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,4 @@ public class Credentials
{
public string TokenJson { get; set; }
public string CredentialsJson { get; set; }

}
}
4 changes: 1 addition & 3 deletions Common/Model/EventModel.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,4 @@ public class Attendee
public string AttendeesEmail { get; set; }

Check warning on line 16 in Common/Model/EventModel.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'AttendeesEmail' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string AttendeesName { get; set; }

Check warning on line 17 in Common/Model/EventModel.cs

View workflow job for this annotation

GitHub Actions / build

Non-nullable property 'AttendeesName' must contain a non-null value when exiting constructor. Consider adding the 'required' modifier or declaring the property as nullable.
public string AlocomHangoutLink { get; set; } = "";

}

}
56 changes: 25 additions & 31 deletions Controllers/GoogleCalendarController.cs
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);
}
}
69 changes: 31 additions & 38 deletions Controllers/OAuthController.cs
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!!");
}
}
17 changes: 17 additions & 0 deletions GlobalUsing.cs
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;
4 changes: 0 additions & 4 deletions Program.cs
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
using GoogleCalendarApi.Common.Model;
using GoogleCalendarApi.Services;
using GoogleCalendarApi.Settings;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
Expand Down
Loading

0 comments on commit 3bdbebe

Please sign in to comment.