Skip to content

Commit

Permalink
clean up frontend.
Browse files Browse the repository at this point in the history
  • Loading branch information
ShroomAgent27 committed Mar 22, 2024
1 parent 20c929f commit b60bcee
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
9 changes: 6 additions & 3 deletions Pages/SharedEmailPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
using Microsoft.AspNetCore.Mvc.RazorPages;
using Newtonsoft.Json;
using System.Net.Http.Headers;
using System.Net.Http.Json;
using System.Text;

namespace weather_consumer.Pages;
Expand All @@ -14,7 +15,6 @@ public abstract class SharedEmailPage : PageModel

public SharedEmailPage(ILogger logger)
{
httpClient.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
_logger = logger;
}

Expand All @@ -32,11 +32,14 @@ public Task<bool> RemoveEmail(Email email)
private async Task<bool> WriteEmail(Email email, bool isSubbing)
{
string json = JsonConvert.SerializeObject(email);
var data = new StringContent(json, Encoding.UTF8, "application/json");
StringContent data = new StringContent(json, Encoding.UTF8, "application/json");

string URL = isSubbing ? Program.WEATHER_BACKEND_PROVIDER + "emails/add/" : Program.WEATHER_BACKEND_PROVIDER + "emails/remove/";

using (HttpResponseMessage response = await httpClient.PutAsync(URL, data))
HttpRequestMessage request = new HttpRequestMessage(HttpMethod.Put, URL);
request.Content = data;

using (HttpResponseMessage response = await httpClient.SendAsync(request))
{
var statusCode = response.StatusCode;
if ((int)statusCode != 200)
Expand Down
13 changes: 7 additions & 6 deletions Pages/Subscribe.cshtml.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,20 @@ public SubscribeModel(ILogger<SubscribeModel> logger) : base(logger)
{
}

public async void OnPost(string email, int zipcode)
public void OnPost(string email, int zipcode)
{
success = false;
if (email is null) {
_logger.LogInformation("Email is null.");
if (email is null)
{
return;
}
if(zipcode <= 0) {
_logger.LogInformation("Zipcode is 0 or negative.");
if (zipcode <= 0)
{
return;
}
this.email = email;
this.zipcode = zipcode;
success = await SaveEmail(new Email(email, zipcode));
success = SaveEmail(new Email(email, zipcode)).Result;
}

}

0 comments on commit b60bcee

Please sign in to comment.