-
Notifications
You must be signed in to change notification settings - Fork 159
Issue 938 Backend: реализация контроллера "Вебинары" в лк #938 #950
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 15 commits
b4ef6ec
4219276
eda70a6
026e80b
4b832f1
24bb06c
c67f35b
6691ac6
07cc1db
8e4ab39
5330e81
8ebe2c1
6697a54
6b8dfb1
c6ce338
0eadcbf
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,65 @@ | ||
| package io.hexlet.cv.controller.account; | ||
|
|
||
| import io.github.inertia4j.spring.Inertia; | ||
| import io.hexlet.cv.service.AccountWebinarService; | ||
| import io.hexlet.cv.service.CalendarEventService; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.util.ObjectUtils; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.servlet.mvc.support.RedirectAttributes; | ||
| import org.springframework.web.servlet.support.RequestContextUtils; | ||
|
|
||
| @Controller | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/account") | ||
| public class AccountWebinarsController { | ||
|
|
||
| private final Inertia inertia; | ||
| private final AccountWebinarService accountWebinarService; | ||
| private final CalendarEventService calendarEventService; | ||
|
|
||
| @GetMapping("/webinars") | ||
| public Object index(@RequestParam(defaultValue = "0") int page, | ||
| @RequestParam(defaultValue = "10") int size, | ||
| HttpServletRequest request) { | ||
|
|
||
| Pageable pageable = PageRequest.of(page, size); | ||
|
|
||
| var props = accountWebinarService.indexWebinars(pageable); | ||
|
|
||
| var flash = RequestContextUtils.getInputFlashMap(request); | ||
| if (!ObjectUtils.isEmpty(flash)) { | ||
| props.put("flash", flash); | ||
| } | ||
|
|
||
| return inertia.render("Account/Webinars/Index", props); | ||
| } | ||
|
|
||
| @PostMapping("/webinars/{webinarId}/registrations") | ||
| public Object registerToWebinar(@PathVariable Long webinarId, | ||
| RedirectAttributes redirectAttributes) { | ||
|
|
||
| accountWebinarService.registrationUserToWebinar(webinarId); | ||
|
|
||
| redirectAttributes.addFlashAttribute("success", "webinar.registered.success"); | ||
| return inertia.redirect("/account/webinars"); | ||
| } | ||
|
|
||
| @PostMapping("/webinars/{webinarId}/calendar-events") | ||
| public Object addWebinarToCalendar(@PathVariable Long webinarId, | ||
| RedirectAttributes redirectAttributes) { | ||
|
|
||
| calendarEventService.addWebinarToCalendar(webinarId); | ||
|
|
||
| redirectAttributes.addFlashAttribute("success", "webinar.add.success"); | ||
| return inertia.redirect("/account/webinars"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,45 @@ | ||
| package io.hexlet.cv.controller.account; | ||
|
|
||
| import io.github.inertia4j.spring.Inertia; | ||
| import io.hexlet.cv.service.PurchaseAndSubscriptionService; | ||
| import io.hexlet.cv.util.UserUtils; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import lombok.RequiredArgsConstructor; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.security.access.prepost.PreAuthorize; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.util.ObjectUtils; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.servlet.support.RequestContextUtils; | ||
|
|
||
| @Controller | ||
| @RequiredArgsConstructor | ||
| @RequestMapping("/account") | ||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Контроллер, судя по названию, про покупки и подписки, почему урл про аккаунт?
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. issue было "Покупки и подписки" для личного кабинета " Ничего не менял. |
||
| public class PurchaseAndSubscriptionController { | ||
|
|
||
| private final Inertia inertia; | ||
| private final PurchaseAndSubscriptionService service; | ||
| private final UserUtils userUtils; | ||
|
|
||
| @PreAuthorize("isAuthenticated()") | ||
| @GetMapping("/purchase") | ||
| public Object index(@RequestParam(defaultValue = "0") int page, | ||
| @RequestParam(defaultValue = "10") int size, | ||
| HttpServletRequest request) { | ||
|
|
||
| var userId = userUtils.currentUserId(); // id юзера который залогинился | ||
|
|
||
| Pageable pageable = PageRequest.of(page, size); | ||
| var props = service.indexPurchSubs(userId.get(), pageable); | ||
|
|
||
| var flash = RequestContextUtils.getInputFlashMap(request); | ||
| if (!ObjectUtils.isEmpty(flash)) { | ||
| props.put("flash", flash); | ||
| } | ||
|
|
||
| return inertia.render("Account/Purchase/Index", props); | ||
| } | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,84 @@ | ||
| package io.hexlet.cv.controller.admin; | ||
|
|
||
| import io.github.inertia4j.spring.Inertia; | ||
| import io.hexlet.cv.dto.admin.WebinarDto; | ||
| import io.hexlet.cv.service.AdminWebinarService; | ||
| import jakarta.servlet.http.HttpServletRequest; | ||
| import lombok.AllArgsConstructor; | ||
| import org.springframework.data.domain.PageRequest; | ||
| import org.springframework.data.domain.Pageable; | ||
| import org.springframework.security.access.prepost.PreAuthorize; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.web.bind.annotation.DeleteMapping; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.PathVariable; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.PutMapping; | ||
| import org.springframework.web.bind.annotation.RequestBody; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
| import org.springframework.web.bind.annotation.RequestParam; | ||
| import org.springframework.web.servlet.mvc.support.RedirectAttributes; | ||
| import org.springframework.web.servlet.support.RequestContextUtils; | ||
|
|
||
|
|
||
| @Controller | ||
| @AllArgsConstructor | ||
| @RequestMapping("/admin/webinars") | ||
| @PreAuthorize("hasRole('ADMIN')") | ||
| public class AdminWebinarsController { | ||
|
|
||
| private final Inertia inertia; | ||
|
|
||
| private final AdminWebinarService adminWebinarService; | ||
|
|
||
| @GetMapping("") | ||
| public Object adminWebinarsIndex(@RequestParam(defaultValue = "0") int page, | ||
| @RequestParam(defaultValue = "10") int size, | ||
| @RequestParam(name = "search", required = false) String searchStr, | ||
| HttpServletRequest request) { | ||
|
|
||
| Pageable pageable = PageRequest.of(page, size); | ||
| var props = adminWebinarService.indexSearchWebinar(pageable, searchStr); | ||
|
|
||
| var flash = RequestContextUtils.getInputFlashMap(request); | ||
|
|
||
| if (flash != null && !flash.isEmpty()) { | ||
| props.put("flash", flash); | ||
| } | ||
|
|
||
| return inertia.render("Admin/Webinars/Index", props); | ||
| } | ||
|
|
||
|
|
||
| @PostMapping("/create") | ||
| public Object createWebinar(@RequestBody WebinarDto webinarDTO, | ||
| RedirectAttributes redirectAttributes) { | ||
|
|
||
|
|
||
|
|
||
| adminWebinarService.createWebinar(webinarDTO); | ||
|
|
||
| redirectAttributes.addFlashAttribute("success", "create.success"); | ||
| return inertia.redirect("/Admin/Webinars/Index"); | ||
| } | ||
|
|
||
| @PutMapping("/{id}/update") | ||
| public Object updateWebinar(@PathVariable Long id, | ||
| @RequestBody WebinarDto webinarDTO, | ||
| RedirectAttributes redirectAttributes) { | ||
|
|
||
| adminWebinarService.updateWebinar(id, webinarDTO); | ||
|
|
||
| redirectAttributes.addFlashAttribute("success", "update.success"); | ||
| return inertia.redirect("/Admin/Webinars/Index"); | ||
| } | ||
|
|
||
| @DeleteMapping("/{id}/delete") | ||
| public Object deleteWebinar(@PathVariable Long id, | ||
| RedirectAttributes redirectAttributes) { | ||
|
|
||
| adminWebinarService.deleteWebinar(id); | ||
| redirectAttributes.addFlashAttribute("success", "delete.success"); | ||
| return inertia.redirect("/Admin/Webinars/Index"); | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,19 @@ | ||
| package io.hexlet.cv.converter; | ||
|
|
||
| import io.hexlet.cv.model.enums.StatePurchaseSubscriptionType; | ||
| import jakarta.persistence.AttributeConverter; | ||
| import jakarta.persistence.Converter; | ||
|
|
||
| @Converter(autoApply = true) | ||
| public class PurchaseAndSubscriptionTypeConverter implements AttributeConverter<StatePurchaseSubscriptionType, String> { | ||
|
|
||
| @Override | ||
| public String convertToDatabaseColumn(StatePurchaseSubscriptionType stateType) { | ||
| return stateType == null ? null : stateType.name().toLowerCase(); | ||
| } | ||
|
|
||
| @Override | ||
| public StatePurchaseSubscriptionType convertToEntityAttribute(String dbValue) { | ||
| return dbValue == null ? null : StatePurchaseSubscriptionType.valueOf(dbValue.toUpperCase()); | ||
| } | ||
| } |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Почему светится как измененное? Строки на вид идентичны
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
тут была опечатка serCive заменено на serVice.
Тут все нормально.