-
Notifications
You must be signed in to change notification settings - Fork 1
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
Add/post/endpoint #109
base: master
Are you sure you want to change the base?
Add/post/endpoint #109
Conversation
@Id | ||
@GeneratedValue(strategy = GenerationType.AUTO) | ||
@Column(name = "POST_ID") | ||
private Integer id; |
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.
Long
|
||
@Setter | ||
@Getter | ||
@NoArgsConstructor |
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.
Check User
private String description; | ||
|
||
@Column(name = "COMMENT", nullable = false) | ||
private String comment; |
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.
comments
import com.kpi.project.model.post.Post; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface PostRepository extends JpaRepository<Post, Long> { |
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.
Does it work?
@@ -37,6 +38,13 @@ public UserResource(UserService userService) { | |||
return ResponseEntity.ok(user); | |||
} | |||
|
|||
@PutMapping("/user/add/post") |
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.
/user/post/add
: new HashSet<>(); | ||
updatedPost.add(newPost); | ||
|
||
final User userWithNewPost = userFromToken.toBuilder() |
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.
seems its redundant code, after saving post with user
@@ -60,6 +61,18 @@ public void validateFriendToAdd(User friend, String friendName) { | |||
} | |||
} | |||
|
|||
public void validatePostToAdd(Post post) { | |||
if (StringUtils.isBlank(post.getImageURL())) { |
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.
Posts can be without image
@@ -60,6 +61,18 @@ public void validateFriendToAdd(User friend, String friendName) { | |||
} | |||
} | |||
|
|||
public void validatePostToAdd(Post post) { |
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.
What about dto?
if (StringUtils.isBlank(post.getDescription())) { | ||
throw new ValidatorException("Description should be present"); | ||
} | ||
if (post.getAuthor() == null) { |
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.
Change to dto with userID
// given | ||
final UserDto givenUserDto = givenUserDto(userDtoBuilder -> userDtoBuilder.friends(Collections.singleton(User.builder().username("newFriend").build()))); | ||
final User givenUser = givenUser(identity()); | ||
final Post newPost = new Post("imageURL", "description", "comment", givenUser); |
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.
givenPost
No description provided.