-
Notifications
You must be signed in to change notification settings - Fork 0
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
Backlogitem and comment crud #12
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
938605d
BacklogItemComment CRUD
Higunio320 01622fb
BacklogItem CRUD and improved exceptions
Higunio320 07a41db
Minor changes and added some tests
Higunio320 f8a3fbe
Finished tests for backlogItemComment
Higunio320 3ebccc1
Applied requested changes
Higunio320 735db15
Merge branch 'main' into backlogitem-and-comment-crud
Higunio320 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
61 changes: 61 additions & 0 deletions
61
.../main/java/dev/corn/cornbackend/api/backlog/comment/BacklogItemCommentControllerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
package dev.corn.cornbackend.api.backlog.comment; | ||
|
||
import dev.corn.cornbackend.api.backlog.comment.data.BacklogItemCommentRequest; | ||
import dev.corn.cornbackend.api.backlog.comment.data.BacklogItemCommentResponse; | ||
import dev.corn.cornbackend.api.backlog.comment.interfaces.BacklogItemCommentController; | ||
import dev.corn.cornbackend.api.backlog.comment.interfaces.BacklogItemCommentService; | ||
import dev.corn.cornbackend.entities.user.User; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import static dev.corn.cornbackend.api.backlog.comment.constants.BacklogItemCommentMappings.BACKLOG_ITEM_COMMENT_ADD_MAPPING; | ||
import static dev.corn.cornbackend.api.backlog.comment.constants.BacklogItemCommentMappings.BACKLOG_ITEM_COMMENT_API_MAPPING; | ||
import static dev.corn.cornbackend.api.backlog.comment.constants.BacklogItemCommentMappings.BACKLOG_ITEM_COMMENT_DELETE_MAPPING; | ||
import static dev.corn.cornbackend.api.backlog.comment.constants.BacklogItemCommentMappings.BACKLOG_ITEM_COMMENT_GET_MAPPING; | ||
import static dev.corn.cornbackend.api.backlog.comment.constants.BacklogItemCommentMappings.BACKLOG_ITEM_COMMENT_UPDATE_MAPPING; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping(BACKLOG_ITEM_COMMENT_API_MAPPING) | ||
public class BacklogItemCommentControllerImpl implements BacklogItemCommentController { | ||
|
||
private final BacklogItemCommentService backlogItemCommentService; | ||
|
||
@Override | ||
@PostMapping(BACKLOG_ITEM_COMMENT_ADD_MAPPING) | ||
public final BacklogItemCommentResponse addNewComment( | ||
@RequestBody BacklogItemCommentRequest request, | ||
@AuthenticationPrincipal User user) { | ||
return backlogItemCommentService.addNewComment(request, user); | ||
} | ||
|
||
@Override | ||
@PutMapping(BACKLOG_ITEM_COMMENT_UPDATE_MAPPING) | ||
public BacklogItemCommentResponse updateComment( | ||
@RequestParam long commentId, | ||
@RequestBody String comment) { | ||
return backlogItemCommentService.updateComment(commentId, comment); | ||
} | ||
|
||
@Override | ||
@DeleteMapping(BACKLOG_ITEM_COMMENT_DELETE_MAPPING) | ||
public BacklogItemCommentResponse deleteComment(@RequestParam long commentId) { | ||
return backlogItemCommentService.deleteComment(commentId); | ||
} | ||
|
||
@Override | ||
@GetMapping(BACKLOG_ITEM_COMMENT_GET_MAPPING) | ||
public BacklogItemCommentResponse getComment(@RequestParam long commentId) { | ||
return backlogItemCommentService.getComment(commentId); | ||
} | ||
|
||
|
||
} |
101 changes: 101 additions & 0 deletions
101
...src/main/java/dev/corn/cornbackend/api/backlog/comment/BacklogItemCommentServiceImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,101 @@ | ||
package dev.corn.cornbackend.api.backlog.comment; | ||
|
||
import dev.corn.cornbackend.api.backlog.comment.data.BacklogItemCommentRequest; | ||
import dev.corn.cornbackend.api.backlog.comment.data.BacklogItemCommentResponse; | ||
import dev.corn.cornbackend.api.backlog.comment.interfaces.BacklogItemCommentService; | ||
import dev.corn.cornbackend.entities.backlog.comment.BacklogItemComment; | ||
import dev.corn.cornbackend.entities.backlog.comment.interfaces.BacklogItemCommentMapper; | ||
import dev.corn.cornbackend.entities.backlog.comment.interfaces.BacklogItemCommentRepository; | ||
import dev.corn.cornbackend.entities.backlog.item.BacklogItem; | ||
import dev.corn.cornbackend.entities.backlog.item.interfaces.BacklogItemRepository; | ||
import dev.corn.cornbackend.entities.user.User; | ||
import dev.corn.cornbackend.utils.exceptions.backlog.item.BacklogItemNotFoundException; | ||
import dev.corn.cornbackend.utils.exceptions.backlog.item.comment.BacklogItemCommentNotFoundException; | ||
import lombok.RequiredArgsConstructor; | ||
import lombok.extern.slf4j.Slf4j; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@Slf4j | ||
@RequiredArgsConstructor | ||
public class BacklogItemCommentServiceImpl implements BacklogItemCommentService { | ||
|
||
private final BacklogItemCommentRepository backlogItemCommentRepository; | ||
|
||
private final BacklogItemRepository backlogItemRepository; | ||
|
||
private final BacklogItemCommentMapper backLogItemCommentMapper; | ||
|
||
private static final String BACKLOG_ITEM_NOT_FOUND_MESSAGE = "Backlog item not found"; | ||
|
||
private static final String RETURNING_RESPONSE_FOR = "Returning response for: {}"; | ||
|
||
private static final String GETTING_BACKLOG_ITEM_COMMENT_OF_ID = "Getting backlogItemComment of id: {}"; | ||
|
||
@Override | ||
public final BacklogItemCommentResponse addNewComment(BacklogItemCommentRequest request, User user) { | ||
log.info("Getting backlogItem of id: {}", request.backlogItemId()); | ||
|
||
BacklogItem item = backlogItemRepository.findById(request.backlogItemId()) | ||
.orElseThrow(() -> new BacklogItemNotFoundException(BACKLOG_ITEM_NOT_FOUND_MESSAGE)); | ||
|
||
log.info("Building and saving new backlogItemComment for request: {} and user: {}", request, user); | ||
|
||
BacklogItemComment comment = BacklogItemComment | ||
.builder() | ||
.comment(request.comment()) | ||
.backlogItem(item) | ||
.user(user) | ||
.build(); | ||
|
||
BacklogItemComment savedComment = backlogItemCommentRepository.save(comment); | ||
|
||
log.info(RETURNING_RESPONSE_FOR, savedComment); | ||
|
||
return backLogItemCommentMapper.toBacklogItemCommentResponse(savedComment); | ||
} | ||
|
||
@Override | ||
public final BacklogItemCommentResponse updateComment(long commentId, String comment) { | ||
log.info(GETTING_BACKLOG_ITEM_COMMENT_OF_ID, commentId); | ||
|
||
BacklogItemComment backlogItemComment = backlogItemCommentRepository.findById(commentId) | ||
.orElseThrow(() -> new BacklogItemCommentNotFoundException(BACKLOG_ITEM_NOT_FOUND_MESSAGE)); | ||
|
||
backlogItemComment.setComment(comment); | ||
|
||
BacklogItemComment savedComment = backlogItemCommentRepository.save(backlogItemComment); | ||
|
||
log.info(RETURNING_RESPONSE_FOR, savedComment); | ||
|
||
return backLogItemCommentMapper.toBacklogItemCommentResponse(savedComment); | ||
} | ||
|
||
@Override | ||
public final BacklogItemCommentResponse deleteComment(long commentId) { | ||
log.info(GETTING_BACKLOG_ITEM_COMMENT_OF_ID, commentId); | ||
|
||
BacklogItemComment backlogItemComment = backlogItemCommentRepository.findById(commentId) | ||
.orElseThrow(() -> new BacklogItemCommentNotFoundException(BACKLOG_ITEM_NOT_FOUND_MESSAGE)); | ||
|
||
log.info("Deleting backlogItemComment of id: {}", commentId); | ||
|
||
backlogItemCommentRepository.delete(backlogItemComment); | ||
|
||
log.info(RETURNING_RESPONSE_FOR, backlogItemComment); | ||
|
||
return backLogItemCommentMapper.toBacklogItemCommentResponse(backlogItemComment); | ||
} | ||
|
||
@Override | ||
public final BacklogItemCommentResponse getComment(long commentId) { | ||
log.info(GETTING_BACKLOG_ITEM_COMMENT_OF_ID, commentId); | ||
|
||
BacklogItemComment backlogItemComment = backlogItemCommentRepository.findById(commentId) | ||
.orElseThrow(() -> new BacklogItemCommentNotFoundException(BACKLOG_ITEM_NOT_FOUND_MESSAGE)); | ||
|
||
log.info(RETURNING_RESPONSE_FOR, backlogItemComment); | ||
|
||
return backLogItemCommentMapper.toBacklogItemCommentResponse(backlogItemComment); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
...n/java/dev/corn/cornbackend/api/backlog/comment/constants/BacklogItemCommentMappings.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
package dev.corn.cornbackend.api.backlog.comment.constants; | ||
|
||
public final class BacklogItemCommentMappings { | ||
|
||
public static final String BACKLOG_ITEM_COMMENT_API_MAPPING = "/api/backlog/comment"; | ||
public static final String BACKLOG_ITEM_COMMENT_ADD_MAPPING = "/add"; | ||
public static final String BACKLOG_ITEM_COMMENT_UPDATE_MAPPING = "/update"; | ||
public static final String BACKLOG_ITEM_COMMENT_DELETE_MAPPING = "/delete"; | ||
public static final String BACKLOG_ITEM_COMMENT_GET_MAPPING = "/get"; | ||
private BacklogItemCommentMappings() { | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...rc/main/java/dev/corn/cornbackend/api/backlog/comment/data/BacklogItemCommentRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package dev.corn.cornbackend.api.backlog.comment.data; | ||
|
||
import lombok.Builder; | ||
|
||
@Builder | ||
public record BacklogItemCommentRequest(String comment, long backlogItemId) { | ||
} |
9 changes: 9 additions & 0 deletions
9
...c/main/java/dev/corn/cornbackend/api/backlog/comment/data/BacklogItemCommentResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,9 @@ | ||
package dev.corn.cornbackend.api.backlog.comment.data; | ||
|
||
import dev.corn.cornbackend.entities.user.User; | ||
import lombok.Builder; | ||
|
||
@Builder | ||
public record BacklogItemCommentResponse(String comment, | ||
User user) { | ||
} |
17 changes: 17 additions & 0 deletions
17
...ava/dev/corn/cornbackend/api/backlog/comment/interfaces/BacklogItemCommentController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package dev.corn.cornbackend.api.backlog.comment.interfaces; | ||
|
||
import dev.corn.cornbackend.api.backlog.comment.data.BacklogItemCommentRequest; | ||
import dev.corn.cornbackend.api.backlog.comment.data.BacklogItemCommentResponse; | ||
import dev.corn.cornbackend.entities.user.User; | ||
|
||
public interface BacklogItemCommentController { | ||
|
||
BacklogItemCommentResponse addNewComment(BacklogItemCommentRequest request, User user); | ||
|
||
BacklogItemCommentResponse updateComment(long commentId, String comment); | ||
|
||
BacklogItemCommentResponse deleteComment(long commentId); | ||
|
||
BacklogItemCommentResponse getComment(long commentId); | ||
|
||
} |
20 changes: 20 additions & 0 deletions
20
...n/java/dev/corn/cornbackend/api/backlog/comment/interfaces/BacklogItemCommentService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package dev.corn.cornbackend.api.backlog.comment.interfaces; | ||
|
||
import dev.corn.cornbackend.api.backlog.comment.data.BacklogItemCommentRequest; | ||
import dev.corn.cornbackend.api.backlog.comment.data.BacklogItemCommentResponse; | ||
import dev.corn.cornbackend.entities.user.User; | ||
|
||
public interface BacklogItemCommentService { | ||
|
||
BacklogItemCommentResponse addNewComment(BacklogItemCommentRequest request, User user); | ||
|
||
BacklogItemCommentResponse updateComment(long commentId, String comment); | ||
|
||
BacklogItemCommentResponse deleteComment(long commentId); | ||
|
||
BacklogItemCommentResponse getComment(long commentId); | ||
|
||
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. co tu się stało XD ? |
||
|
||
|
||
|
||
} |
78 changes: 78 additions & 0 deletions
78
...ackend/src/main/java/dev/corn/cornbackend/api/backlog/item/BacklogItemControllerImpl.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
package dev.corn.cornbackend.api.backlog.item; | ||
|
||
import dev.corn.cornbackend.api.backlog.item.data.BacklogItemDetails; | ||
import dev.corn.cornbackend.api.backlog.item.data.BacklogItemRequest; | ||
import dev.corn.cornbackend.api.backlog.item.data.BacklogItemResponse; | ||
import dev.corn.cornbackend.api.backlog.item.interfaces.BacklogItemController; | ||
import dev.corn.cornbackend.api.backlog.item.interfaces.BacklogItemService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RequestParam; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import java.util.List; | ||
|
||
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemMappings.BACKLOG_ITEM_ADD_MAPPING; | ||
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemMappings.BACKLOG_ITEM_API_MAPPING; | ||
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemMappings.BACKLOG_ITEM_DELETE_MAPPING; | ||
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemMappings.BACKLOG_ITEM_GET_BY_PROJECT_MAPPING; | ||
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemMappings.BACKLOG_ITEM_GET_BY_SPRINT_MAPPING; | ||
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemMappings.BACKLOG_ITEM_GET_DETAILS_MAPPING; | ||
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemMappings.BACKLOG_ITEM_GET_MAPPING; | ||
import static dev.corn.cornbackend.api.backlog.item.constants.BacklogItemMappings.BACKLOG_ITEM_UPDATE_MAPPING; | ||
|
||
@RestController | ||
@RequestMapping(BACKLOG_ITEM_API_MAPPING) | ||
@RequiredArgsConstructor | ||
public class BacklogItemControllerImpl implements BacklogItemController { | ||
|
||
private final BacklogItemService backlogItemService; | ||
|
||
@Override | ||
@GetMapping(BACKLOG_ITEM_GET_MAPPING) | ||
public BacklogItemResponse getById(@RequestParam long id) { | ||
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.
|
||
return backlogItemService.getById(id); | ||
} | ||
|
||
@Override | ||
@PutMapping(BACKLOG_ITEM_UPDATE_MAPPING) | ||
public BacklogItemResponse update(@RequestParam long id, | ||
@RequestBody BacklogItemRequest backlogItemRequest) { | ||
return backlogItemService.update(id, backlogItemRequest); | ||
} | ||
|
||
@Override | ||
@DeleteMapping(BACKLOG_ITEM_DELETE_MAPPING) | ||
public BacklogItemResponse deleteById(@RequestParam long id) { | ||
return backlogItemService.deleteById(id); | ||
} | ||
|
||
@Override | ||
@PostMapping(BACKLOG_ITEM_ADD_MAPPING) | ||
public BacklogItemResponse create(@RequestBody BacklogItemRequest backlogItemRequest) { | ||
return backlogItemService.create(backlogItemRequest); | ||
} | ||
|
||
@Override | ||
@GetMapping(BACKLOG_ITEM_GET_BY_SPRINT_MAPPING) | ||
public List<BacklogItemResponse> getBySprintId(@RequestParam long sprintId) { | ||
return backlogItemService.getBySprintId(sprintId); | ||
} | ||
|
||
@Override | ||
@GetMapping(BACKLOG_ITEM_GET_BY_PROJECT_MAPPING) | ||
public List<BacklogItemResponse> getByProjectId(@RequestParam long projectId) { | ||
return backlogItemService.getByProjectId(projectId); | ||
} | ||
|
||
@Override | ||
@GetMapping(BACKLOG_ITEM_GET_DETAILS_MAPPING) | ||
public BacklogItemDetails getDetailsById(@RequestParam long id) { | ||
return backlogItemService.getDetailsById(id); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
final