7월, 2024의 게시물 표시

BE Study 8th

 Let's take a look at JPA through looking into Post.java @Entity @Table(name = "posts") @Entity is an annotation that enables the following class to be mapped with a table of DB. @Table is an annotation that designates which table the entity will be mapped to. It has parameters like  name: designates the name of the table to which entity will be mapped, uses entity's name if not given. catalog: map catalog schema: map schema uniqueContraints: generate unique constraints if use DDL public class Post { defines the class     @Id     @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "post_id_generator")     @SequenceGenerator(name = "post_id_generator", sequenceName = "post_id_seq", allocationSize = 5) @Id means that the following attribute will be the primary key of the table. @GeneratedValue is the value that uses other strategies to define primary key like strategy = GenerationType.IDENTITY: this uses 'AUTO_INCREMENT'...

BE Study 7th

Let's take a look at test codes. package com.sivalabs.techbuzz.posts.web.controllers; import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; import com.sivalabs.techbuzz.common.AbstractIntegrationTest; import org.junit.jupiter.api.Test; class HomeControllerTest extends AbstractIntegrationTest {     @Test     void shouldHomePageWithCategoriesList() throws Exception {         mockMvc.perform(get("/"))                 .andExpect(status().isOk())                 .andExpect(view().name("posts/home"))                 .andExpect(model().attributeExi...

BE Study 6th

 HomeController was too basic. Let's take a look at harder one: CreatePostController It must be a controller about creating a post. @Controller @Loggable @Controller is an annotation that tells this is a controller and @Loggable is an annotation that enables logging of this class. public class CreatePostController { defining this class CreatePostController     private static final Logger log = LoggerFactory.getLogger(CreatePostController.class); Logger Declaration.     private static final String MODEL_ATTRIBUTE_POST = "post";     private final PostService postService; Attributes of the class. Let's see how does it work.     public CreatePostController(PostService postService) {         this.postService = postService;     } Consturctor.     @GetMapping("/posts/new") Mapping for Get, url of /posts/new     @AnyAuthenticatedUser Guess this is an custom annotation. There is a file named AnyAuthent...

Design Patterns

이미지
 1. State 'State' Pattern is used to implement 'Finite State Model' of discrete mathematics. Finite State Model is a model that has 1. finite numbers of states 2. there are available actions for each states and state changes through those actions. For example, we can have an example like 'Aegislash' of Pokemon. Aegislash is a Pokemon that its form changes with its move. It has two different forms, swords form and shield form, and let's suppose that it has three different moves: swords dance, king shield, and shadow claw. To implement this pattern, you have look into 3 different steps. 1. make an interface for the 'State' having corresponding methods for each action. interface AegislashForm() {     void swords_dance();     void king_shield();     void shadow_claw(); } 2. make each specific 'State' implement the the interface of 'State' of 1. Each state should have the entity(the machine) as its attribute, and have to override(implemen...