From 92fb9f4f5b7bed769b5716902fd389f0730caf52 Mon Sep 17 00:00:00 2001 From: Puqns67 Date: Tue, 19 Sep 2023 01:21:49 +0800 Subject: [PATCH] update sources Signed-off-by: Puqns67 --- .../action/{Account.kt => AccountAction.kt} | 2 +- .../action/{Cart.kt => CartAction.kt} | 6 +- .../action/{Order.kt => OrderAction.kt} | 4 +- .../editor/{Item.kt => ItemEditorAction.kt} | 2 +- .../editor/{User.kt => UserEditorAction.kt} | 4 +- .../page/{Editor.kt => EditorPage.kt} | 4 +- .../page/{Error.kt => ErrorPage.kt} | 2 +- .../fruitable/controller/page/OrderPage.kt | 63 +++++++++++ .../team8/fruitable/controller/page/Pages.kt | 18 ++-- .../team8/fruitable/datebase/entity/Item.kt | 5 + src/main/resources/static/styles/base.less | 41 +++++++ src/main/resources/static/styles/item.less | 51 +++------ src/main/resources/static/styles/order.less | 0 src/main/resources/static/styles/orders.less | 0 src/main/resources/static/styles/user.css | 41 ------- src/main/resources/templates/account.mustache | 2 +- src/main/resources/templates/cart.mustache | 5 +- .../resources/templates/editor/item.mustache | 8 +- .../resources/templates/editor/user.mustache | 8 +- src/main/resources/templates/header.mustache | 6 +- src/main/resources/templates/item.mustache | 26 ++--- src/main/resources/templates/login.mustache | 2 +- .../resources/templates/order/create.mustache | 100 ++++++++++++++++++ .../resources/templates/order/update.mustache | 81 ++++++++++++++ src/main/resources/templates/orders.mustache | 31 ++++++ .../resources/templates/register.mustache | 2 +- 26 files changed, 387 insertions(+), 127 deletions(-) rename src/main/kotlin/team8/fruitable/controller/action/{Account.kt => AccountAction.kt} (98%) rename src/main/kotlin/team8/fruitable/controller/action/{Cart.kt => CartAction.kt} (97%) rename src/main/kotlin/team8/fruitable/controller/action/{Order.kt => OrderAction.kt} (98%) rename src/main/kotlin/team8/fruitable/controller/action/editor/{Item.kt => ItemEditorAction.kt} (99%) rename src/main/kotlin/team8/fruitable/controller/action/editor/{User.kt => UserEditorAction.kt} (97%) rename src/main/kotlin/team8/fruitable/controller/page/{Editor.kt => EditorPage.kt} (98%) rename src/main/kotlin/team8/fruitable/controller/page/{Error.kt => ErrorPage.kt} (93%) create mode 100644 src/main/kotlin/team8/fruitable/controller/page/OrderPage.kt create mode 100644 src/main/resources/static/styles/base.less create mode 100644 src/main/resources/static/styles/order.less create mode 100644 src/main/resources/static/styles/orders.less delete mode 100644 src/main/resources/static/styles/user.css create mode 100644 src/main/resources/templates/order/create.mustache create mode 100644 src/main/resources/templates/order/update.mustache create mode 100644 src/main/resources/templates/orders.mustache diff --git a/src/main/kotlin/team8/fruitable/controller/action/Account.kt b/src/main/kotlin/team8/fruitable/controller/action/AccountAction.kt similarity index 98% rename from src/main/kotlin/team8/fruitable/controller/action/Account.kt rename to src/main/kotlin/team8/fruitable/controller/action/AccountAction.kt index 4fb40ba..446e2e6 100644 --- a/src/main/kotlin/team8/fruitable/controller/action/Account.kt +++ b/src/main/kotlin/team8/fruitable/controller/action/AccountAction.kt @@ -14,7 +14,7 @@ import team8.fruitable.datebase.repository.AccountRepository @Controller @RequestMapping("/action/account") -class Account(private val repository: AccountRepository) { +class AccountAction(private val repository: AccountRepository) { private fun getCurrentUser(token: String?): User? { return token?.let(repository::findByToken) } diff --git a/src/main/kotlin/team8/fruitable/controller/action/Cart.kt b/src/main/kotlin/team8/fruitable/controller/action/CartAction.kt similarity index 97% rename from src/main/kotlin/team8/fruitable/controller/action/Cart.kt rename to src/main/kotlin/team8/fruitable/controller/action/CartAction.kt index 627ad84..bf8722c 100644 --- a/src/main/kotlin/team8/fruitable/controller/action/Cart.kt +++ b/src/main/kotlin/team8/fruitable/controller/action/CartAction.kt @@ -15,7 +15,7 @@ import team8.fruitable.datebase.repository.ItemRepository @Controller @RequestMapping("/action/cart") -class Cart( +class CartAction( private val cartRepository: CartRepository, private val accountRepository: AccountRepository, private val itemRepository: ItemRepository @@ -33,13 +33,13 @@ class Cart( ): String { val user = this.getCurrentUser(token) ?: return error(attributes, "添加商品至购物车", "未登录账户", "/login") val item = itemRepository.findById(id) - .orElse(null) ?: return error(attributes, "添加商品至购物车", "商品不存在", "/cart") + .orElse(null) ?: return error(attributes, "添加商品至购物车", "商品不存在", "/items") cartRepository.save( cartRepository.findByUserAndItem(user, item)?.let { it.number += 1; it } ?: CartedItem(user, item)) redirect?.let { return "redirect:/${it}" } - return "redirect:/items" + return "redirect:/cart" } @RequestMapping("/add/{id}/{number}") diff --git a/src/main/kotlin/team8/fruitable/controller/action/Order.kt b/src/main/kotlin/team8/fruitable/controller/action/OrderAction.kt similarity index 98% rename from src/main/kotlin/team8/fruitable/controller/action/Order.kt rename to src/main/kotlin/team8/fruitable/controller/action/OrderAction.kt index 741cb80..065d1ae 100644 --- a/src/main/kotlin/team8/fruitable/controller/action/Order.kt +++ b/src/main/kotlin/team8/fruitable/controller/action/OrderAction.kt @@ -14,7 +14,7 @@ import team8.fruitable.datebase.repository.* @Controller @RequestMapping("/action/order") -class Order( +class OrderAction( private val orderRepository: OrderRepository, private val orderedItemRepository: OrderedItemRepository, private val payTypeRepository: PayTypeRepository, @@ -61,7 +61,7 @@ class Order( attributes: RedirectAttributes, @CookieValue("TOKEN", required = false) token: String?, @RequestParam("items") itemIds: Array, - @RequestParam("item_numbers") itemNumbers: Array, + @RequestParam("numbers") itemNumbers: Array, @RequestParam("name") name: String, @RequestParam("phone") phone: String, @RequestParam("address") address: String, diff --git a/src/main/kotlin/team8/fruitable/controller/action/editor/Item.kt b/src/main/kotlin/team8/fruitable/controller/action/editor/ItemEditorAction.kt similarity index 99% rename from src/main/kotlin/team8/fruitable/controller/action/editor/Item.kt rename to src/main/kotlin/team8/fruitable/controller/action/editor/ItemEditorAction.kt index bc1839c..a2266e6 100644 --- a/src/main/kotlin/team8/fruitable/controller/action/editor/Item.kt +++ b/src/main/kotlin/team8/fruitable/controller/action/editor/ItemEditorAction.kt @@ -20,7 +20,7 @@ import kotlin.io.path.exists @Controller @RequestMapping("/action/edit/item") -class Item( +class ItemEditorAction( private val accountRepository: AccountRepository, private val itemRepository: ItemRepository, private val tagRepository: TagRepository diff --git a/src/main/kotlin/team8/fruitable/controller/action/editor/User.kt b/src/main/kotlin/team8/fruitable/controller/action/editor/UserEditorAction.kt similarity index 97% rename from src/main/kotlin/team8/fruitable/controller/action/editor/User.kt rename to src/main/kotlin/team8/fruitable/controller/action/editor/UserEditorAction.kt index e6048c8..f7135d1 100644 --- a/src/main/kotlin/team8/fruitable/controller/action/editor/User.kt +++ b/src/main/kotlin/team8/fruitable/controller/action/editor/UserEditorAction.kt @@ -11,7 +11,7 @@ import team8.fruitable.datebase.repository.AccountRepository @Controller @RequestMapping("/action/edit/user") -class User(private val accountRepository: AccountRepository) { +class UserEditorAction(private val accountRepository: AccountRepository) { private fun getCurrentUser(token: String?): User? { return token?.let(accountRepository::findByToken) } @@ -93,7 +93,7 @@ class User(private val accountRepository: AccountRepository) { attributes, "禁用账户", "未找到此账户", "/editor?use=user" ) user.revoke() - accountRepository.delete(user) + accountRepository.save(user) redirect?.let { return "redirect:/${it}" } return "redirect:/editor?use=user" } diff --git a/src/main/kotlin/team8/fruitable/controller/page/Editor.kt b/src/main/kotlin/team8/fruitable/controller/page/EditorPage.kt similarity index 98% rename from src/main/kotlin/team8/fruitable/controller/page/Editor.kt rename to src/main/kotlin/team8/fruitable/controller/page/EditorPage.kt index 77e48a6..ccfd546 100644 --- a/src/main/kotlin/team8/fruitable/controller/page/Editor.kt +++ b/src/main/kotlin/team8/fruitable/controller/page/EditorPage.kt @@ -17,7 +17,7 @@ import team8.fruitable.datebase.repository.PagebleItemRepository @Controller -class Editor( +class EditorPage( private val accountRepository: AccountRepository, private val itemRepository: ItemRepository, private val pagingAccountRepository: PagebleAccountRepository, @@ -108,7 +108,7 @@ class Editor( "revoking" -> model["isRevoking"] = true else -> model["isNothing"] = true } - if (action == "updating" || action == "deleting") { + if (action == "updating" || action == "revoking") { model["target"] = when (use) { "item" -> { target?.let { diff --git a/src/main/kotlin/team8/fruitable/controller/page/Error.kt b/src/main/kotlin/team8/fruitable/controller/page/ErrorPage.kt similarity index 93% rename from src/main/kotlin/team8/fruitable/controller/page/Error.kt rename to src/main/kotlin/team8/fruitable/controller/page/ErrorPage.kt index c6e2956..caf6ea0 100644 --- a/src/main/kotlin/team8/fruitable/controller/page/Error.kt +++ b/src/main/kotlin/team8/fruitable/controller/page/ErrorPage.kt @@ -10,7 +10,7 @@ import org.springframework.web.bind.annotation.RequestMapping import team8.fruitable.datebase.repository.AccountRepository @Controller -class Error(private val repository: AccountRepository) : ErrorController { +class ErrorPage(private val repository: AccountRepository) : ErrorController { @RequestMapping("/error") fun error( model: Model, diff --git a/src/main/kotlin/team8/fruitable/controller/page/OrderPage.kt b/src/main/kotlin/team8/fruitable/controller/page/OrderPage.kt new file mode 100644 index 0000000..9b7e050 --- /dev/null +++ b/src/main/kotlin/team8/fruitable/controller/page/OrderPage.kt @@ -0,0 +1,63 @@ +package team8.fruitable.controller.page + +import org.springframework.stereotype.Controller +import org.springframework.ui.Model +import org.springframework.ui.set +import org.springframework.web.bind.annotation.CookieValue +import org.springframework.web.bind.annotation.PathVariable +import org.springframework.web.bind.annotation.RequestMapping +import org.springframework.web.bind.annotation.RequestParam +import org.springframework.web.servlet.mvc.support.RedirectAttributes +import team8.fruitable.controller.util.error +import team8.fruitable.datebase.entity.User +import team8.fruitable.datebase.repository.AccountRepository +import team8.fruitable.datebase.repository.ItemRepository +import team8.fruitable.datebase.repository.OrderRepository + +@Controller +class OrderPage( + private val orderRepository: OrderRepository, + private val accountRepository: AccountRepository, + private val itemRepository: ItemRepository +) { + private fun getCurrentUser(token: String?): User? { + return token?.let(accountRepository::findByToken) + } + + @RequestMapping("/orders") + fun orders( + model: Model, attributes: RedirectAttributes, @CookieValue("TOKEN", required = false) token: String? + ): String { + model["isOrder"] = true + val user = this.getCurrentUser(token) ?: return error(attributes, "查看订单列表", "账户未登录", "/login") + model["user"] = user + return "orders" + } + + @RequestMapping("/order/create") + fun create( + model: Model, + attributes: RedirectAttributes, + @CookieValue("TOKEN", required = false) token: String?, + @RequestParam("id") id: Array + ): String { + val user = this.getCurrentUser(token) ?: return error(attributes, "更新", "账户未登录", "/login") + model["user"] = user + return "order/create" + } + + @RequestMapping("/order/create/{id}") + fun info( + model: Model, + attributes: RedirectAttributes, + @CookieValue("TOKEN", required = false) token: String?, + @PathVariable("id") id: Long, + @RequestParam("number") number: Int? + ): String { + val user = this.getCurrentUser(token) ?: return error(attributes, "查看订单", "账户未登录", "/login") + val item = itemRepository.findById(id).orElse(null) ?: return error(attributes, "查看订单", "商品不存在") + model["items"] = arrayOf(Triple(item, number ?: 1, item.price!! * (number ?: 1))) + model["user"] = user + return "order/create" + } +} \ No newline at end of file diff --git a/src/main/kotlin/team8/fruitable/controller/page/Pages.kt b/src/main/kotlin/team8/fruitable/controller/page/Pages.kt index 3f03d2c..3040b3d 100644 --- a/src/main/kotlin/team8/fruitable/controller/page/Pages.kt +++ b/src/main/kotlin/team8/fruitable/controller/page/Pages.kt @@ -1,6 +1,5 @@ package team8.fruitable.controller.page -import org.springframework.beans.factory.annotation.Value import org.springframework.stereotype.Controller import org.springframework.ui.Model import org.springframework.ui.set @@ -15,9 +14,6 @@ import team8.fruitable.datebase.repository.ItemRepository @Controller class Pages(private val accountRepository: AccountRepository, private val itemRepository: ItemRepository) { - @Value("\${data.handler}") - lateinit var handler: String - private fun getCurrentUser(token: String?): User? { return token?.let(accountRepository::findByToken) } @@ -90,8 +86,18 @@ class Pages(private val accountRepository: AccountRepository, private val itemRe this.getCurrentUser(token)?.let { model["user"] = it } val item = itemRepository.findById(id).orElse(null) ?: return error(attributes, "查看商品", "不存在的商品") model["item"] = item - model["itemPicture"] = - item.picture?.let { "${handler}/picture/${it.slice(0..1)}/${it}" } ?: "/images/placeholder.png" return "item" } + + @RequestMapping("/cart") + fun cart( + model: Model, + attributes: RedirectAttributes, + @CookieValue("TOKEN", required = false) token: String? + ): String { + model["isCart"] = true + val user = this.getCurrentUser(token) ?: return error(attributes, "更新", "账户未登录", "/login") + model["user"] = user + return "cart" + } } diff --git a/src/main/kotlin/team8/fruitable/datebase/entity/Item.kt b/src/main/kotlin/team8/fruitable/datebase/entity/Item.kt index f5c82a9..4ab9c56 100644 --- a/src/main/kotlin/team8/fruitable/datebase/entity/Item.kt +++ b/src/main/kotlin/team8/fruitable/datebase/entity/Item.kt @@ -106,4 +106,9 @@ class Item( fun getTagString(): String { return this.tags.joinToString(" ") } + + @Bean + fun getPictureLink(): String { + return this.picture?.let { "/resourcesNew/picture/${it.slice(0..1)}/${it}" } ?: "/images/placeholder.png" + } } diff --git a/src/main/resources/static/styles/base.less b/src/main/resources/static/styles/base.less new file mode 100644 index 0000000..6c17d9c --- /dev/null +++ b/src/main/resources/static/styles/base.less @@ -0,0 +1,41 @@ +@font-face { + font-family: "Normal"; + src: url("../fonts/华文圆体-Regular.ttf") format("ttf"); +} + +body { + display: flex; + margin: auto; + flex-direction: column; + align-items: center; +} + +div { + display: flex; +} + +#Contents { + flex-direction: column; + width: 100%; + justify-content: center; + align-items: center; +} + +.TabForm { + margin: 5px; + padding: 26px 48px; + background-color: rgba(0, 60, 130, 0.8); + border: 3px solid rgba(0, 120, 255, 0.8); + border-radius: 15px; +} + +.TabTitle, .TabFormItem > .ItemName { + color: wheat; + font-family: "Normal", system-ui; +} + +@media (min-width: 640px) { + #Contents { + width: 640px; + } +} \ No newline at end of file diff --git a/src/main/resources/static/styles/item.less b/src/main/resources/static/styles/item.less index c32e0cd..de9e063 100644 --- a/src/main/resources/static/styles/item.less +++ b/src/main/resources/static/styles/item.less @@ -68,51 +68,28 @@ div { font-weight: bold; } - > .Options { - flex-direction: column; + > .Number { + flex-direction: row; + justify-content: space-evenly; - > .Option { - flex-direction: row; - margin: 5px 0; - border: 1px solid rgba(0, 120, 255, 0.8); - border-radius: 5px; - - > .Title { - font-weight: bold; - padding: 0 10px; - border-radius: 5px 0 0 5px; - background: green; - font-size: 20px; - } - - > .Contents { - flex-wrap: wrap; - align-items: stretch; - - > .Option { - font-size: 18px; - padding: 0 5px; - align-items: center; - background-color: #355ae8; - } - - .Option[selected] { - font-weight: bold; - background-color: #489dff; - } - } + > .Input { + margin-left: 20px; + border-radius: 10px; + border: 3px solid skyblue; } } > .Buttons { - justify-content: space-evenly; text-align: center; + justify-content: space-evenly; > .Button { - width: 90px; - padding: 10px 30px; - border-radius: 15px; - background-color: darkgreen; + flex: 1; + padding: 8px 30px; + border: 3px solid skyblue; + border-radius: 10px; + background-color: cadetblue; + font-size: 24px; } } diff --git a/src/main/resources/static/styles/order.less b/src/main/resources/static/styles/order.less new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/static/styles/orders.less b/src/main/resources/static/styles/orders.less new file mode 100644 index 0000000..e69de29 diff --git a/src/main/resources/static/styles/user.css b/src/main/resources/static/styles/user.css deleted file mode 100644 index 6ad6d77..0000000 --- a/src/main/resources/static/styles/user.css +++ /dev/null @@ -1,41 +0,0 @@ -@font-face { - font-family: "Normal"; - src: url("../fonts/华文圆体-Regular.ttf") format("ttf"); -} - -body { - display: flex; - margin: auto; - flex-direction: column; - align-items: center; -} - -div { - display: flex; -} - -#Contents { - flex-direction: column; - width: 100%; - justify-content: center; - align-items: center; -} - -.TabForm { - margin: 5px; - padding: 26px 48px; - background-color: rgba(0, 60, 130, 0.8); - border: 3px solid rgba(0, 120, 255, 0.8); - border-radius: 15px; -} - -.TabTitle, .TabFormItem > .ItemName { - color: wheat; - font-family: "Normal"; -} - -@media (min-width: 640px) { - #Contents { - width: 640px; - } -} \ No newline at end of file diff --git a/src/main/resources/templates/account.mustache b/src/main/resources/templates/account.mustache index 53cbfa8..92274d1 100644 --- a/src/main/resources/templates/account.mustache +++ b/src/main/resources/templates/account.mustache @@ -12,7 +12,7 @@ - + diff --git a/src/main/resources/templates/cart.mustache b/src/main/resources/templates/cart.mustache index 7344a82..42da003 100644 --- a/src/main/resources/templates/cart.mustache +++ b/src/main/resources/templates/cart.mustache @@ -2,7 +2,7 @@ - 编辑 - 在线果蔬商城 + 我的购物车 - 在线果蔬商城 @@ -11,9 +11,8 @@ - - + diff --git a/src/main/resources/templates/editor/item.mustache b/src/main/resources/templates/editor/item.mustache index 6cd53f9..6e2f7ec 100644 --- a/src/main/resources/templates/editor/item.mustache +++ b/src/main/resources/templates/editor/item.mustache @@ -8,6 +8,7 @@ 更新时间 价格 标签 + 已撤销 操作 @@ -20,6 +21,7 @@ {{editTime}} {{price}} {{tagPretty}} + {{#isRevoked}}是{{/isRevoked}}{{^isRevoked}}否{{/isRevoked}} @@ -124,9 +126,9 @@ {{/isUpdating}} {{#isRevoking}} -
-

确定要删除商品 {{target.name}} 吗?

- + +

确定要撤销商品 {{target.name}} 吗?

+
{{/isRevoking}} diff --git a/src/main/resources/templates/editor/user.mustache b/src/main/resources/templates/editor/user.mustache index 9b0ac91..543838a 100644 --- a/src/main/resources/templates/editor/user.mustache +++ b/src/main/resources/templates/editor/user.mustache @@ -12,6 +12,7 @@ 邮箱 地址 管理员 + 已禁用 操作 @@ -28,6 +29,7 @@ {{#email}}{{email}}{{/email}} {{#address}}{{address}}{{/address}} {{#isAdmin}}是{{/isAdmin}}{{^isAdmin}}否{{/isAdmin}} + {{#isRevoked}}是{{/isRevoked}}{{^isRevoked}}否{{/isRevoked}} @@ -185,9 +187,9 @@ {{/isUpdating}} {{#isRevoking}} -
-

确定要删除用户 {{target.name}} 吗?

- + +

确定要禁用用户 {{target.name}} 吗?

+
{{/isRevoking}} diff --git a/src/main/resources/templates/header.mustache b/src/main/resources/templates/header.mustache index ce2b38c..926df09 100644 --- a/src/main/resources/templates/header.mustache +++ b/src/main/resources/templates/header.mustache @@ -15,7 +15,11 @@
{{#user}} -