-
Notifications
You must be signed in to change notification settings - Fork 0
Feature/ticket mapper #10
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
Closed
Closed
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2b98709
Initial code TicketController
FionaSprinkles 6d6894f
fix: correct TicketService injection in TicketController
FionaSprinkles c91e435
Create TicketService and initial code
FionaSprinkles 92b40f0
feat: implement createTicket mapping in TicketService
FionaSprinkles 343ea3c
Create TicketMapper, add entityToViewDTO
FionaSprinkles f601843
Refactor `TicketController` and `TicketService` for clarity: make `ti…
simonforsberg File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
51 changes: 51 additions & 0 deletions
51
src/main/java/org/example/alfs/controllers/TicketController.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,51 @@ | ||
| package org.example.alfs.controllers; | ||
|
|
||
| import jakarta.validation.Valid; | ||
| import org.example.alfs.dto.ticket.TicketCreateDTO; | ||
| import org.example.alfs.entities.Ticket; | ||
| import org.example.alfs.services.TicketService; | ||
| import org.springframework.stereotype.Controller; | ||
| import org.springframework.ui.Model; | ||
| import org.springframework.validation.BindingResult; | ||
| import org.springframework.web.bind.annotation.GetMapping; | ||
| import org.springframework.web.bind.annotation.ModelAttribute; | ||
| import org.springframework.web.bind.annotation.PostMapping; | ||
| import org.springframework.web.bind.annotation.RequestMapping; | ||
|
|
||
| @Controller | ||
| @RequestMapping | ||
| public class TicketController { | ||
|
|
||
| private final TicketService ticketService; | ||
|
|
||
| public TicketController(TicketService ticketService) { | ||
| this.ticketService = ticketService; | ||
|
|
||
| } | ||
|
|
||
| //create ticket | ||
| @GetMapping("/create") | ||
| public String createNewTicketForm(Model model) { | ||
| model.addAttribute("ticket", new TicketCreateDTO()); | ||
| return "create"; | ||
| } | ||
|
|
||
| //TODO REDIRECT, WHERE?? | ||
| @PostMapping("/create") | ||
| public String createNewTicket(@ModelAttribute("ticket") @Valid TicketCreateDTO ticketCreateDTO, BindingResult bindingResult) { | ||
| if (bindingResult.hasErrors()) { | ||
| return "create"; | ||
| } | ||
|
|
||
| ticketService.createNewTicket(ticketCreateDTO); | ||
|
|
||
| return "redirect:/home"; | ||
| } | ||
|
|
||
| //view ticket | ||
| //assign ticket | ||
| //update status | ||
| //create comment | ||
| //View comment | ||
| //upload attachment | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,28 @@ | ||
| package org.example.alfs.mapper; | ||
|
|
||
| import org.example.alfs.dto.ticket.TicketViewDTO; | ||
| import org.example.alfs.entities.Ticket; | ||
| import org.springframework.stereotype.Component; | ||
|
|
||
| @Component | ||
| public class TicketMapper { | ||
|
|
||
| public TicketViewDTO entityToViewDTO(Ticket ticket){ | ||
|
|
||
| TicketViewDTO ticketViewDTO = new TicketViewDTO(); | ||
|
|
||
| ticketViewDTO.setId(ticket.getId()); | ||
| ticketViewDTO.setTitle(ticket.getTitle()); | ||
| ticketViewDTO.setDescription(ticket.getDescription()); | ||
| ticketViewDTO.setStatus(ticket.getStatus()); | ||
| ticketViewDTO.setCreatedAt(ticket.getCreatedAt()); | ||
|
|
||
| if (ticket.getInvestigator() != null) { | ||
| ticketViewDTO.setAssignedInvestigatorId(ticket.getInvestigator().getId()); | ||
| } | ||
|
|
||
| return ticketViewDTO; | ||
| } | ||
|
|
||
|
|
||
| } |
34 changes: 34 additions & 0 deletions
34
src/main/java/org/example/alfs/services/TicketService.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,34 @@ | ||
| package org.example.alfs.services; | ||
|
|
||
| import org.example.alfs.dto.ticket.TicketCreateDTO; | ||
| import org.example.alfs.dto.ticket.TicketViewDTO; | ||
| import org.example.alfs.entities.Ticket; | ||
| import org.example.alfs.mapper.TicketMapper; | ||
| import org.example.alfs.repositories.TicketRepository; | ||
| import org.springframework.stereotype.Service; | ||
|
|
||
| @Service | ||
| public class TicketService { | ||
|
|
||
|
|
||
| private final TicketRepository ticketRepository; | ||
| private final TicketMapper ticketMapper; | ||
|
|
||
| public TicketService(TicketRepository ticketRepository, TicketMapper ticketMapper) { | ||
| this.ticketRepository = ticketRepository; | ||
| this.ticketMapper = ticketMapper; | ||
| } | ||
|
|
||
| //createNewTicket | ||
| public TicketViewDTO createNewTicket(TicketCreateDTO ticketCreateDTO) { | ||
|
|
||
| Ticket ticket = new Ticket(); | ||
|
|
||
| ticket.setTitle(ticketCreateDTO.getTitle()); | ||
| ticket.setDescription(ticketCreateDTO.getDescription()); | ||
|
|
||
| Ticket savedTicket = ticketRepository.save(ticket); | ||
|
|
||
| return ticketMapper.entityToViewDTO(savedTicket); | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.