-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #2 from AleksandraKrasteva/dev
Add basic setup and functionality
- Loading branch information
Showing
48 changed files
with
823 additions
and
314 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
FROM gradle:latest AS build | ||
COPY . /home/gradle/src | ||
WORKDIR /home/gradle/src | ||
COPY . /home | ||
WORKDIR /home | ||
RUN gradle build --no-daemon | ||
|
||
FROM amazoncorretto:17-al2023-jdk | ||
FROM eclipse-temurin:17-jre-alpine as builder | ||
WORKDIR application | ||
COPY --from=build home/build/libs/*.jar application.jar | ||
RUN java -Djarmode=layertools -jar application.jar extract | ||
|
||
EXPOSE 8020 | ||
FROM eclipse-temurin:17-jre-alpine | ||
WORKDIR application | ||
COPY --from=builder application/dependencies/ ./ | ||
COPY --from=builder application/spring-boot-loader/ ./ | ||
COPY --from=builder application/snapshot-dependencies/ ./ | ||
COPY --from=builder application/application/ ./ | ||
|
||
RUN mkdir /app | ||
|
||
COPY --from=build /home/gradle/src/build/libs/*.jar /app/spring-boot-application.jar | ||
|
||
ENTRYPOINT ["java","-jar","/app/spring-boot-application.jar"] | ||
ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
FROM gradle:latest AS build | ||
COPY . /home/gradle/src | ||
WORKDIR /home/gradle/src | ||
COPY . /home | ||
WORKDIR /home | ||
RUN gradle build --no-daemon | ||
|
||
FROM amazoncorretto:17-al2023-jdk | ||
FROM eclipse-temurin:17-jre-alpine as builder | ||
WORKDIR application | ||
COPY --from=build home/build/libs/*.jar application.jar | ||
RUN java -Djarmode=layertools -jar application.jar extract | ||
|
||
EXPOSE 8090 | ||
FROM eclipse-temurin:17-jre-alpine | ||
WORKDIR application | ||
COPY --from=builder application/dependencies/ ./ | ||
COPY --from=builder application/spring-boot-loader/ ./ | ||
COPY --from=builder application/snapshot-dependencies/ ./ | ||
COPY --from=builder application/application/ ./ | ||
|
||
RUN mkdir /app | ||
|
||
COPY --from=build /home/gradle/src/build/libs/*.jar /app/spring-boot-application.jar | ||
|
||
ENTRYPOINT ["java","-jar","/app/spring-boot-application.jar"] | ||
ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
37 changes: 37 additions & 0 deletions
37
PostManagement/src/main/java/com/skipass/postmanagement/controllers/PostController.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
package com.skipass.postmanagement.controllers; | ||
|
||
import com.skipass.postmanagement.domain.CreatePostRequest; | ||
import com.skipass.postmanagement.persistance.PostEntity; | ||
import com.skipass.postmanagement.persistance.PostRepository; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@CrossOrigin(origins = "http://krakend:8080") | ||
@AllArgsConstructor | ||
public class PostController { | ||
|
||
private final PostRepository postRepository; | ||
|
||
@PostMapping("/create-post") | ||
public ResponseEntity createPost(@RequestBody CreatePostRequest request) { | ||
PostEntity post = PostEntity.builder().text(request.getText()).userId(request.getUserId()).build(); | ||
var response = postRepository.save(post); | ||
return ResponseEntity.ok().body(response.getId()); | ||
} | ||
|
||
@GetMapping("/view/{userId}") | ||
public ResponseEntity<List<PostEntity>> viewPostsForUser(@PathVariable(value = "userId") long userId) { | ||
List<PostEntity> posts = postRepository.getPostEntitiesByUserIdIs(userId); | ||
return ResponseEntity.ok().body(posts); | ||
} | ||
|
||
@DeleteMapping("/delete/{postId}") | ||
public ResponseEntity deletePost(@PathVariable(value = "postId") long postId) { | ||
postRepository.deleteById(postId); | ||
return ResponseEntity.ok().build(); | ||
} | ||
} |
16 changes: 0 additions & 16 deletions
16
PostManagement/src/main/java/com/skipass/postmanagement/controllers/testController.java
This file was deleted.
Oops, something went wrong.
11 changes: 11 additions & 0 deletions
11
PostManagement/src/main/java/com/skipass/postmanagement/domain/CreatePostRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
package com.skipass.postmanagement.domain; | ||
|
||
import lombok.Builder; | ||
import lombok.Data; | ||
|
||
@Data | ||
@Builder | ||
public class CreatePostRequest { | ||
private String text; | ||
private Long userId; | ||
} |
29 changes: 29 additions & 0 deletions
29
PostManagement/src/main/java/com/skipass/postmanagement/messaging/RabbitMQConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
package com.skipass.postmanagement.messaging; | ||
|
||
import org.springframework.amqp.core.Binding; | ||
import org.springframework.amqp.core.BindingBuilder; | ||
import org.springframework.amqp.core.FanoutExchange; | ||
import org.springframework.amqp.core.Queue; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
|
||
@Configuration | ||
public class RabbitMQConfig { | ||
static final String deletePostExchangeName = "delete-post"; | ||
static final String statisticsQueueName = "delete-post-stats"; | ||
|
||
@Bean | ||
public Queue statisticsQueue() { | ||
return new Queue(statisticsQueueName); | ||
} | ||
|
||
@Bean | ||
public FanoutExchange deletePostExchange() { | ||
return new FanoutExchange(deletePostExchangeName); | ||
} | ||
|
||
@Bean | ||
public Binding statisticsBinding() { | ||
return BindingBuilder.bind(statisticsQueue()).to(deletePostExchange()); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
PostManagement/src/main/java/com/skipass/postmanagement/messaging/RabbitMQProducer.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.skipass.postmanagement.messaging; | ||
|
||
import org.springframework.amqp.core.FanoutExchange; | ||
import org.springframework.amqp.rabbit.core.RabbitTemplate; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class RabbitMQProducer { | ||
@Autowired | ||
private RabbitTemplate rabbitTemplate; | ||
|
||
@Autowired | ||
private FanoutExchange deletePostExchange; | ||
|
||
public void sendDeleteStatisticsAndReactionsForPostMessage(String message) { | ||
rabbitTemplate.convertAndSend( | ||
deletePostExchange.getName(), "", message); | ||
} | ||
} |
17 changes: 13 additions & 4 deletions
17
PostManagement/src/main/java/com/skipass/postmanagement/messaging/RabbitMQReceiver.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,13 +1,22 @@ | ||
package com.skipass.postmanagement.messaging; | ||
|
||
import com.skipass.postmanagement.persistance.PostRepository; | ||
import lombok.AllArgsConstructor; | ||
import org.springframework.amqp.rabbit.annotation.RabbitListener; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@AllArgsConstructor | ||
public class RabbitMQReceiver { | ||
@RabbitListener(queues = "delete-posts") | ||
public void receiveMessage(String message) | ||
{ | ||
System.out.println("Received message in Post service: " + message); | ||
|
||
private RabbitMQProducer rabbitMQProducer; | ||
|
||
private final PostRepository postRepository; | ||
|
||
@RabbitListener(queues = "delete-profile-posts") | ||
public void receiveMessage(long userId) { | ||
System.out.println("Received delete posts for user: " + userId); | ||
postRepository.deletePostEntitiesByUserIdIs(userId); | ||
} | ||
} | ||
|
22 changes: 22 additions & 0 deletions
22
PostManagement/src/main/java/com/skipass/postmanagement/persistance/PostEntity.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
package com.skipass.postmanagement.persistance; | ||
|
||
import jakarta.persistence.*; | ||
import lombok.*; | ||
|
||
@Entity | ||
@Data | ||
@Builder | ||
@Table(name = "posts") | ||
@AllArgsConstructor | ||
@NoArgsConstructor | ||
public class PostEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
Long id; | ||
|
||
String text; | ||
|
||
Long userId; | ||
|
||
} |
17 changes: 17 additions & 0 deletions
17
PostManagement/src/main/java/com/skipass/postmanagement/persistance/PostRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
package com.skipass.postmanagement.persistance; | ||
|
||
import jakarta.transaction.Transactional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.List; | ||
|
||
@Repository | ||
|
||
public interface PostRepository extends JpaRepository<PostEntity, Long> { | ||
List<PostEntity> getPostEntitiesByUserIdIs(long userId); | ||
|
||
@Transactional | ||
void deletePostEntitiesByUserIdIs(long userId); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,8 +6,5 @@ | |
@SpringBootTest | ||
class PostManagementApplicationTests { | ||
|
||
@Test | ||
void contextLoads() { | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,18 @@ | ||
FROM gradle:latest AS build | ||
COPY . /home/gradle/src | ||
WORKDIR /home/gradle/src | ||
COPY . /home | ||
WORKDIR /home | ||
RUN gradle build --no-daemon | ||
|
||
FROM amazoncorretto:17-al2023-jdk | ||
FROM eclipse-temurin:17-jre-alpine as builder | ||
WORKDIR application | ||
COPY --from=build home/build/libs/*.jar application.jar | ||
RUN java -Djarmode=layertools -jar application.jar extract | ||
|
||
EXPOSE 8030 | ||
FROM eclipse-temurin:17-jre-alpine | ||
WORKDIR application | ||
COPY --from=builder application/dependencies/ ./ | ||
COPY --from=builder application/spring-boot-loader/ ./ | ||
COPY --from=builder application/snapshot-dependencies/ ./ | ||
COPY --from=builder application/application/ ./ | ||
|
||
RUN mkdir /app | ||
|
||
COPY --from=build /home/gradle/src/build/libs/*.jar /app/spring-boot-application.jar | ||
|
||
ENTRYPOINT ["java","-jar","/app/spring-boot-application.jar"] | ||
ENTRYPOINT ["java", "org.springframework.boot.loader.launch.JarLauncher"] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.