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

Backlogitem and comment crud #12

Merged
merged 6 commits into from
Dec 20, 2023
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions corn-backend/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,8 @@ dependencies {
implementation 'org.springframework.boot:spring-boot-starter-web'

testImplementation 'org.projectlombok:lombok:1.18.28'
annotationProcessor 'org.projectlombok:lombok'
compileOnly 'org.projectlombok:lombok'
compileOnly 'org.projectlombok:lombok:1.18.28'
annotationProcessor 'org.projectlombok:lombok:1.18.28'

runtimeOnly 'org.postgresql:postgresql'

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

Choose a reason for hiding this comment

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

final

@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);
}


}
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);
}
}
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() {
}
}
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) {
}
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) {
}
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);

}
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);

Copy link
Owner

Choose a reason for hiding this comment

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

co tu się stało XD ?




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

Choose a reason for hiding this comment

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

final

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);
}
}
Loading