nVarap / CSABlog

A CSA Blog for a CSA Student
MIT License
0 stars 0 forks source link

Extra - Student Teaching Pt 2 #8

Open nVarap opened 8 months ago

nVarap commented 8 months ago

Extra. Discuss a key learning or journey you experienced as a result of student lessons. Describe something from lessons that you plan to user or apply in future project.

One key learning journey I experienced through the student lessons was the creation and application of an admin panel in spring. In trimester 1, I did not use spring that much, if at all, as we switched part way through to a different framework. This meant I was actually less knowledgable about the basics of spring going into the lessons. Thus, throughout these lessons I made it a point to pay attention throughout the spring lessons. I had vague ideas of what Thymeleaf was, and same with JWT, but I didn't know how I could complete them. Throughout the two lessons, one I learned from and one I taught, I gained knowledge about how useful an admin panel that displays all data related to the system can be, and how it can be created by sending JWT tokens and/or storing these JWT tokens in cookies in order to ensure their access throughout the system. The reason I taught a lot during my section about login redirection is because as I was researching that alongside the rest of the JWT research, I found myself growing really interested in the concepts. Similarly with Thymeleaf, I noticed the huge advantage server-side requests had, and that these requests could make management of the system easier than making many different postman requests to the server. So much so I'd like to think I went above and beyond, with the thymeleaf section in particular allowing the display of jokes, but also an easy-to-parse UI that changes color depending on whether the jokes are funny or not.

Controller (Thymeleaf)

package com.nighthawk.spring_portfolio.controllers;

import java.util.List;
import java.util.ArrayList;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;

import com.nighthawk.spring_portfolio.mvc.jokes.JokesJpaRepository;
import com.nighthawk.spring_portfolio.mvc.jokes.Jokes;

@Controller
public class HelloController {

    @Autowired
    private JokesJpaRepository repository;

    @GetMapping("/hello")
    public String hello(Model model) {
        List<Jokes> jokes = repository.findAll();
        model.addAttribute("jokes", jokes);

        return "thyme"; // This corresponds to the Thymeleaf template name (src/main/resources/templates/hello.html)
    }
}

Page

<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.thymeleaf.org">

<head>
    <meta charset="UTF-8">
    <title>Jokes!</title>
</head>

<body style="background-color: aqua;">
    <h1> Jokes! </h1>
    <div th:each="j : ${jokes}">
        <div th:style="${j.haha &gt; j.boohoo ? 'background-color: #90EE90; border: 5px solid black;' : 'background-color: #FFB3B2; border: 5px solid black;'}">
            <p th:text="${j.joke}"></p>
            <p>Upvotes: <span th:text="${j.haha}"></span>
            <p>Downvotes: <span th:text="${j.boohoo}"></span>
        </div>
    </div>
</body>

</html>

Final Product

scrn