Skip to content

Commit

Permalink
move to file scoped namespaces
Browse files Browse the repository at this point in the history
  • Loading branch information
mythz committed Jan 16, 2024
1 parent f8c38a5 commit 71d6513
Show file tree
Hide file tree
Showing 57 changed files with 6,444 additions and 6,519 deletions.
137 changes: 68 additions & 69 deletions TechStacks.ServiceInterface/Admin/AdminServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -6,119 +6,118 @@
using TechStacks.ServiceModel;
using TechStacks.ServiceModel.Types;

namespace TechStacks.ServiceInterface.Admin
namespace TechStacks.ServiceInterface.Admin;

[ExcludeMetadata]
[Route("/tasks/daily")]
public class DailyTasks : IReturn<DailyTasksResponse> {}

public class DailyTasksResponse
{
[ExcludeMetadata]
[Route("/tasks/daily")]
public class DailyTasks : IReturn<DailyTasksResponse> {}
public int TechStackFavCountRowsUpdated { get; set; }
public int TechnologyFavCountRowsUpdated { get; set; }
public int TechStackViewCountRowsUpdated { get; set; }
public int TechnologyViewCountRowsUpdated { get; set; }

public int UserTechStackCountRowsUpdated { get; set; }
public int UserTechnologyCountRowsUpdated { get; set; }
public int UserCommentCountRowsUpdated { get; set; }
public int UserUpVotesRowsUpdated { get; set; }
public int UserDownVotesRowsUpdated { get; set; }
public int UserReportCountRowsUpdated { get; set; }
}

