Compare commits

..

No commits in common. '989f94de81a48efc032b48c9b39c47b23b36fc15' and 'd7485f796f19e3faa5947332277cf8b2829335e9' have entirely different histories.

  1. 13
      BE/pom.xml
  2. 9
      BE/src/main/java/org/example/controllers/UserController.java
  3. 26
      BE/src/main/java/org/example/models/Like.java
  4. 18
      BE/src/main/java/org/example/objects/ApiResponse.java
  5. 11
      BE/src/main/java/org/example/repositories/UserRepository.java
  6. 15
      BE/src/main/java/org/example/requests/CreateLikeRequest.java
  7. 13
      BE/src/main/java/org/example/services/UserService.java

@ -40,18 +40,7 @@
<groupId>org.neo4j.driver</groupId>
<artifactId>neo4j-java-driver</artifactId>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-core</artifactId>
<version>4.0.10</version>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.neo4j</groupId>
<artifactId>neo4j-ogm-bolt-driver</artifactId>
<version>4.0.10</version>
<scope>runtime</scope>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>

@ -1,10 +1,8 @@
package org.example.controllers;
import org.example.models.User;
import org.example.objects.ApiResponse;
import org.example.objects.UserDTO;
import org.example.repositories.UserRepository;
import org.example.requests.CreateLikeRequest;
import org.example.requests.CreateUserRequest;
import org.example.services.UserService;
import org.springframework.http.HttpStatus;
@ -38,11 +36,4 @@ public class UserController {
return new ResponseEntity<>(responseUser, HttpStatus.CREATED);
}
@PostMapping("/createLike")
public ApiResponse<CreateLikeRequest> createLike(@RequestBody CreateLikeRequest request) {
ApiResponse<CreateLikeRequest> response = new ApiResponse<>();
response.setResult(userService.createLike(request));
return response;
}
}

@ -1,26 +0,0 @@
package org.example.models;
import lombok.*;
import lombok.experimental.FieldDefaults;
import org.neo4j.ogm.annotation.EndNode;
import org.neo4j.ogm.annotation.RelationshipEntity;
import org.neo4j.ogm.annotation.StartNode;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
@RelationshipEntity(type = "LIKE")
public class Like {
Long userId;
Long postId;
String status;
@StartNode
private User user;
@EndNode
private Post post;
}

@ -1,18 +0,0 @@
package org.example.objects;
import com.fasterxml.jackson.annotation.JsonInclude;
import lombok.*;
import lombok.experimental.FieldDefaults;
@Data
@AllArgsConstructor
@NoArgsConstructor
@Builder
@FieldDefaults(level = AccessLevel.PRIVATE)
@JsonInclude(JsonInclude.Include.NON_NULL)
public class ApiResponse<T>{
int code = 1000;
String message;
T result;
}

@ -4,7 +4,6 @@ import org.example.models.User;
import org.example.queryresults.PostQueryResult;
import org.springframework.data.neo4j.repository.Neo4jRepository;
import org.springframework.data.neo4j.repository.query.Query;
import org.springframework.data.repository.query.Param;
import java.util.Optional;
@ -18,16 +17,6 @@ public interface UserRepository extends Neo4jRepository<User, Long> {
"RETURN EXISTS((user)-[:ENROLLED_IN]->(course))")
Boolean findEnrolmentStatus(String username, String identifier);
@Query("match (u:User), (p:POST)\n" +
"WHERE id(u) = $nameId AND id(p) = $postId\n" +
"create (u) - [:LIKE] -> (p)")
void createLike(@Param("nameId") Long nameId, @Param("postId*") Long postId);
@Query("match (a:User)-[r:LIKE]-> (b:POST)\n" +
"WHERE id(a) = $id AND id(b) = $idd\n" +
"RETURN COUNT(r) > 0 AS Relationship")
boolean checkLike(@Param("id") Long userId,@Param("idd") Long postId);
// @Query("MATCH (user:User), (course:Course) WHERE user.username = $username AND course.identifier = $identifier " +
// "CREATE (user)-[:ENROLLED_IN]->(course) RETURN user, course")
// CourseEnrolmentQueryResult createEnrolmentRelationship(String username, String identifier);

@ -1,15 +0,0 @@
package org.example.requests;
import lombok.*;
import lombok.experimental.FieldDefaults;
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class CreateLikeRequest {
Long userId;
Long postId;
}

@ -2,7 +2,6 @@ package org.example.services;
import org.example.models.User;
import org.example.repositories.UserRepository;
import org.example.requests.CreateLikeRequest;
import org.example.requests.CreateUserRequest;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;
@ -34,16 +33,4 @@ public class UserService {
return user;
}
public CreateLikeRequest createLike(CreateLikeRequest request) {
Long userId = request.getUserId();
Long postId = request.getPostId();
if(userRepository.checkLike(userId, postId)){
throw new IllegalArgumentException("Already liked");
}
userRepository.createLike(userId, postId);
return request;
}
}

Loading…
Cancel
Save