Skip to content
Open
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
21 changes: 14 additions & 7 deletions docs/NEW_MODULE_TEMPLATE.md
Original file line number Diff line number Diff line change
Expand Up @@ -67,11 +67,14 @@ import java.util.stream.Collectors;
@Service
public class CheckinService {

@Autowired
private CheckinRepository checkinRepo;
private final CheckinRepository checkinRepo;
private final StudentRepository studentRepo;

@Autowired
private StudentRepository studentRepo;
public CheckinService(CheckinRepository checkinRepo, StudentRepository studentRepo) {
this.checkinRepo = checkinRepo;
this.studentRepo = studentRepo;
}

public Checkin save(Checkin checkin) {
if (checkin.getDate() == null) {
Expand Down Expand Up @@ -130,8 +133,12 @@ import java.util.List;
@RequestMapping("/checkin")
public class CheckinController {

private final CheckinService checkinService;

@Autowired
private CheckinService checkinService;
public CheckinController(CheckinService checkinService) {
this.checkinService = checkinService;
}

@GetMapping("/")
public String home(ModelMap model) {
Expand Down Expand Up @@ -198,7 +205,7 @@ public class CheckinController {

- Use `checkin/read.html` as a resource, not a template

```HTML
```HTML
<!DOCTYPE html>
<html xmlns:th="http://thymeleaf.org">
<div th:replace="~{fragments/head :: head(${pageTitle})}"></div>
Expand Down Expand Up @@ -242,7 +249,7 @@ public class CheckinController {
<td><span th:text="${checkin.codingType}"></span></td>
<td><span th:text="${checkin.issueNumber}"></span></td>
<td><a th:href="@{/checkin/update/{checkinId}(checkinId=${checkin.id})}">
<span><svg xmlns="http://www.w3.org/2000/svg" width="16"
<span><svg xmlns="http://www.w3.org/2000/svg" width="16"
height="16" fill="currentColor" class="bi bi-view-list"
viewBox="0 0 16 16">
<path
Expand Down Expand Up @@ -469,4 +476,4 @@ public class CheckinController {



```
```
19 changes: 10 additions & 9 deletions src/main/java/com/coderscampus/cp/service/CheckinService.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,16 +15,16 @@
@Service
public class CheckinService {

@Autowired
private CheckinRepository checkinRepo;
private final CheckinRepository checkinRepo;
private final StudentRepository studentRepo;

@Autowired
private StudentRepository studentRepo;
public CheckinService(CheckinRepository checkinRepo, StudentRepository studentRepo) {
this.checkinRepo = checkinRepo;
this.studentRepo = studentRepo;
}

public Checkin saveByUid(Checkin checkin, String uid) {
// if (checkinRepo.findByUid(uid) == null) {
// checkin.setDate(Instant.now());
// }
setDateIfNull(checkin);
setStudentAndUid(checkin, uid);
return checkinRepo.save(checkin);
Expand All @@ -45,7 +45,8 @@ private void setDateIfNull(Checkin checkin) {
}

public List<Checkin> findAll() {
return checkinRepo.findAll().stream().sorted(Comparator.comparing(Checkin::getDate).reversed()).collect(Collectors.toList());
return checkinRepo.findAll().stream().sorted(Comparator.comparing(Checkin::getDate).reversed())
.collect(Collectors.toList());
}

public Checkin findById(Long id) {
Expand All @@ -57,7 +58,7 @@ public void delete(Checkin checkin) {
}

public List<Checkin> findByUid(String uid) {
return checkinRepo.findByUid(uid).stream().sorted(Comparator.comparing(Checkin::getDate).reversed()).collect(Collectors.toList());
return checkinRepo.findByUid(uid).stream().sorted(Comparator.comparing(Checkin::getDate).reversed())
.collect(Collectors.toList());
}
}

Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,12 @@
@Service
public class CodingCategoryService {

private final CodingCategoryRepository codingCategoryRepo;

@Autowired
private CodingCategoryRepository codingCategoryRepo;
public CodingCategoryService(CodingCategoryRepository codingCategoryRepo) {
this.codingCategoryRepo = codingCategoryRepo;
}

public CodingCategory save(CodingCategory codingCategory) {
return codingCategoryRepo.save(codingCategory);
Expand Down
9 changes: 6 additions & 3 deletions src/main/java/com/coderscampus/cp/service/FoobarService.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,14 @@
@Service
public class FoobarService {

@Autowired
private FoobarRepository foobarRepo;
private final FoobarRepository foobarRepo;
private final StudentRepository studentRepo;

@Autowired
private StudentRepository studentRepo;
public FoobarService(FoobarRepository foobarRepo, StudentRepository studentRepo) {
this.foobarRepo = foobarRepo;
this.studentRepo = studentRepo;
}

public Foobar save(Foobar foobar) {
System.out.println("FoobarService.java save method| Foobar is: " + foobar);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
@Service
public class SpringProjectService {

private final SpringProjectRepository springRepo;

@Autowired
SpringProjectRepository springRepo;
public SpringProjectService(SpringProjectRepository springRepo) {
this.springRepo = springRepo;
}

public List<SpringProject> findAll() {
return springRepo.findAll();
Expand All @@ -22,4 +26,3 @@ public Optional<SpringProject> findById(Long springProjectId) {
return springRepo.findById(springProjectId);
}
}

8 changes: 6 additions & 2 deletions src/main/java/com/coderscampus/cp/service/StudentService.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,12 @@
@Service
public class StudentService {

private final StudentRepository studentRepo;

@Autowired
private StudentRepository studentRepo;
public StudentService(StudentRepository studentRepo) {
this.studentRepo = studentRepo;
}

public void save(Student student) {
if (isValidNewStudent(student)) {
Expand All @@ -25,6 +29,7 @@ public void save(Student student) {
studentRepo.save(student);
}
}

@Transactional
public StudentDTO saveByUid(Student student, String uid) {
Student foundStudent = studentRepo.findByUid(uid);
Expand All @@ -37,7 +42,6 @@ public StudentDTO saveByUid(Student student, String uid) {
return returnStudent;
}


boolean doesStudentExistInRepository(Student student) {
Optional<Student> existingStudent = studentRepo.findById(student.getId());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
@Service
public class UserHistoryService {

private final UserHistoryRepository userHistoryRepo;

@Autowired
private UserHistoryRepository userHistoryRepo;
public UserHistoryService(UserHistoryRepository userHistoryRepo) {
this.userHistoryRepo = userHistoryRepo;
}

public UserHistory save(UserHistory userHistory) {
if (userHistory.getDate() == null) {
Expand All @@ -24,7 +28,8 @@ public UserHistory save(UserHistory userHistory) {
}

public List<UserHistory> findAll() {
return userHistoryRepo.findAll().stream().sorted(Comparator.comparing(UserHistory::getDate).reversed()).collect(Collectors.toList());
return userHistoryRepo.findAll().stream().sorted(Comparator.comparing(UserHistory::getDate).reversed())
.collect(Collectors.toList());
}

public UserHistory findById(Long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,13 @@
@Controller
@RequestMapping("/activityLog")
public class ActivityLogController {

private final ActivityLogService activityLogService;

@Autowired
private ActivityLogService activityLogService;
public ActivityLogController(ActivityLogService activityLogService) {
this.activityLogService = activityLogService;
}

@PostMapping("/create")
public String postCreate(ActivityLog activityLog, @RequestParam("uid") String uid) {
Expand Down
11 changes: 9 additions & 2 deletions src/main/java/com/coderscampus/cp/web/CheckinController.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import com.coderscampus.cp.domain.Checkin;
import com.coderscampus.cp.service.CheckinService;
import jakarta.servlet.http.HttpSession;

import org.hibernate.annotations.DialectOverride.Check;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
Expand All @@ -15,8 +17,12 @@
@RequestMapping("/checkin")
public class CheckinController {

private final CheckinService checkinService;

@Autowired
private CheckinService checkinService;
public CheckinController(CheckinService checkinService) {
this.checkinService = checkinService;
}

@GetMapping("/")
public String home(ModelMap model, HttpSession httpSession) {
Expand Down Expand Up @@ -55,7 +61,8 @@ public String fetch(ModelMap model, @PathVariable Long id) {
}

@PostMapping("/update/{id}")
public String update(@ModelAttribute("checkin") Checkin checkin, @ModelAttribute("activityLog") ActivityLog activityLog) {
public String update(@ModelAttribute("checkin") Checkin checkin,
@ModelAttribute("activityLog") ActivityLog activityLog) {
checkin.getActivityLog().add(activityLog);
return "redirect:/checkin/";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
@RequestMapping("coding-category")
public class CodingCategoryController {

private final CodingCategoryService codingCategoryService;

@Autowired
private CodingCategoryService codingCategoryService;
public CodingCategoryController(CodingCategoryService codingCategoryService) {
this.codingCategoryService = codingCategoryService;
}

@GetMapping("/")
public String home(ModelMap model) {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/coderscampus/cp/web/FoobarController.java
Original file line number Diff line number Diff line change
Expand Up @@ -13,8 +13,12 @@
@RequestMapping("/foobar")
public class FoobarController {

private final FoobarService foobarService;

@Autowired
private FoobarService foobarService;
public FoobarController(FoobarService foobarService) {
this.foobarService = foobarService;
}

@GetMapping("/")
public String home(ModelMap model) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,12 @@
@RequestMapping("/user-history")
public class UserHistoryController {

private final UserHistoryService userHistoryService;

@Autowired
private UserHistoryService userHistoryService;
public UserHistoryController(UserHistoryService userHistoryService) {
this.userHistoryService = userHistoryService;
}

@GetMapping("/")
public String home(ModelMap model) {
Expand All @@ -43,7 +47,6 @@ public String create(UserHistory userHistory) {
return "redirect:/user-history/";
}


@GetMapping("/update/{id}")
public String fetch(ModelMap model, @PathVariable Long id) {
UserHistory userHistory = userHistoryService.findById(id);
Expand Down
Loading