Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,10 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-webmvc</artifactId>
</dependency>

<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-thymeleaf</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,11 +24,14 @@ public void run(String... args) {
return;
}

jdbcTemplate.update(
"""
INSERT INTO users (id, username, email, password, full_name, enabled, created_at)
VALUES (1, 'testuser', 'testuser@example.com', 'password123', 'Test User', true, CURRENT_TIMESTAMP)
"""
);
jdbcTemplate.update("""
INSERT INTO users (id, username, email, password, full_name, enabled, created_at)
VALUES
(1, 'user', 'user@example.com', 'password', 'user', true, CURRENT_TIMESTAMP),
(2, 'adamaj01', 'adamaj@example.com', 'password', 'Adam', true, CURRENT_TIMESTAMP),
(3, 'emmtra01', 'emmtra@example.com', 'password', 'Emma', true, CURRENT_TIMESTAMP),
(4, 'erifa101', 'erifa1@example.com', 'password', 'Erika', true, CURRENT_TIMESTAMP),
(5, 'johjan01', 'johjan@example.com', 'password', 'Johan', true, CURRENT_TIMESTAMP)
""");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package org.group1.projectbackend.controller.web;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;

@Controller
public class HomeController {

@GetMapping("/")
public String home() {
return "index";
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@
package org.group1.projectbackend.controller.web;

import jakarta.validation.Valid;
import java.security.Principal;
import org.group1.projectbackend.dto.comment.CreateCommentDto;
import org.group1.projectbackend.dto.ticket.CreateTicketRequest;
import org.group1.projectbackend.dto.ticket.TicketResponse;
import org.group1.projectbackend.dto.ticket.UpdateTicketStatusRequest;
import org.group1.projectbackend.entity.User;
import org.group1.projectbackend.entity.enums.TicketPriority;
import org.group1.projectbackend.entity.enums.TicketStatus;
import org.group1.projectbackend.exception.ResourceNotFoundException;
import org.group1.projectbackend.repository.UserRepository;
import org.group1.projectbackend.service.CommentService;
import org.group1.projectbackend.service.SupportTicketService;
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.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class TicketViewController {

private final SupportTicketService supportTicketService;
private final CommentService commentService;
private final UserRepository userRepository;

public TicketViewController(
SupportTicketService supportTicketService,
CommentService commentService,
UserRepository userRepository
) {
this.supportTicketService = supportTicketService;
this.commentService = commentService;
this.userRepository = userRepository;
}

@GetMapping("/tickets")
public String listTickets(Model model) {
model.addAttribute("tickets", supportTicketService.getAllTickets());
return "tickets/list";
}

@GetMapping("/tickets/{id}")
public String showTicket(@PathVariable Long id, Model model) {
model.addAttribute("ticket", supportTicketService.getTicketById(id));
model.addAttribute("comments", commentService.getCommentsBySupportTicketId(id, "asc"));
model.addAttribute("statuses", TicketStatus.values());
return "tickets/detail";
}

@GetMapping("/tickets/new")
public String showCreateTicketForm(Model model) {
model.addAttribute("createTicketRequest", new CreateTicketRequest("", "", null));
model.addAttribute("priorities", TicketPriority.values());
return "tickets/new";
}

@PostMapping("/tickets")
public String createTicket(
Principal principal,
@Valid @ModelAttribute CreateTicketRequest request,
BindingResult bindingResult,
Model model
) {
if (bindingResult.hasErrors()) {
model.addAttribute("priorities", TicketPriority.values());
return "tickets/new";
}

TicketResponse ticket = supportTicketService.createTicket(principal.getName(), request);
Comment thread
VonAdamo marked this conversation as resolved.

return "redirect:/tickets/" + ticket.id();
}

@PostMapping("/tickets/{id}/comments")
public String createComment(
@PathVariable Long id,
@RequestParam String content,
Principal principal
) {
User user = userRepository.findByUsername(principal.getName())
.orElseThrow(() -> new ResourceNotFoundException("User not found with username: " + principal.getName()));

CreateCommentDto comment = new CreateCommentDto();
comment.setContent(content);
comment.setSupportTicketId(id);
comment.setUserId(user.getId());

commentService.createComment(comment);
Comment thread
VonAdamo marked this conversation as resolved.

return "redirect:/tickets/" + id;
}

@PostMapping("/tickets/{id}/status")
public String updateTicketStatus(
@PathVariable Long id,
@RequestParam TicketStatus status
) {
supportTicketService.updateStatus(id, new UpdateTicketStatusRequest(status));

return "redirect:/tickets/" + id;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,5 +13,7 @@ public interface SupportTicketService {

TicketResponse updateStatus(Long ticketId, UpdateTicketStatusRequest request);

List<TicketResponse> getAllTickets();

List<TicketResponse> getTicketsForUser(Long userId);
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,11 @@ public TicketResponse updateStatus(Long ticketId, UpdateTicketStatusRequest requ
return SupportTicketMapper.toResponse(supportTicketRepository.save(ticket));
}

@Override
public List<TicketResponse> getAllTickets() {
return SupportTicketMapper.toResponseList(supportTicketRepository.findAll());
}

@Override
public List<TicketResponse> getTicketsForUser(Long userId) {
return SupportTicketMapper.toResponseList(supportTicketRepository.findByCreatedById(userId));
Expand Down
5 changes: 5 additions & 0 deletions src/main/resources/application.properties
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ spring.jpa.properties.hibernate.jdbc.time_zone=UTC
spring.flyway.baseline-on-migrate=true
spring.flyway.baseline-version=0

spring.web.resources.cache.period=0
spring.web.resources.chain.cache=false

spring.thymeleaf.cache=false

storage.s3.endpoint=${STORAGE_S3_ENDPOINT:}
storage.s3.region=${STORAGE_S3_REGION:us-east-1}
storage.s3.access-key=${STORAGE_S3_ACCESS_KEY:}
Expand Down
Loading