Skip to content

Commit

Permalink
fix amountToBuy to be very high value due to being negative and remov…
Browse files Browse the repository at this point in the history
…e 0 items to buy and patch frontend
  • Loading branch information
BaptTF committed Apr 27, 2024
1 parent f801ab0 commit 1c29d6d
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 12 deletions.
15 changes: 9 additions & 6 deletions backend/api/course.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,15 @@ func (s *Server) GetCourse(c echo.Context, params autogen.GetCourseParams) error
}

for _, item := range data {
var amount_needed uint64 = item.OptimalAmount - item.AmountLeft
if amount_needed > 0 && item.AmountPerBundle != nil {
course = append(course, autogen.CourseItem{
AmountToBuy: amount_needed / *item.AmountPerBundle + (amount_needed % *item.AmountPerBundle) * 2 / *item.AmountPerBundle,
Item: item.Item,
})
var amount_needed = item.OptimalAmount - item.AmountLeft
if item.OptimalAmount > item.AmountLeft && item.AmountPerBundle != nil {
amountToBuy := amount_needed / *item.AmountPerBundle + (amount_needed%*item.AmountPerBundle)*2 / *item.AmountPerBundle
if amountToBuy > 0 {
course = append(course, autogen.CourseItem{
AmountToBuy: amountToBuy,
Item: item.Item,
})
}
}
}

Expand Down
14 changes: 8 additions & 6 deletions frontend/src/routes/panel/products/course/+page.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -63,18 +63,20 @@
</tr>
</thead>
<tbody class="divide-y divide-gray-200 dark:divide-gray-700">
<td>
{#each items as item}
<td class="h-px">
<p class="py-3 px-2 block border-gray-200 border-2 rounded-md text-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400">
{item.item.name}
</p>
{/each}
</td>
<td class="h-px">
<p class="py-3 px-2 block border-gray-200 border-2 rounded-md text-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400">
{item.amountToBuy}
</p>
<td>
{#each items as item}
<p class="py-3 px-2 block border-gray-200 border-2 rounded-md text-sm focus:border-blue-500 focus:ring-blue-500 dark:bg-gray-800 dark:border-gray-700 dark:text-gray-400">
{item.amountToBuy}
</p>
{/each}
</td>
{/each}
</tbody>
</table>

0 comments on commit 1c29d6d

Please sign in to comment.