Skip to content
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

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open

Add/post/endpoint #109

wants to merge 3 commits into from

Conversation

olegLevochkin
Copy link
Collaborator

No description provided.

@olegLevochkin olegLevochkin linked an issue Apr 5, 2021 that may be closed by this pull request
@Id
@GeneratedValue(strategy = GenerationType.AUTO)
@Column(name = "POST_ID")
private Integer id;
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Long


@Setter
@Getter
@NoArgsConstructor
Copy link
Owner

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;
Copy link
Owner

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> {
Copy link
Owner

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")
Copy link
Owner

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()
Copy link
Owner

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())) {
Copy link
Owner

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) {
Copy link
Owner

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) {
Copy link
Owner

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);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

givenPost

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add comments endpoint
2 participants