Skip to content

Commit

Permalink
Update
Browse files Browse the repository at this point in the history
  • Loading branch information
haiphucnguyen committed Nov 7, 2024
1 parent 2a9cabb commit be755aa
Show file tree
Hide file tree
Showing 35 changed files with 292 additions and 801 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,6 @@ public AccountService(
this.accountMapper = accountMapper;
}

// Find an account by its ID
public Optional<AccountDTO> findAccountById(Long accountId) {
return accountRepository.findById(accountId).map(accountMapper::accountToAccountDTO);
}
Expand Down Expand Up @@ -72,7 +71,6 @@ public AccountDTO updateAccount(Long accountId, AccountDTO accountDetails) {
new EntityNotFoundException(
"Account not found with id: " + accountId));

// Step 2: Update the fields of the existing account with the new details
existingAccount.setName(accountEntityDetails.getName());
existingAccount.setType(accountEntityDetails.getType());
existingAccount.setIndustry(accountEntityDetails.getIndustry());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,23 +27,30 @@ public ContactService(ContactRepository contactRepository, ContactMapper contact
this.contactMapper = contactMapper;
}

public Page<Contact> findByAccountId(Long accountId, Pageable pageable) {
return contactRepository.findByAccountId(accountId, pageable);
public Page<ContactDTO> findByAccountId(Long accountId, Pageable pageable) {
return contactRepository
.findByAccountId(accountId, pageable)
.map(contactMapper::contactToContactDTO);
}

public Optional<Contact> getContactById(Long id) {
return contactRepository.findById(id);
public Optional<ContactDTO> getContactById(Long id) {
return contactRepository.findById(id).map(contactMapper::contactToContactDTO);
}

public Contact createContact(Contact contact) {
return contactRepository.save(contact);
public ContactDTO createContact(ContactDTO contact) {
return contactMapper.contactToContactDTO(
contactRepository.save(contactMapper.contactDTOToContact(contact)));
}

public Contact updateContact(Long id, Contact contactDetails) {
public ContactDTO updateContact(ContactDTO contactDetails) {
Contact contact =
contactRepository
.findById(id)
.orElseThrow(() -> new RuntimeException("Contact not found with id " + id));
.findById(contactDetails.getId())
.orElseThrow(
() ->
new RuntimeException(
"Contact not found with id "
+ contactDetails.getId()));

contact.setFirstName(contactDetails.getFirstName());
contact.setLastName(contactDetails.getLastName());
Expand All @@ -52,7 +59,7 @@ public Contact updateContact(Long id, Contact contactDetails) {
contact.setPosition(contactDetails.getPosition());
contact.setNotes(contactDetails.getNotes());

return contactRepository.save(contact);
return contactMapper.contactToContactDTO(contactRepository.save(contact));
}

public void deleteContact(Long id) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,43 +8,43 @@
@Builder
public class AccountDTO {

private Long id; // Unique identifier for the account
private Long id;

private String name; // Name of the account
private String name;

private String type; // Type of the account (e.g., customer, vendor)
private String type;

private String industry; // Industry in which the account operates
private String industry;

private String website; // Website URL for the account
private String website;

private String phoneNumber; // Contact phone number
private String phoneNumber;

private String email; // Email address
private String email;

private String addressLine1; // First line of address
private String addressLine1;

private String addressLine2; // Second line of address (optional)
private String addressLine2;

private String city; // City where the account is located
private String city;

private String state; // State or region of the account
private String state;

private String postalCode; // Postal code
private String postalCode;

private String country; // Country of the account
private String country;

private String annualRevenue; // Annual revenue of the account (if applicable)
private String annualRevenue;

private Long parentAccountId; // ID of the parent account (if any)
private Long parentAccountId;

private LocalDateTime createdAt; // Creation timestamp
private LocalDateTime createdAt;

private LocalDateTime updatedAt; // Last update timestamp
private LocalDateTime updatedAt;

private String status; // Current status of the account
private String status;

private Long assignedToUserId; // ID of the user the account is assigned to
private Long assignedToUserId;

private String notes; // Additional notes or details about the account
private String notes;
}
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ public class ContactDTO {

private Long id;

private Long accountId; // Assuming that you want to reference the Account by its ID in the DTO
private Long accountId;

private String accountName;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,7 @@
package io.flexwork.modules.crm.web.rest;

import io.flexwork.modules.crm.domain.Contact;
import io.flexwork.modules.crm.service.ContactService;
import io.flexwork.modules.crm.service.dto.ContactDTO;
import io.flexwork.modules.crm.service.mapper.ContactMapper;
import io.flexwork.query.QueryDTO;
import jakarta.validation.Valid;
import java.util.List;
Expand All @@ -18,13 +16,10 @@
@RequestMapping("/api/crm/contacts")
public class ContactController {

private ContactMapper contactMapper;

private ContactService contactService;

public ContactController(ContactService contactService, ContactMapper contactMapper) {
public ContactController(ContactService contactService) {
this.contactService = contactService;
this.contactMapper = contactMapper;
}

@PostMapping("/search")
Expand All @@ -36,30 +31,25 @@ public ResponseEntity<Page<ContactDTO>> findContacts(

@GetMapping("/account/{accountId}")
public Page<ContactDTO> getContacts(@PathVariable Long accountId, Pageable pageable) {
return contactService
.findByAccountId(accountId, pageable)
.map(value -> contactMapper.contactToContactDTO(value));
return contactService.findByAccountId(accountId, pageable);
}

@GetMapping("/{id}")
public ResponseEntity<ContactDTO> getContactById(@PathVariable Long id) {
Optional<Contact> contact = contactService.getContactById(id);
return contact.map(value -> ResponseEntity.ok(contactMapper.contactToContactDTO(value)))
Optional<ContactDTO> contact = contactService.getContactById(id);
return contact.map(value -> ResponseEntity.ok(value))
.orElseGet(() -> ResponseEntity.notFound().build());
}

@PostMapping
public ContactDTO createContact(@RequestBody ContactDTO contactDTO) {
return contactMapper.contactToContactDTO(
contactService.createContact(contactMapper.contactDTOToContact(contactDTO)));
return contactService.createContact(contactDTO);
}

@PutMapping("/{id}")
public ResponseEntity<ContactDTO> updateContact(
@PathVariable Long id, @RequestBody ContactDTO contactDTO) {
Contact updatedContact =
contactService.updateContact(id, contactMapper.contactDTOToContact(contactDTO));
return ResponseEntity.ok(contactMapper.contactToContactDTO(updatedContact));
@PutMapping()
public ResponseEntity<ContactDTO> updateContact(@RequestBody ContactDTO contactDTO) {
ContactDTO updatedContact = contactService.updateContact(contactDTO);
return ResponseEntity.ok(updatedContact);
}

@DeleteMapping("/{id}")
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package io.flexwork.modules.teams.domain;

import io.flexwork.modules.usermanagement.domain.Team;
import io.flexwork.modules.usermanagement.domain.User;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
Expand All @@ -15,7 +16,7 @@
import lombok.NoArgsConstructor;

@Entity
@Table(name = "fw_requests")
@Table(name = "fw_team_request")
@Data
@Builder
@NoArgsConstructor
Expand All @@ -27,22 +28,23 @@ public class TeamRequest {
private Long id;

@ManyToOne
@JoinColumn(name = "workflow_id", nullable = false)
private Workflow workflow;
@JoinColumn(name = "team_id", nullable = false)
private Team team;

@ManyToOne
@JoinColumn(name = "current_status_id", nullable = false)
private WorkflowStatus currentStatus;
@JoinColumn(name = "workflow_id", nullable = false)
private Workflow workflow;

@ManyToOne
@JoinColumn(name = "created_by", nullable = false)
private User createdBy;

private LocalDateTime createdAt;
@JoinColumn(name = "request_user_id", nullable = false)
private User requestUser;

@ManyToOne
@JoinColumn(name = "updated_by")
private User updatedBy;
@JoinColumn(name = "assign_user_id")
private User assignUser;

private LocalDateTime updatedAt;
private String requestTitle;
private String requestDescription;
private LocalDateTime createdDate;
private String currentState;
}

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,46 +1,24 @@
package io.flexwork.modules.teams.domain;

import io.flexwork.modules.usermanagement.domain.User;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.OneToMany;
import jakarta.persistence.Table;
import java.time.LocalDateTime;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import java.util.List;

@Entity
@Table(name = "fw_workflow")
@Data
@Builder
@NoArgsConstructor
@AllArgsConstructor
public class Workflow {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

private String name;

private String description;

@ManyToOne
@JoinColumn(name = "created_by", nullable = false)
private User createdBy;

private LocalDateTime createdAt;

@ManyToOne
@JoinColumn(name = "updated_by")
private User updatedBy;

private LocalDateTime updatedAt;

// Getters and Setters
@OneToMany(mappedBy = "workflow")
private List<WorkflowState> states;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package io.flexwork.modules.teams.domain;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import jakarta.persistence.Table;

@Entity
@Table(name = "fw_workflow_actions")
public class WorkflowAction {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;

@ManyToOne
@JoinColumn(name = "transition_id", nullable = false)
private WorkflowTransition transition;

private String actionType;

@Column(columnDefinition = "json")
private String actionData; // Store JSON data for flexibility
}
Loading

0 comments on commit be755aa

Please sign in to comment.