-
Notifications
You must be signed in to change notification settings - Fork 0
Product reviews branch #14
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -29,6 +29,19 @@ | |
| <scope>provided</scope> | ||
| </dependency> | ||
|
|
||
| <!-- https://mvnrepository.com/artifact/org.springframework.boot/spring-boot-starter-data-jpa --> | ||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-data-jpa</artifactId> | ||
| <version>3.2.4</version> | ||
| </dependency> | ||
| <!-- https://mvnrepository.com/artifact/org.postgresql/postgresql --> | ||
| <dependency> | ||
| <groupId>org.postgresql</groupId> | ||
| <artifactId>postgresql</artifactId> | ||
| <version>42.7.3</version> | ||
| </dependency> | ||
|
|
||
| <dependency> | ||
| <groupId>org.springframework.boot</groupId> | ||
| <artifactId>spring-boot-starter-test</artifactId> | ||
|
|
@@ -41,6 +54,11 @@ | |
| <artifactId>spring-boot-starter-thymeleaf</artifactId> | ||
| <version>3.2.4</version> | ||
| </dependency> | ||
| <dependency> | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we already have this in the project |
||
| <groupId>org.springframework.data</groupId> | ||
| <artifactId>spring-data-jpa</artifactId> | ||
| <version>3.2.4</version> | ||
| </dependency> | ||
|
|
||
|
|
||
| </dependencies> | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,22 +1,21 @@ | ||
| package com.example.demo1.model; | ||
|
|
||
| import lombok.AllArgsConstructor; | ||
| import lombok.Builder; | ||
| import jakarta.persistence.*; | ||
| import lombok.Data; | ||
| import lombok.Getter; | ||
| import lombok.experimental.SuperBuilder; | ||
|
|
||
| import java.time.LocalDate; | ||
| import java.util.Date; | ||
| import java.time.LocalDateTime; | ||
|
|
||
| @Entity | ||
| @Table(name = "reviews") | ||
| @Data | ||
| @SuperBuilder | ||
| public class Review { | ||
| private int id; | ||
|
|
||
| @GeneratedValue(strategy = GenerationType.IDENTITY) | ||
| @Id | ||
| private Integer id; | ||
| private String reviewMsg; | ||
| private LocalDate date; | ||
|
|
||
| private LocalDateTime date; | ||
| private String userName; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This should be a User entrity and a relation like ManyToOne |
||
|
|
||
| public Review() { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. you can use lomboks' @DaTa |
||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,31 @@ | ||
| package com.example.demo1.model.dto; | ||
|
|
||
| import com.example.demo1.model.Review; | ||
| import lombok.Data; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Data | ||
| public class ReviewDto { | ||
| private String reviewMsg; | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. these fields should be validated (maybe @NotNull or minimum size?) |
||
| private LocalDateTime date; | ||
| private String userName; | ||
|
|
||
| public Review toObject(ReviewDto reviewDto) { | ||
| Review review = new Review(); | ||
| review.setReviewMsg(reviewDto.getReviewMsg()); | ||
| review.setDate(reviewDto.getDate()); | ||
| review.setUserName(reviewDto.getUserName()); | ||
| return review; | ||
| } | ||
|
|
||
| public ReviewDto toDto(Review review) { | ||
| ReviewDto reviewDto = new ReviewDto(); | ||
| reviewDto.setReviewMsg(review.getReviewMsg()); | ||
| reviewDto.setDate(review.getDate()); | ||
| reviewDto.setUserName(review.getUserName()); | ||
| return reviewDto; | ||
|
|
||
| } | ||
| // BeanUtils.copyProperties(delivery, deliveryDto); | ||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.example.demo1.model.dto; | ||
|
|
||
| import com.example.demo1.model.Review; | ||
| import lombok.Data; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Data | ||
| public class ReviewReturnDto { | ||
| private Integer id; | ||
| private String reviewMsg; | ||
| private LocalDateTime date; | ||
| private String userName; | ||
|
|
||
| public static Review toObject(ReviewReturnDto reviewDto) { | ||
| Review review = new Review(); | ||
| review.setId(reviewDto.getId()); | ||
| review.setReviewMsg(reviewDto.getReviewMsg()); | ||
| review.setDate(reviewDto.getDate()); | ||
| review.setUserName(reviewDto.getUserName()); | ||
| return review; | ||
|
|
||
| } | ||
|
|
||
| public static ReviewReturnDto toDto(Review review) { | ||
| ReviewReturnDto reviewDto = new ReviewReturnDto(); | ||
| reviewDto.setId(review.getId()); | ||
| reviewDto.setReviewMsg(review.getReviewMsg()); | ||
| reviewDto.setDate(review.getDate()); | ||
| reviewDto.setUserName(review.getUserName()); | ||
| return reviewDto; | ||
| } | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,33 @@ | ||
| package com.example.demo1.model.dto; | ||
|
|
||
| import com.example.demo1.model.Review; | ||
| import lombok.Data; | ||
|
|
||
| import java.time.LocalDateTime; | ||
|
|
||
| @Data | ||
| public class ReviewUpdateDto { | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. validation |
||
| private Integer id; | ||
| private String reviewMsg; | ||
| private LocalDateTime date; | ||
| private String userName; | ||
|
|
||
| public static Review toObject(ReviewUpdateDto reviewDto) { | ||
| Review review = new Review(); | ||
| review.setId(reviewDto.getId()); | ||
| review.setReviewMsg(reviewDto.getReviewMsg()); | ||
| review.setDate(reviewDto.getDate()); | ||
| review.setUserName(reviewDto.getUserName()); | ||
| return review; | ||
|
|
||
| } | ||
|
|
||
| public static ReviewUpdateDto toDto(Review review) { | ||
| ReviewUpdateDto reviewDto = new ReviewUpdateDto(); | ||
| reviewDto.setId(review.getId()); | ||
| reviewDto.setReviewMsg(review.getReviewMsg()); | ||
| reviewDto.setDate(review.getDate()); | ||
| reviewDto.setUserName(review.getUserName()); | ||
| return reviewDto; | ||
| } | ||
| } | ||
This file was deleted.
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| package com.example.demo1.repository; | ||
|
|
||
|
|
||
| import com.example.demo1.model.Review; | ||
| import org.springframework.data.jpa.repository.JpaRepository; | ||
| import org.springframework.stereotype.Repository; | ||
|
|
||
| import java.util.List; | ||
|
|
||
| @Repository | ||
| public interface ReviewsRepository extends JpaRepository<Review, Integer> { | ||
| List<Review> getAllByUser(String userName); | ||
|
|
||
| void deleteAllByUser(String userName); | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. deleteAllByUser_name or something similar will work but you need to have the OneToOne/ OneToMany relation set up correctly |
||
| } | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,15 @@ | ||
| spring.application.name=demo1 | ||
| server.port=8080 | ||
| service.version=not set | ||
| language=not set | ||
| numbers.separator=n | ||
|
|
||
| logging.level.root=info | ||
|
Owner
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. don't commit this file :) git rm --cached |
||
|
|
||
| ##TODO install postgres, create database eshop, set user postgres password | ||
|
|
||
| spring.datasource.url=jdbc:postgresql://localhost:5432/eshop | ||
| spring.datasource.username=postgres | ||
| spring.datasource.password=1897 | ||
| spring.jpa.hibernate.ddl-auto=update | ||
| spring.jpa.hibernate.show-sql=true | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
we already have this