Combined all F# code into one project
Less to migrate, less to maintain, and I'll never swap these out as components; might as well get the ease of managing them all in one project.
This commit is contained in:
56
src/MyWebLog.App/Logic/Category.fs
Normal file
56
src/MyWebLog.App/Logic/Category.fs
Normal file
@@ -0,0 +1,56 @@
|
||||
module MyWebLog.Logic.Category
|
||||
|
||||
open MyWebLog.Data
|
||||
open MyWebLog.Entities
|
||||
|
||||
/// Sort categories by their name, with their children sorted below them, including an indent level
|
||||
let sortCategories categories =
|
||||
let rec getChildren (cat : Category) indent =
|
||||
seq {
|
||||
yield cat, indent
|
||||
for child in categories |> List.filter (fun c -> c.ParentId = Some cat.Id) do
|
||||
yield! getChildren child (indent + 1)
|
||||
}
|
||||
categories
|
||||
|> List.filter (fun c -> c.ParentId.IsNone)
|
||||
|> List.map (fun c -> getChildren c 0)
|
||||
|> Seq.collect id
|
||||
|> Seq.toList
|
||||
|
||||
/// Find all categories for a given web log
|
||||
let findAllCategories (data : IMyWebLogData) webLogId =
|
||||
data.AllCategories webLogId
|
||||
|> sortCategories
|
||||
|
||||
/// Try to find a category for a given web log Id and category Id
|
||||
let tryFindCategory (data : IMyWebLogData) webLogId catId = data.CategoryById webLogId catId
|
||||
|
||||
/// Try to find a category by its slug for a given web log
|
||||
let tryFindCategoryBySlug (data : IMyWebLogData) webLogId slug = data.CategoryBySlug webLogId slug
|
||||
|
||||
/// Save a category
|
||||
let saveCategory (data : IMyWebLogData) (cat : Category) =
|
||||
match cat.Id with
|
||||
| "new" -> let newCat = { cat with Id = string <| System.Guid.NewGuid() }
|
||||
data.AddCategory newCat
|
||||
newCat.Id
|
||||
| _ -> data.UpdateCategory cat
|
||||
cat.Id
|
||||
|
||||
/// Remove a category from its parent
|
||||
let removeCategoryFromParent (data : IMyWebLogData) webLogId parentId catId =
|
||||
match tryFindCategory data webLogId parentId with
|
||||
| Some parent -> parent.Children
|
||||
|> List.filter (fun childId -> childId <> catId)
|
||||
|> data.UpdateChildren webLogId parentId
|
||||
| None -> ()
|
||||
|
||||
/// Add a category to a given parent
|
||||
let addCategoryToParent (data : IMyWebLogData) webLogId parentId catId =
|
||||
match tryFindCategory data webLogId parentId with
|
||||
| Some parent -> catId :: parent.Children
|
||||
|> data.UpdateChildren webLogId parentId
|
||||
| None -> ()
|
||||
|
||||
/// Delete a category
|
||||
let deleteCategory (data : IMyWebLogData) cat = data.DeleteCategory cat
|
||||
29
src/MyWebLog.App/Logic/Page.fs
Normal file
29
src/MyWebLog.App/Logic/Page.fs
Normal file
@@ -0,0 +1,29 @@
|
||||
/// Logic for manipulating <see cref="Page" /> entities
|
||||
module MyWebLog.Logic.Page
|
||||
|
||||
open MyWebLog.Data
|
||||
open MyWebLog.Entities
|
||||
|
||||
/// Find a page by its Id and web log Id
|
||||
let tryFindPage (data : IMyWebLogData) webLogId pageId = data.PageById webLogId pageId true
|
||||
|
||||
/// Find a page by its Id and web log Id, without the revision list
|
||||
let tryFindPageWithoutRevisions (data : IMyWebLogData) webLogId pageId = data.PageById webLogId pageId false
|
||||
|
||||
/// Find a page by its permalink
|
||||
let tryFindPageByPermalink (data : IMyWebLogData) webLogId permalink = data.PageByPermalink webLogId permalink
|
||||
|
||||
/// Find a list of all pages (excludes text and revisions)
|
||||
let findAllPages (data : IMyWebLogData) webLogId = data.AllPages webLogId
|
||||
|
||||
/// Save a page
|
||||
let savePage (data : IMyWebLogData) (page : Page) =
|
||||
match page.Id with
|
||||
| "new" -> let newPg = { page with Id = string <| System.Guid.NewGuid () }
|
||||
data.AddPage newPg
|
||||
newPg.Id
|
||||
| _ -> data.UpdatePage page
|
||||
page.Id
|
||||
|
||||
/// Delete a page
|
||||
let deletePage (data : IMyWebLogData) webLogId pageId = data.DeletePage webLogId pageId
|
||||
60
src/MyWebLog.App/Logic/Post.fs
Normal file
60
src/MyWebLog.App/Logic/Post.fs
Normal file
@@ -0,0 +1,60 @@
|
||||
/// Logic for manipulating <see cref="Post" /> entities
|
||||
module MyWebLog.Logic.Post
|
||||
|
||||
open MyWebLog.Data
|
||||
open MyWebLog.Entities
|
||||
|
||||
/// Find a page of published posts
|
||||
let findPageOfPublishedPosts (data : IMyWebLogData) webLogId pageNbr nbrPerPage =
|
||||
data.PageOfPublishedPosts webLogId pageNbr nbrPerPage
|
||||
|
||||
/// Find a pages of published posts in a given category
|
||||
let findPageOfCategorizedPosts (data : IMyWebLogData) webLogId catId pageNbr nbrPerPage =
|
||||
data.PageOfCategorizedPosts webLogId catId pageNbr nbrPerPage
|
||||
|
||||
/// Find a page of published posts tagged with a given tag
|
||||
let findPageOfTaggedPosts (data : IMyWebLogData) webLogId tag pageNbr nbrPerPage =
|
||||
data.PageOfTaggedPosts webLogId tag pageNbr nbrPerPage
|
||||
|
||||
/// Find the next newer published post for the given post
|
||||
let tryFindNewerPost (data : IMyWebLogData) post = data.NewerPost post
|
||||
|
||||
/// Find the next newer published post in a given category for the given post
|
||||
let tryFindNewerCategorizedPost (data : IMyWebLogData) catId post = data.NewerCategorizedPost catId post
|
||||
|
||||
/// Find the next newer published post tagged with a given tag for the given post
|
||||
let tryFindNewerTaggedPost (data : IMyWebLogData) tag post = data.NewerTaggedPost tag post
|
||||
|
||||
/// Find the next older published post for the given post
|
||||
let tryFindOlderPost (data : IMyWebLogData) post = data.OlderPost post
|
||||
|
||||
/// Find the next older published post in a given category for the given post
|
||||
let tryFindOlderCategorizedPost (data : IMyWebLogData) catId post = data.OlderCategorizedPost catId post
|
||||
|
||||
/// Find the next older published post tagged with a given tag for the given post
|
||||
let tryFindOlderTaggedPost (data : IMyWebLogData) tag post = data.OlderTaggedPost tag post
|
||||
|
||||
/// Find a page of all posts for a web log
|
||||
let findPageOfAllPosts (data : IMyWebLogData) webLogId pageNbr nbrPerPage =
|
||||
data.PageOfAllPosts webLogId pageNbr nbrPerPage
|
||||
|
||||
/// Try to find a post by its Id
|
||||
let tryFindPost (data : IMyWebLogData) webLogId postId = data.PostById webLogId postId
|
||||
|
||||
/// Try to find a post by its permalink
|
||||
let tryFindPostByPermalink (data : IMyWebLogData) webLogId permalink = data.PostByPermalink webLogId permalink
|
||||
|
||||
/// Try to find a post by its prior permalink
|
||||
let tryFindPostByPriorPermalink (data : IMyWebLogData) webLogId permalink = data.PostByPriorPermalink webLogId permalink
|
||||
|
||||
/// Find posts for the RSS feed
|
||||
let findFeedPosts (data : IMyWebLogData) webLogId nbrOfPosts = data.FeedPosts webLogId nbrOfPosts
|
||||
|
||||
/// Save a post
|
||||
let savePost (data : IMyWebLogData) (post : Post) =
|
||||
match post.Id with
|
||||
| "new" -> let newPost = { post with Id = string <| System.Guid.NewGuid() }
|
||||
data.AddPost newPost
|
||||
newPost.Id
|
||||
| _ -> data.UpdatePost post
|
||||
post.Id
|
||||
9
src/MyWebLog.App/Logic/User.fs
Normal file
9
src/MyWebLog.App/Logic/User.fs
Normal file
@@ -0,0 +1,9 @@
|
||||
/// Logic for manipulating <see cref="User" /> entities
|
||||
module MyWebLog.Logic.User
|
||||
|
||||
open MyWebLog.Data
|
||||
|
||||
/// Try to log on a user
|
||||
let tryUserLogOn (data : IMyWebLogData) email passwordHash = data.LogOn email passwordHash
|
||||
|
||||
let setUserPassword (data : IMyWebLogData) = data.SetUserPassword
|
||||
11
src/MyWebLog.App/Logic/WebLog.fs
Normal file
11
src/MyWebLog.App/Logic/WebLog.fs
Normal file
@@ -0,0 +1,11 @@
|
||||
/// Logic for manipulating <see cref="WebLog" /> entities
|
||||
module MyWebLog.Logic.WebLog
|
||||
|
||||
open MyWebLog.Data
|
||||
open MyWebLog.Entities
|
||||
|
||||
/// Find a web log by its URL base
|
||||
let tryFindWebLogByUrlBase (data : IMyWebLogData) urlBase = data.WebLogByUrlBase urlBase
|
||||
|
||||
/// Find the counts for the admin dashboard
|
||||
let findDashboardCounts (data : IMyWebLogData) webLogId = data.DashboardCounts webLogId
|
||||
Reference in New Issue
Block a user