Skip to content

Commit

Permalink
feat(develop): removing responsibility of Comment MS to Create
Browse files Browse the repository at this point in the history
  • Loading branch information
lucasmoraist committed Oct 4, 2024
1 parent 129af0f commit 3465c70
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 31 deletions.
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.lucasmoraist.comments.controller;

import com.lucasmoraist.comments.domain.dto.CommentRequest;
import com.lucasmoraist.comments.domain.dto.CommentUpdate;
import com.lucasmoraist.comments.domain.entity.Comment;
import com.lucasmoraist.comments.service.CommentService;
import com.netflix.discovery.converters.Auto;
import jakarta.validation.Valid;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -25,18 +24,9 @@ public ResponseEntity<List<Comment>> listComments(){
log.info("Listing all comments");
return ResponseEntity.ok().body(this.service.listAll());
}

@PostMapping("/{taskId}/comments")
public ResponseEntity<Void> createComment(@PathVariable Long taskId, @Valid @RequestBody CommentRequest request) {
log.info("Creating comment for task with ID: {}", taskId);
log.info("Request: {}", request);
this.service.create(taskId, request);
log.info("Comment created");
return ResponseEntity.ok().build();
}

@PutMapping("{commentId}")
public ResponseEntity<Void> updateComment(@PathVariable Long commentId, @Valid @RequestBody CommentRequest request) {
public ResponseEntity<Void> updateComment(@PathVariable Long commentId, @Valid @RequestBody CommentUpdate request) {
log.info("Updating comment with id: {}", commentId);
log.info("Request: {}", request);
this.service.update(commentId, request);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
package com.lucasmoraist.comments.service;

import com.lucasmoraist.comments.domain.dto.CommentRequest;
import com.lucasmoraist.comments.domain.dto.CommentUpdate;
import com.lucasmoraist.comments.domain.entity.Comment;

import java.util.List;

public interface CommentService {
Long create(Long taskId, CommentRequest request);
List<Comment> listAll();
void update(Long id, CommentRequest request);
void update(Long id, CommentUpdate request);
void delete(Long id);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.lucasmoraist.comments.service.impl;

import com.lucasmoraist.comments.domain.dto.CommentRequest;
import com.lucasmoraist.comments.domain.dto.CommentUpdate;
import com.lucasmoraist.comments.domain.entity.Comment;
import com.lucasmoraist.comments.repository.CommentRepository;
import com.lucasmoraist.comments.service.CommentService;
Expand All @@ -18,20 +18,6 @@ public class CommentServiceImpl implements CommentService {

private final CommentRepository repository;

@Transactional
@Override
public Long create(Long taskId, CommentRequest request) {
Comment comment = Comment.builder()
.text(request.text())
.taskId(taskId)
.build();

this.repository.save(comment);
log.info("Comment created: {}", comment);

return comment.getId();
}

@Transactional
@Override
public List<Comment> listAll() {
Expand All @@ -40,7 +26,7 @@ public List<Comment> listAll() {
}

@Override
public void update(Long id, CommentRequest request) {
public void update(Long id, CommentUpdate request) {
log.info("Updating comment with id: {}", id);

Comment comment = this.findById(id);
Expand Down

0 comments on commit 3465c70

Please sign in to comment.