Skip to content

Commit 9d66bdf

Browse files
committed
SCHP-102 Allow order from kitchen-view after opening, add afterhours feature
1 parent 8fc8b34 commit 9d66bdf

File tree

8 files changed

+79
-137
lines changed

8 files changed

+79
-137
lines changed

src/main/kotlin/hu/kirdev/schpincer/dao/Repositories.kt

+3-1
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,9 @@ interface ReviewRepository : JpaRepository<ReviewEntity, Long> {
6969
}
7070

7171
@Repository
72-
interface TimeWindowRepository : JpaRepository<TimeWindowEntity, Long>
72+
interface TimeWindowRepository : JpaRepository<TimeWindowEntity, Long> {
73+
override fun findById(id: Long): Optional<TimeWindowEntity>
74+
}
7375

7476
@Repository
7577
interface UserRepository : JpaRepository<UserEntity, String> {

src/main/kotlin/hu/kirdev/schpincer/dto/ItemEntityDto.kt

+8-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import hu.kirdev.schpincer.model.*
44
import java.lang.Integer.max
55
import java.lang.Integer.min
66

7-
class ItemEntityDto(base: ItemEntity, opening: OpeningEntity?, loggedin: Boolean) {
7+
class ItemEntityDto(base: ItemEntity, opening: OpeningEntity?, loggedin: Boolean, explicitMapping: Boolean) {
88
val id: Long
99
val name: String
1010
val description: String
@@ -41,7 +41,13 @@ class ItemEntityDto(base: ItemEntity, opening: OpeningEntity?, loggedin: Boolean
4141
personallyOrderable = base.personallyOrderable
4242
imageName = base.imageName ?: "/cdn/image/blank-null-item.jpg"
4343
nextOpeningDate = opening?.dateStart ?: 0
44-
timeWindows = opening?.timeWindows ?: listOf()
44+
45+
timeWindows = if (loggedin) {
46+
(opening?.timeWindows ?: listOf()).filter { explicitMapping || it.extraItemCount >= 0 }
47+
} else {
48+
listOf()
49+
}
50+
4551
orderStatus = ItemOrderableStatus.OK
4652
flag = base.flag
4753
discountPrice = base.discountPrice

src/main/kotlin/hu/kirdev/schpincer/model/OpeningEntity.kt

+4
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,10 @@ data class OpeningEntity(
113113
appendTimeWindow(openings, time)
114114
time += this.intervalLength * MILLIS_TO_MINS
115115
}
116+
117+
val tw = TimeWindowEntity(0, this, "Túlóra", this.dateEnd, 0, Integer.MIN_VALUE)
118+
timeWindows.add(tw)
119+
openings.saveTimeWindow(tw)
116120
}
117121

118122
private fun appendTimeWindow(openings: OpeningService, time: Long) {

src/main/kotlin/hu/kirdev/schpincer/service/HibernateSearchService.kt

-97
This file was deleted.

src/main/kotlin/hu/kirdev/schpincer/service/MakeOrderProcedure.kt

+25-14
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ class MakeOrderProcedure (
5151

5252
details = calculateExtra(detailsJson, order, item, manualUser?.card ?: user.cardType)
5353
updateBasicDetails()
54-
current = openings.findNextOf(item.circle?.id!!) ?: throw FailedOrderException(RESPONSE_INTERNAL_ERROR)
5554
if (manualUser == null)
5655
validateOrderable(System.currentTimeMillis())
5756

@@ -61,8 +60,9 @@ class MakeOrderProcedure (
6160
validateOrderCount()
6261
timeWindow = timeWindowRepo.getOne(time)
6362
validateTimeWindow()
64-
updateCategoryLimitations()
63+
updateCategoryLimitations(true)
6564
} else {
65+
updateCategoryLimitations(false)
6666
timeWindow = timeWindowRepo.getOne(time)
6767
}
6868

@@ -94,7 +94,8 @@ class MakeOrderProcedure (
9494
internal fun updateBasicDetails() {
9595
order.intervalId = time
9696
order.name = item.name
97-
order.openingId = openings.findNextOf(item.circle?.id!!)?.id!!
97+
current = timeWindowRepo.findById(time).map { it.opening }.orElse(null) ?: throw FailedOrderException(RESPONSE_TIME_WINDOW_INVALID)
98+
order.openingId = current.id
9899
}
99100

100101
internal fun validateOrderable(now: Long) {
@@ -116,32 +117,42 @@ class MakeOrderProcedure (
116117
throw FailedOrderException(RESPONSE_MAX_REACHED_EXTRA)
117118
}
118119

119-
internal fun updateCategoryLimitations() {
120+
internal fun updateCategoryLimitations(force: Boolean) {
120121
when (ItemCategory.of(item.category)) {
121-
ItemCategory.ALPHA ->
122+
ItemCategory.ALPHA -> {
122123
if (current.usedAlpha + count <= current.maxAlpha)
123124
current.usedAlpha += count
124-
else throw FailedOrderException(RESPONSE_CATEGORY_FULL)
125+
else if (force) throw FailedOrderException(RESPONSE_CATEGORY_FULL)
126+
else return
127+
}
125128

126-
ItemCategory.BETA ->
129+
ItemCategory.BETA -> {
127130
if (current.usedBeta + count <= current.maxBeta)
128131
current.usedBeta += count
129-
else throw FailedOrderException(RESPONSE_CATEGORY_FULL)
132+
else if (force) throw FailedOrderException(RESPONSE_CATEGORY_FULL)
133+
else return
134+
}
130135

131-
ItemCategory.GAMMA ->
136+
ItemCategory.GAMMA -> {
132137
if (current.usedGamma + count <= current.maxGamma)
133138
current.usedGamma += count
134-
else throw FailedOrderException(RESPONSE_CATEGORY_FULL)
139+
else if (force) throw FailedOrderException(RESPONSE_CATEGORY_FULL)
140+
else return
141+
}
135142

136-
ItemCategory.DELTA ->
143+
ItemCategory.DELTA -> {
137144
if (current.usedDelta + count <= current.maxDelta)
138145
current.usedDelta += count
139-
else throw FailedOrderException(RESPONSE_CATEGORY_FULL)
146+
else if (force) throw FailedOrderException(RESPONSE_CATEGORY_FULL)
147+
else return
148+
}
140149

141-
ItemCategory.LAMBDA ->
150+
ItemCategory.LAMBDA -> {
142151
if (current.usedLambda + count <= current.maxLambda)
143152
current.usedLambda += count
144-
else throw FailedOrderException(RESPONSE_CATEGORY_FULL)
153+
else if (force) throw FailedOrderException(RESPONSE_CATEGORY_FULL)
154+
else return
155+
}
145156

146157
else -> {
147158
// No extra action is required

src/main/kotlin/hu/kirdev/schpincer/service/OrderService.kt

+1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ const val RESPONSE_MANUAL_FAIL = "MANUAL_FAIL"
3838
const val RESPONSE_BAD_REQUEST = "BAD_REQUEST"
3939
const val RESPONSE_INVALID_STATUS = "INVALID_STATUS"
4040
const val RESPONSE_ORDER_PERIOD_ENDED = "ORDER_PERIOD_ENDED"
41+
const val RESPONSE_TIME_WINDOW_INVALID = "TIME_WINDOW_INVALID"
4142

4243
@Service
4344
open class OrderService {

src/main/kotlin/hu/kirdev/schpincer/web/ApiController.kt

+15-6
Original file line numberDiff line numberDiff line change
@@ -42,12 +42,17 @@ open class ApiController(
4242
@ApiOperation("Item info")
4343
@GetMapping("/item/{id}")
4444
@ResponseBody
45-
fun getItem(request: HttpServletRequest, @PathVariable id: Long): ItemEntityDto? {
45+
fun getItem(
46+
request: HttpServletRequest,
47+
@PathVariable id: Long,
48+
@RequestParam(defaultValue = "0") explicitOpening: Long
49+
): ItemEntityDto? {
4650
val item = items.getOne(id)
4751
if (item == null || (!request.hasUser() && !item.visibleWithoutLogin))
4852
return null
4953
val loggedIn = request.hasUser() || request.isInInternalNetwork()
50-
return ItemEntityDto(item, openings.findNextOf(item.circle!!.id), loggedIn)
54+
val opening = if (explicitOpening != 0L) openings.getOne(explicitOpening) else openings.findNextOf(item.circle!!.id)
55+
return ItemEntityDto(item, opening, loggedIn, loggedIn && explicitOpening > 0)
5156
}
5257

5358
@ApiOperation("List of items")
@@ -66,7 +71,8 @@ open class ApiController(
6671
.map { item: ItemEntity ->
6772
ItemEntityDto(item,
6873
cache.computeIfAbsent(item.circle!!.id) { openings.findNextOf(it) },
69-
loggedIn || request.isInInternalNetwork())
74+
loggedIn || request.isInInternalNetwork(),
75+
false)
7076
}
7177
.collect(Collectors.toList())
7278
return ResponseEntity(list, HttpStatus.OK)
@@ -78,7 +84,8 @@ open class ApiController(
7884
.map { item: ItemEntity ->
7985
ItemEntityDto(item,
8086
cache.computeIfAbsent(item.circle!!.id) { openings.findNextOf(it) },
81-
loggedIn || request.isInInternalNetwork())
87+
loggedIn || request.isInInternalNetwork(),
88+
false)
8289
}
8390
.collect(Collectors.toList())
8491
return ResponseEntity(list, HttpStatus.OK)
@@ -97,7 +104,8 @@ open class ApiController(
97104
.map { item: ItemEntity ->
98105
ItemEntityDto(item,
99106
cache.computeIfAbsent(item.circle!!.id) { openings.findNextOf(it) },
100-
loggedIn || request.isInInternalNetwork())
107+
loggedIn || request.isInInternalNetwork(),
108+
false)
101109
}
102110
.collect(Collectors.toList())
103111
return ResponseEntity(list, HttpStatus.OK)
@@ -116,7 +124,8 @@ open class ApiController(
116124
.map { item: ItemEntity ->
117125
ItemEntityDto(item,
118126
cache.computeIfAbsent(item.circle!!.id) { openings.findNextOf(it) },
119-
loggedIn || request.isInInternalNetwork())
127+
loggedIn || request.isInInternalNetwork(),
128+
false)
120129
}
121130
.collect(Collectors.toList())
122131
return ResponseEntity(list, HttpStatus.OK)

src/main/resources/static/js/items.js

+23-17
Original file line numberDiff line numberDiff line change
@@ -370,7 +370,7 @@ function itemChangedPizzasch() {
370370
}
371371

372372
function showPopup(id) {
373-
getForJsonObject('api/item/' + id)
373+
getForJsonObject('api/item/' + id + (manualOrder ? ('?explicitOpening=' + OPENING_ID) : ''))
374374
.then(function (data) {
375375
disableScroll();
376376
latestData = data;
@@ -556,7 +556,8 @@ const ResponseType = {
556556
MAX_REACHED_EXTRA: 'MAX_REACHED_EXTRA',
557557
NO_ORDERING: 'NO_ORDERING',
558558
NO_ROOM_SET: 'NO_ROOM_SET',
559-
CATEGORY_FULL: 'CATEGORY_FULL'
559+
CATEGORY_FULL: 'CATEGORY_FULL',
560+
TIME_WINDOW_INVALID: 'TIME_WINDOW_INVALID'
560561
};
561562

562563
function packManualOrderDetails() {
@@ -593,22 +594,27 @@ function buySelectedItem() {
593594
if (data === ResponseType.ACK) {
594595
closePopup(true);
595596
doneOrder();
596-
} else if (data === ResponseType.INTERNAL_ERROR) {
597-
showMessageBox(LANG.internal);
598-
} else if (data === ResponseType.OVERALL_MAX_REACHED) {
599-
showMessageBox(LANG.orderFull);
600-
} else if (data === ResponseType.MAX_REACHED) {
601-
showMessageBox(LANG.intervalFull);
602-
} else if (data === ResponseType.MAX_REACHED_EXTRA) {
603-
showMessageBox(LANG.intervalFullExtra);
604-
} else if (data === ResponseType.NO_ORDERING) {
605-
showMessageBox(LANG.alreadyClosed);
606-
} else if (data === ResponseType.NO_ROOM_SET) {
607-
showMessageBox(LANG.noRoom);
608-
} else if (data === ResponseType.CATEGORY_FULL) {
609-
showMessageBox(LANG.categoryFull);
610597
} else {
611-
showMessageBox(data);
598+
console.error(data);
599+
if (data === ResponseType.INTERNAL_ERROR) {
600+
showMessageBox(LANG.internal);
601+
} else if (data === ResponseType.OVERALL_MAX_REACHED) {
602+
showMessageBox(LANG.orderFull);
603+
} else if (data === ResponseType.MAX_REACHED) {
604+
showMessageBox(LANG.intervalFull);
605+
} else if (data === ResponseType.MAX_REACHED_EXTRA) {
606+
showMessageBox(LANG.intervalFullExtra);
607+
} else if (data === ResponseType.NO_ORDERING) {
608+
showMessageBox(LANG.alreadyClosed);
609+
} else if (data === ResponseType.NO_ROOM_SET) {
610+
showMessageBox(LANG.noRoom);
611+
} else if (data === ResponseType.CATEGORY_FULL) {
612+
showMessageBox(LANG.categoryFull);
613+
} else if (data === ResponseType.TIME_WINDOW_INVALID) {
614+
showMessageBox(LANG.internal);
615+
} else {
616+
showMessageBox(data);
617+
}
612618
}
613619

614620
}).catch(function (e) {

0 commit comments

Comments
 (0)