Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
haiphucnguyen committed Nov 21, 2024
1 parent aeafd1d commit 1d9a07a
Show file tree
Hide file tree
Showing 35 changed files with 195 additions and 181 deletions.
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.flexwork.modules.crm.domain;
package io.flexwork.modules.collab.domain;

import io.flexwork.modules.usermanagement.domain.User;
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.EnumType;
import jakarta.persistence.Enumerated;
import jakarta.persistence.FetchType;
import jakarta.persistence.ForeignKey;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
Expand All @@ -16,11 +16,9 @@
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.CreationTimestamp;
import org.hibernate.annotations.UpdateTimestamp;

@Entity
@Table(name = "fw_crm_comments")
@Table(name = "fw_comment")
@Data
@Builder
@NoArgsConstructor
Expand All @@ -31,31 +29,26 @@ public class Comment {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@Column(name = "content", nullable = false)
@Column(name = "content", nullable = false, columnDefinition = "TEXT")
private String content;

@ManyToOne
@JoinColumn(name = "created_by", nullable = false)
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(
name = "created_by",
nullable = false,
foreignKey = @ForeignKey(name = "fk_comment_user"))
private User createdBy;

@Column(name = "created_at", updatable = false)
@CreationTimestamp
@Column(
name = "created_at",
nullable = false,
columnDefinition = "TIMESTAMPTZ",
updatable = false)
private LocalDateTime createdAt;

@Column(name = "updated_at")
@UpdateTimestamp
private LocalDateTime updatedAt;

@Enumerated(EnumType.STRING)
@Column(name = "entity_type", nullable = false)
private EntityType entityType;
@Column(name = "entity_type", nullable = false, length = 20)
private String entityType;

@Column(name = "entity_id", nullable = false)
private Long entityId;

public enum EntityType {
ACCOUNT,
CONTACT,
CASE
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.flexwork.modules.usermanagement.domain;
package io.flexwork.modules.collab.domain;

import jakarta.persistence.*;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
package io.flexwork.modules.usermanagement.domain;
package io.flexwork.modules.collab.domain;

import io.flexwork.modules.teams.domain.TeamWorkflowSelection;
import io.flexwork.modules.teams.domain.Workflow;
import io.flexwork.modules.usermanagement.domain.User;
import io.flexwork.modules.usermanagement.domain.UserTeam;
import jakarta.persistence.*;
import jakarta.validation.constraints.Size;
import java.util.HashSet;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.flexwork.modules.usermanagement.domain;
package io.flexwork.modules.collab.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
package io.flexwork.modules.crm.repository;
package io.flexwork.modules.collab.repository;

import io.flexwork.modules.crm.domain.Comment;
import io.flexwork.modules.collab.domain.Comment;
import java.util.List;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface CommentRepository extends JpaRepository<Comment, Long> {
List<Comment> findByEntityTypeAndEntityId(Comment.EntityType entityType, Long entityId);

List<Comment> findByEntityTypeAndEntityId(String entityType, Long entityId);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.flexwork.modules.usermanagement.repository;
package io.flexwork.modules.collab.repository;

import io.flexwork.modules.usermanagement.domain.Organization;
import io.flexwork.modules.collab.domain.Organization;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.JpaSpecificationExecutor;
import org.springframework.stereotype.Repository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.flexwork.modules.usermanagement.repository;
package io.flexwork.modules.collab.repository;

import io.flexwork.modules.usermanagement.domain.Team;
import io.flexwork.modules.collab.domain.Team;
import io.flexwork.modules.collab.service.dto.TeamDTO;
import io.flexwork.modules.usermanagement.domain.User;
import io.flexwork.modules.usermanagement.service.dto.TeamDTO;
import io.flexwork.modules.usermanagement.service.dto.UserWithTeamRoleDTO;
import java.util.List;
import org.springframework.data.domain.Page;
Expand All @@ -17,7 +17,7 @@
@Repository
public interface TeamRepository extends JpaRepository<Team, Long>, JpaSpecificationExecutor<Team> {
@Query(
"SELECT new io.flexwork.modules.usermanagement.service.dto.TeamDTO(t.id, t.name, t.logoUrl, t.slogan, t.description, t.organization.id, COUNT(m.id)) "
"SELECT new io.flexwork.modules.collab.service.dto.TeamDTO(t.id, t.name, t.logoUrl, t.slogan, t.description, t.organization.id, COUNT(m.id)) "
+ "FROM Team t LEFT JOIN t.users m "
+ "GROUP BY t.id")
Page<TeamDTO> findAllDTOs(Specification<Team> spec, Pageable pageable);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.flexwork.modules.usermanagement.repository;
package io.flexwork.modules.collab.repository;

import io.flexwork.modules.usermanagement.domain.TeamRole;
import io.flexwork.modules.collab.domain.TeamRole;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.stereotype.Repository;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package io.flexwork.modules.collab.service;

import io.flexwork.modules.collab.domain.Comment;
import io.flexwork.modules.collab.repository.CommentRepository;
import jakarta.transaction.Transactional;
import java.util.List;
import org.springframework.stereotype.Service;

@Service
@Transactional
public class CommentService {

private final CommentRepository commentRepository;

public CommentService(CommentRepository commentRepository) {
this.commentRepository = commentRepository;
}

public Comment saveComment(Comment comment) {
return commentRepository.save(comment);
}

public Comment getCommentById(Long id) {
return commentRepository
.findById(id)
.orElseThrow(
() -> new IllegalArgumentException("Comment not found with id: " + id));
}

public List<Comment> getCommentsForEntity(String entityType, Long entityId) {
return commentRepository.findByEntityTypeAndEntityId(entityType, entityId);
}

public void deleteComment(Long id) {
if (!commentRepository.existsById(id)) {
throw new IllegalArgumentException("Comment not found with id: " + id);
}
commentRepository.deleteById(id);
}
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.flexwork.modules.usermanagement.service;
package io.flexwork.modules.collab.service;

import io.flexwork.config.FlexworkProperties;
import io.flexwork.modules.usermanagement.domain.User;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.flexwork.modules.usermanagement.service;
package io.flexwork.modules.collab.service;

import static io.flexwork.query.QueryUtils.createSpecification;

import io.flexwork.modules.usermanagement.domain.Organization;
import io.flexwork.modules.usermanagement.repository.OrganizationRepository;
import io.flexwork.modules.collab.domain.Organization;
import io.flexwork.modules.collab.repository.OrganizationRepository;
import io.flexwork.query.QueryDTO;
import jakarta.persistence.EntityNotFoundException;
import java.util.Optional;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,20 +1,20 @@
package io.flexwork.modules.usermanagement.service;
package io.flexwork.modules.collab.service;

import static io.flexwork.query.QueryUtils.createSpecification;

import io.flexwork.modules.usermanagement.domain.Team;
import io.flexwork.modules.usermanagement.domain.TeamRole;
import io.flexwork.modules.collab.domain.Team;
import io.flexwork.modules.collab.domain.TeamRole;
import io.flexwork.modules.collab.repository.TeamRepository;
import io.flexwork.modules.collab.repository.TeamRoleRepository;
import io.flexwork.modules.collab.service.dto.TeamDTO;
import io.flexwork.modules.collab.service.mapper.TeamMapper;
import io.flexwork.modules.usermanagement.domain.User;
import io.flexwork.modules.usermanagement.domain.UserTeam;
import io.flexwork.modules.usermanagement.domain.UserTeamId;
import io.flexwork.modules.usermanagement.repository.TeamRepository;
import io.flexwork.modules.usermanagement.repository.TeamRoleRepository;
import io.flexwork.modules.usermanagement.repository.UserRepository;
import io.flexwork.modules.usermanagement.repository.UserTeamRepository;
import io.flexwork.modules.usermanagement.service.dto.TeamDTO;
import io.flexwork.modules.usermanagement.service.dto.UserDTO;
import io.flexwork.modules.usermanagement.service.dto.UserWithTeamRoleDTO;
import io.flexwork.modules.usermanagement.service.mapper.TeamMapper;
import io.flexwork.modules.usermanagement.service.mapper.UserMapper;
import io.flexwork.query.QueryDTO;
import jakarta.persistence.EntityNotFoundException;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.flexwork.modules.usermanagement.service.dto;
package io.flexwork.modules.collab.service.dto;

import java.util.Set;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.flexwork.modules.usermanagement.service.dto;
package io.flexwork.modules.collab.service.dto;

import lombok.AllArgsConstructor;
import lombok.Builder;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.flexwork.modules.usermanagement.service.mapper;
package io.flexwork.modules.collab.service.mapper;

import io.flexwork.modules.usermanagement.domain.Organization;
import io.flexwork.modules.usermanagement.domain.Team;
import io.flexwork.modules.usermanagement.service.dto.OrganizationDTO;
import io.flexwork.modules.usermanagement.service.dto.TeamDTO;
import io.flexwork.modules.collab.domain.Organization;
import io.flexwork.modules.collab.domain.Team;
import io.flexwork.modules.collab.service.dto.OrganizationDTO;
import io.flexwork.modules.collab.service.dto.TeamDTO;
import java.util.Set;
import java.util.stream.Collectors;
import org.mapstruct.Mapper;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.flexwork.modules.usermanagement.service.mapper;
package io.flexwork.modules.collab.service.mapper;

import io.flexwork.modules.usermanagement.domain.Organization;
import io.flexwork.modules.usermanagement.domain.Team;
import io.flexwork.modules.usermanagement.service.dto.TeamDTO;
import io.flexwork.modules.collab.domain.Organization;
import io.flexwork.modules.collab.domain.Team;
import io.flexwork.modules.collab.service.dto.TeamDTO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.MappingTarget;
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.flexwork.modules.collab.web.rest;

import io.flexwork.modules.collab.domain.Comment;
import io.flexwork.modules.collab.service.CommentService;
import java.util.List;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/comments")
public class CommentController {

private final CommentService commentService;

public CommentController(CommentService commentService) {
this.commentService = commentService;
}

@PostMapping
public ResponseEntity<Comment> saveComment(@RequestBody Comment comment) {
Comment savedComment = commentService.saveComment(comment);
return ResponseEntity.ok(savedComment);
}

// Get a Comment by ID
@GetMapping("/{id}")
public ResponseEntity<Comment> getCommentById(@PathVariable Long id) {
Comment comment = commentService.getCommentById(id);
return ResponseEntity.ok(comment);
}

// Get Comments for an Entity
@GetMapping
public ResponseEntity<List<Comment>> getCommentsForEntity(
@RequestParam String entityType, @RequestParam Long entityId) {
List<Comment> comments = commentService.getCommentsForEntity(entityType, entityId);
return ResponseEntity.ok(comments);
}

// Delete a Comment
@DeleteMapping("/{id}")
public ResponseEntity<Void> deleteComment(@PathVariable Long id) {
commentService.deleteComment(id);
return ResponseEntity.noContent().build();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.flexwork.modules.usermanagement.web.rest;
package io.flexwork.modules.collab.web.rest;

import io.flexwork.modules.usermanagement.domain.Organization;
import io.flexwork.modules.usermanagement.service.OrganizationService;
import io.flexwork.modules.usermanagement.service.dto.OrganizationDTO;
import io.flexwork.modules.usermanagement.service.mapper.OrganizationMapper;
import io.flexwork.modules.collab.domain.Organization;
import io.flexwork.modules.collab.service.OrganizationService;
import io.flexwork.modules.collab.service.dto.OrganizationDTO;
import io.flexwork.modules.collab.service.mapper.OrganizationMapper;
import io.flexwork.query.QueryDTO;
import java.util.Optional;
import org.springframework.data.domain.Page;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.flexwork.modules.usermanagement.web.rest;
package io.flexwork.modules.collab.web.rest;

import io.flexwork.modules.collab.domain.Team;
import io.flexwork.modules.collab.service.TeamService;
import io.flexwork.modules.collab.service.dto.TeamDTO;
import io.flexwork.modules.fss.ResourceRemoveEvent;
import io.flexwork.modules.fss.service.StorageService;
import io.flexwork.modules.usermanagement.domain.Team;
import io.flexwork.modules.usermanagement.service.TeamService;
import io.flexwork.modules.usermanagement.service.dto.TeamDTO;
import io.flexwork.modules.usermanagement.service.dto.UserDTO;
import io.flexwork.modules.usermanagement.service.dto.UserWithTeamRoleDTO;
import io.flexwork.query.QueryDTO;
Expand Down
Loading

0 comments on commit 1d9a07a

Please sign in to comment.