Skip to content

Commit

Permalink
Merge branch 'main' of github.com:NitroDevs/FShopOnWeb
Browse files Browse the repository at this point in the history
  • Loading branch information
seangwright committed Nov 7, 2022
2 parents c1af249 + 8a9c598 commit 7b57fa7
Show file tree
Hide file tree
Showing 2 changed files with 22 additions and 7 deletions.
3 changes: 0 additions & 3 deletions src/Microsoft.eShopWeb.Web/Basket/Basket.Domain.fs
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,3 @@ module BasketDomain =
i)

{ basket with Items = items }

// TODO:
// let getCatalogItemById =
26 changes: 22 additions & 4 deletions src/Microsoft.eShopWeb.Web/Basket/Basket.Page.fs
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ open Microsoft.eShopWeb.Web
open System.Linq

module BasketPage =

module private Template =

let metadata: PublicLayout.HeadMetadata = { Title = "Basket"; Description = "" }
Expand All @@ -19,11 +20,28 @@ module BasketPage =

let page basket = PublicLayout.layout head (body basket)

let private getIdFromForm (form: FormCollectionReader) =
form.TryGetString "id" |> Option.map int

let handler: HttpHandler =
Services.inject<ShopContext> (fun context ->
let dbItems = context.CatalogItems.ToList()
Request.mapForm
(fun form ->
let dbItems = context.CatalogItems.ToList()

let items = List.ofSeq (dbItems)
let basket = BasketDomain.basketFromCatalog List.empty

let id = getIdFromForm form

let basketToRender =
match id with
| None -> basket
| Some id ->
let catalogItem = items[id]

let items = List.ofSeq (dbItems)
let basket = BasketDomain.basketFromCatalog items
let updatedBasket = BasketDomain.addItemToBasket basket catalogItem
updatedBasket

Response.ofHtml (Template.page basket))
Template.page basketToRender)
Response.ofHtml)

0 comments on commit 7b57fa7

Please sign in to comment.