Skip to content

Commit

Permalink
Merge pull request #4 from smartSenseSolutions/add-new-endpoints-for-…
Browse files Browse the repository at this point in the history
…user-chat-and-edc-registration

feat: add curd operation endpoints for user, chat and edc registration.
  • Loading branch information
dilipdhankecha2530 authored Nov 19, 2024
2 parents 0448fb8 + bc6c77b commit 04e5657
Show file tree
Hide file tree
Showing 35 changed files with 813 additions and 85 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -30,5 +30,8 @@ public final class ContMessage {

public static final String SOMETHING_WENT_WRONG = "something.went.wrong";
public static final String USER_CREATED = "user.created.successfully";
public static final String EDC_CREATED = "edc.created.successfully";
public static final String CHAT_CREATED = "chat.created.successfully";
public static final String VALIDATE_USER_CREATE_NAME_EXIST = "validate.user.create.name.exist";
public static final String VALIDATE_EDC_CREATE_URL_EXIST = "validate.edc.create.url.exist";
}
12 changes: 11 additions & 1 deletion chat-api/src/main/java/com/smartsense/api/constant/ContURI.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,11 +27,21 @@
*/
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public final class ContURI {
//Test Resource
//User Management
public static final String USER = "/common/user";
public static final String USER_WITH_ID = "/common/user/{userId}";
public static final String USER_FILTER = "/common/user/filter";

// EDC Register
public static final String EDC_CREATE = "common/edc/create";
public static final String EDC_UPDATE = "common/edc/update";
public static final String EDC_FILTER = "common/edc/filter";
public static final String GET_EDC = "common/edc/{edcId}";
public static final String GET_EDC_USER = "/common/user/edc/{userId}";

// Chat
public static final String CHAT_REGISTER = "common/chat";

//Context
public static final String CONTEXT_AUTHENTICATED_ALL = "/common/**";
public static final String CONTEXT_AUTHENTICATED_WITH_NO_FILTER_ALL = "/common2/**";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.smartsense.api.model.request;

import java.util.UUID;

public record ChatRequest(UUID senderId,
UUID receiverId,
String message,
String messageType) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.smartsense.api.model.request;

import java.util.UUID;

public record EDCRegisterRequest(String edcUrl, UUID userId) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
package com.smartsense.api.model.request;

import java.util.UUID;

public record EDCUpdateRequest(UUID edcId, EDCRegisterRequest request) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,22 +15,18 @@
*/
package com.smartsense.api.model.request;

import jakarta.validation.constraints.Min;
import jakarta.validation.constraints.NotEmpty;
import com.smartsense.api.model.BaseModel;
import jakarta.validation.constraints.NotEmpty;


/**
* User request
* Create a new {@code UserRequest} with the given first name, last name, and email.
*
* @param name name of user
* @param age age of user
* @param city city of user
* @param country country of city
* @author Sunil Kanzar
* @since 14th feb 2024
* @param firstName the user's first name (must not be empty)
* @param lastName the user's last name (must not be empty)
* @param email the user's email (must not be empty)
*/
public record UserRequest(@NotEmpty(message = "{please.enter.user.name}") String name,
@Min(value = 18, message = "{you.are.under.age}") Integer age,
@NotEmpty(message = "{please.enter.city}") String city,
@NotEmpty(message = "{please.enter.county}") String country) implements BaseModel {
public record UserRequest(@NotEmpty(message = "{please.enter.user.first.name}") String firstName,
String lastName,
@NotEmpty(message = "{please.enter.email}") String email) implements BaseModel {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.smartsense.api.model.response;

import java.util.UUID;

public record ChatResponse(String id,
UUID senderId,
UUID receiverId,
String message,
String messageType,
String createdAt) {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.smartsense.api.model.response;

import java.util.UUID;

public record EDCRegisterResponse(
UUID id,
String edcUrl,
UserResponse userId
) {
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,9 +18,10 @@

import com.smartsense.api.model.BaseModel;

public record UserResponse(String id,
String name,
Integer age,
String city,
String country) implements BaseModel {
import java.util.UUID;

public record UserResponse(UUID id,
String firstName,
String lastName,
String email) implements BaseModel {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.smartsense.api.model.response;

import java.util.List;
import java.util.UUID;

public record UsersEDCResponse(UUID userId,
List<String> edcUrl) {
}
4 changes: 2 additions & 2 deletions chat-dao/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@ plugins {


dependencies {
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'
api 'org.springframework.boot:spring-boot-starter-data-jpa'
api 'org.springframework.boot:spring-boot-starter-data-mongodb'
api project(":chat-api")
}

Expand Down
27 changes: 27 additions & 0 deletions chat-dao/src/main/java/com/smartsense/dao/entity/ChatMaster.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
package com.smartsense.dao.entity;

import jakarta.persistence.Id;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.springframework.data.mongodb.core.mapping.Document;

import java.util.UUID;

@Getter
@Setter
@AllArgsConstructor
@NoArgsConstructor
@Document(collection = "chat_master")
@Builder
public class ChatMaster extends BaseAuditEntity {

@Id
private String id;
private UUID senderId;
private UUID receiverId;
private String message;
private String messageType;
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
package com.smartsense.dao.entity;

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;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.UUID;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@Builder
@Entity
@Table(name = "edc_register_master")
public class EDCRegisterMaster extends BaseAuditEntity {

@Id
@GeneratedValue(strategy = GenerationType.UUID)
@Column(name = "id", nullable = false, updatable = false, insertable = false)
private UUID id = UUID.randomUUID();

@ManyToOne
@JoinColumn(name = "user_id_id", nullable = false)
private UserMaster userId;

private String edcUrl;


}
27 changes: 15 additions & 12 deletions chat-dao/src/main/java/com/smartsense/dao/entity/UserMaster.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,16 @@
import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.Table;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;
import org.hibernate.annotations.GenericGenerator;

import java.util.UUID;

/**
* UserMaster Represent user
Expand All @@ -43,19 +45,20 @@
public class UserMaster extends BaseAuditEntity {

@Id
@GeneratedValue(generator = "uuid2")
@GenericGenerator(name = "uuid2", strategy = "org.hibernate.id.UUIDGenerator")
private String id;
@GeneratedValue(strategy = GenerationType.UUID)
@Column(name = "id", nullable = false, updatable = false, insertable = false)
private UUID id = UUID.randomUUID();

@Column(name = "name")
private String name;
@Column(name = "first_name")
private String firstName;

@Column(name = "age")
private Integer age;
@Column(name = "last_name")
private String lastName;

@Column(name = "city")
private String city;
@Column(name = "email")
private String email;

@Column(name = "country")
private String country;
public UserMaster(String id) {
this.id = UUID.fromString(id);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
package com.smartsense.dao.repository;

import com.smartsense.dao.entity.ChatMaster;
import org.springframework.data.mongodb.repository.MongoRepository;
import org.springframework.stereotype.Repository;

@Repository
public interface ChatMasterRepository extends MongoRepository<ChatMaster, String> {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.smartsense.dao.repository;


import com.smartsense.dao.entity.EDCRegisterMaster;
import com.smartsensesolutions.commons.dao.base.BaseRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.UUID;

@Repository
public interface EDCRegisterMasterRepository extends BaseRepository<EDCRegisterMaster, UUID> {

boolean existsByEdcUrl(String edcUrl);

@Query("select e from EDCRegisterMaster e where e.userId.id = ?1")
List<EDCRegisterMaster> findByUserId(UUID id);

}
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,11 @@
*/
package com.smartsense.dao.repository;

import com.smartsense.dao.entity.UserMaster;
import com.smartsensesolutions.commons.dao.base.BaseRepository;
import org.springframework.stereotype.Repository;
import com.smartsense.dao.entity.UserMaster;

import java.util.UUID;

/**
* Database operation related to {@link UserMaster}
Expand All @@ -26,6 +28,7 @@
* @since 14th feb 2024
*/
@Repository
public interface UserMasterRepository extends BaseRepository<UserMaster, String> {
boolean existsByName(String name);
public interface UserMasterRepository extends BaseRepository<UserMaster, UUID> {

boolean existsByFirstName(String name);
}
1 change: 0 additions & 1 deletion chat-service-impl/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ plugins {
dependencies {
api project(":chat-dao")
api project(":chat-service")
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
implementation "com.fasterxml.jackson.core:jackson-databind:${jacksonVersion}"
implementation "com.fasterxml.jackson.core:jackson-core:${jacksonVersion}"
implementation 'org.springframework.cloud:spring-cloud-starter-openfeign'
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package com.smartsense.service.entity;

import com.smartsense.api.constant.ContMessage;
import com.smartsense.api.model.request.EDCRegisterRequest;
import com.smartsense.api.model.response.UsersEDCResponse;
import com.smartsense.api.utils.Validate;
import com.smartsense.dao.entity.EDCRegisterMaster;
import com.smartsense.dao.entity.UserMaster;
import com.smartsense.dao.repository.EDCRegisterMasterRepository;
import com.smartsensesolutions.commons.dao.base.BaseRepository;
import com.smartsensesolutions.commons.dao.specification.SpecificationUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.UUID;

@Service
public class EDCService extends BaseEntityService<EDCRegisterMaster, UUID> {

@Autowired
private EDCRegisterMasterRepository edcRegisterMasterRepository;
@Autowired
private SpecificationUtil<EDCRegisterMaster> specificationUtil;

public EDCRegisterMaster createEDC(EDCRegisterRequest request, UserMaster user) {
Validate.isTrue(edcRegisterMasterRepository.existsByEdcUrl(request.edcUrl())).launch(ContMessage.VALIDATE_EDC_CREATE_URL_EXIST);
EDCRegisterMaster edcRegisterMaster = EDCRegisterMaster.builder()
.edcUrl(request.edcUrl())
.userId(user)
.build();
return create(edcRegisterMaster);
}


@Override
protected BaseRepository<EDCRegisterMaster, UUID> getRepository() {
return edcRegisterMasterRepository;
}

public UsersEDCResponse getEDCByUserid(UUID userId) {
List<EDCRegisterMaster> edcList = edcRegisterMasterRepository.findByUserId(userId);
List<String> edcUrls = edcList.stream().map(EDCRegisterMaster::getEdcUrl).toList();
return new UsersEDCResponse(userId, edcUrls);
}
}
Loading

0 comments on commit 04e5657

Please sign in to comment.