public class DailyTasksResponse
[Authenticate]
[RequiredRole("Admin")]
public class AdminServices : Service
{
public object Put(LogoUrlApproval request)
{
public int TechStackFavCountRowsUpdated { get; set; }
public int TechnologyFavCountRowsUpdated { get; set; }
public int TechStackViewCountRowsUpdated { get; set; }
public int TechnologyViewCountRowsUpdated { get; set; }

public int UserTechStackCountRowsUpdated { get; set; }
public int UserTechnologyCountRowsUpdated { get; set; }
public int UserCommentCountRowsUpdated { get; set; }
public int UserUpVotesRowsUpdated { get; set; }
public int UserDownVotesRowsUpdated { get; set; }
public int UserReportCountRowsUpdated { get; set; }
var tech = Db.SingleById<Technology>(request.TechnologyId);
if (tech == null)
{
throw HttpError.NotFound("Technology not found");
}
tech.LogoApproved = request.Approved;
Db.Save(tech);
return new LogoUrlApprovalResponse
{
Result = tech
};
}

[Authenticate]
[RequiredRole("Admin")]
public class AdminServices : Service
public object Put(LockTechStack request)
{
public object Put(LogoUrlApproval request)
var techStack = Db.SingleById<TechnologyStack>(request.TechnologyStackId);
if (techStack == null)
{
var tech = Db.SingleById<Technology>(request.TechnologyId);
if (tech == null)
{
throw HttpError.NotFound("Technology not found");
}
tech.LogoApproved = request.Approved;
Db.Save(tech);
return new LogoUrlApprovalResponse
{
Result = tech
};
throw HttpError.NotFound("TechnologyStack not found");
}

public object Put(LockTechStack request)
{
var techStack = Db.SingleById<TechnologyStack>(request.TechnologyStackId);
if (techStack == null)
{
throw HttpError.NotFound("TechnologyStack not found");
}

techStack.IsLocked = request.IsLocked;
Db.Save(techStack);
return new LockStackResponse();
}
techStack.IsLocked = request.IsLocked;
Db.Save(techStack);
return new LockStackResponse();
}

public object Put(LockTech request)
public object Put(LockTech request)
{
var tech = Db.SingleById<Technology>(request.TechnologyId);
if (tech == null)
{
var tech = Db.SingleById<Technology>(request.TechnologyId);
if (tech == null)
{
throw HttpError.NotFound("Technology not found");
}

tech.IsLocked = request.IsLocked;
Db.Save(tech);
return new LockTechResponse();
throw HttpError.NotFound("Technology not found");
}

public object Any(DailyTasks request)
tech.IsLocked = request.IsLocked;
Db.Save(tech);
return new LockTechResponse();
}

public object Any(DailyTasks request)
{
return new DailyTasksResponse
{
return new DailyTasksResponse
{
TechStackFavCountRowsUpdated = Db.ExecuteSql(@"UPDATE technology_stack SET fav_count=fav.count
TechStackFavCountRowsUpdated = Db.ExecuteSql(@"UPDATE technology_stack SET fav_count=fav.count
FROM (SELECT technology_stack_id, Count(*) AS Count FROM user_favorite_technology_stack GROUP BY technology_stack_id) as fav
WHERE id = fav.technology_stack_id"),

TechnologyFavCountRowsUpdated = Db.ExecuteSql(@"UPDATE technology SET fav_count=fav.count
TechnologyFavCountRowsUpdated = Db.ExecuteSql(@"UPDATE technology SET fav_count=fav.count
FROM (SELECT technology_id, Count(*) AS Count FROM user_favorite_technology GROUP BY technology_id) as fav
WHERE id = fav.technology_id"),

TechStackViewCountRowsUpdated = Db.ExecuteSql(@"UPDATE technology_stack SET view_count=v.view_count
TechStackViewCountRowsUpdated = Db.ExecuteSql(@"UPDATE technology_stack SET view_count=v.view_count
FROM (SELECT ref_slug, view_count FROM page_stats WHERE ref_type='stack') AS v
WHERE v.ref_slug = slug"),

TechnologyViewCountRowsUpdated = Db.ExecuteSql(@"UPDATE technology SET view_count=v.view_count
TechnologyViewCountRowsUpdated = Db.ExecuteSql(@"UPDATE technology SET view_count=v.view_count
FROM (SELECT ref_slug, view_count FROM page_stats WHERE ref_type='tech') AS v
WHERE v.ref_slug = slug"),

UserTechStackCountRowsUpdated = Db.ExecuteSql(@"UPDATE user_activity SET tech_stacks_count=t.total
UserTechStackCountRowsUpdated = Db.ExecuteSql(@"UPDATE user_activity SET tech_stacks_count=t.total
FROM (SELECT owner_id, COUNT(*) as total FROM technology_stack GROUP BY owner_id) AS t
WHERE t.owner_id::int = id"),

UserTechnologyCountRowsUpdated = Db.ExecuteSql(@"UPDATE user_activity SET technology_count=t.total
UserTechnologyCountRowsUpdated = Db.ExecuteSql(@"UPDATE user_activity SET technology_count=t.total
FROM (SELECT owner_id, COUNT(*) as total FROM technology GROUP BY owner_id) AS t
WHERE t.owner_id::int = id"),

UserCommentCountRowsUpdated = Db.ExecuteSql(@"UPDATE user_activity SET comments_count=t.total
UserCommentCountRowsUpdated = Db.ExecuteSql(@"UPDATE user_activity SET comments_count=t.total
FROM (SELECT user_id, COUNT(*) as total FROM post_comment GROUP BY user_id) AS t
WHERE t.user_id = id"),

UserUpVotesRowsUpdated = Db.ExecuteSql(@"UPDATE user_activity SET up_votes=t.total
UserUpVotesRowsUpdated = Db.ExecuteSql(@"UPDATE user_activity SET up_votes=t.total
FROM (SELECT user_id, SUM(up_votes) as total FROM post GROUP BY user_id) AS t
WHERE t.user_id = id"),

UserDownVotesRowsUpdated = Db.ExecuteSql(@"UPDATE user_activity SET down_votes=t.total
UserDownVotesRowsUpdated = Db.ExecuteSql(@"UPDATE user_activity SET down_votes=t.total
FROM (SELECT user_id, SUM(down_votes) as total FROM post GROUP BY user_id) AS t
WHERE t.user_id = id"),

UserReportCountRowsUpdated = Db.ExecuteSql(@"UPDATE user_activity SET report_count=t.report_count
UserReportCountRowsUpdated = Db.ExecuteSql(@"UPDATE user_activity SET report_count=t.report_count
FROM (SELECT id as user_id,
(select count(*) from post_report where user_id = c.id) +
(select count(*) from post_comment where user_id = c.id and report_user_ids != null) as report_count
FROM custom_user_auth c) t
WHERE t.user_id = id")
};
}
};
}
}
}
17 changes: 8 additions & 9 deletions TechStacks.ServiceInterface/Admin/DummyTypesService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,14 @@
using ServiceStack;
using TechStacks.ServiceModel.Types;

namespace TechStacks.ServiceInterface.Admin
namespace TechStacks.ServiceInterface.Admin;

public class DummyTypes
{
public class DummyTypes
{
public List<Post> Post { get; set; }
}
public List<Post> Post { get; set; }
}

public class DummyTypesService : Service
{
public object Any(DummyTypes request) => request;
}
public class DummyTypesService : Service
{
public object Any(DummyTypes request) => request;
}
109 changes: 54 additions & 55 deletions TechStacks.ServiceInterface/Admin/EmailServices.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,70 +7,69 @@
using TechStacks.ServiceInterface.Notifications;
using TechStacks.ServiceModel.Types;

namespace TechStacks.ServiceInterface.Admin
namespace TechStacks.ServiceInterface.Admin;

[Route("/email/post/{PostId}")]
public class EmailTest : IReturn<EmailTestRespoonse>
{
[Route("/email/post/{PostId}")]
public class EmailTest : IReturn<EmailTestRespoonse>
{
public int? PostId { get; set; }
}
public int? PostId { get; set; }
}

public class EmailTestRespoonse
{
public ResponseStatus ResponseStatus { get; set; }
}
public class EmailTestRespoonse
{
public ResponseStatus ResponseStatus { get; set; }
}

[Authenticate]
[RequiredRole("Admin")]
public class EmailServices : Service
{
public EmailProvider Email { get; set; }
[Authenticate]
[RequiredRole("Admin")]
public class EmailServices : Service
{
public EmailProvider Email { get; set; }

public IAppSettings AppSettings { get; set; }
public IAppSettings AppSettings { get; set; }

public async Task<EmailTestRespoonse> Any(EmailTest request)
{
if (request.PostId == null)
throw new ArgumentNullException(nameof(request.PostId));
public async Task<EmailTestRespoonse> Any(EmailTest request)
{
if (request.PostId == null)
throw new ArgumentNullException(nameof(request.PostId));

var post = Db.SingleById<Post>(request.PostId);
var org = Db.SingleById<Organization>(post.OrganizationId);
var post = Db.SingleById<Post>(request.PostId);
var org = Db.SingleById<Organization>(post.OrganizationId);

var context = new ScriptContext {
VirtualFiles = base.VirtualFiles,
}.Init();
var context = new ScriptContext {
VirtualFiles = base.VirtualFiles,
}.Init();

var page = context.GetPage("emails/post-new");
var result = new PageResult(page) {
Args = {
["baseUrl"] = AppSettings.GetString("PublicBaseUrl"),
["post"] = post,
["organization"] = org,
}
};
var html = await result.RenderToStringAsync();
var page = context.GetPage("emails/post-new");
var result = new PageResult(page) {
Args = {
["baseUrl"] = AppSettings.GetString("PublicBaseUrl"),
["post"] = post,
["organization"] = org,
}
};
var html = await result.RenderToStringAsync();

var user = Db.SingleById<CustomUserAuth>(post.UserId);
var user = Db.SingleById<CustomUserAuth>(post.UserId);

Email.Send(new EmailMessage {
To = new MailTo {
Email = AppSettings.GetString("NotificationsFromEmail"),
Name = "Demis"
},
From = new MailTo {
Email = AppSettings.GetString("NotificationsFromEmail"),
Name = user.DisplayName ?? user.UserName
},
Cc = new MailTo {
Email = AppSettings.GetString("NotificationsCcEmail"),
Name = org.Name + " Subscribed"
},
Subject = $"[{post.Type}] {post.Title}",
BodyHtml = html,
});
Email.Send(new EmailMessage {
To = new MailTo {
Email = AppSettings.GetString("NotificationsFromEmail"),
Name = "Demis"
},
From = new MailTo {
Email = AppSettings.GetString("NotificationsFromEmail"),
Name = user.DisplayName ?? user.UserName
},
Cc = new MailTo {
Email = AppSettings.GetString("NotificationsCcEmail"),
Name = org.Name + " Subscribed"
},
Subject = $"[{post.Type}] {post.Title}",
BodyHtml = html,
});

return new EmailTestRespoonse();
}

return new EmailTestRespoonse();
}
}

}
Loading

0 comments on commit 71d6513

Please sign in to comment.