Skip to content

Commit

Permalink
Merge pull request #181 from bounswe/mobile-posts2
Browse files Browse the repository at this point in the history
Merge mobile posts branch into main mobile branch
  • Loading branch information
edonmez01 authored May 17, 2024
2 parents 5f88aa5 + 1ccb300 commit a72dfe1
Show file tree
Hide file tree
Showing 82 changed files with 5,303 additions and 2,361 deletions.
Binary file modified .DS_Store
Binary file not shown.
8 changes: 0 additions & 8 deletions .idea/.gitignore

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/inspectionProfiles/Project_Default.xml

This file was deleted.

6 changes: 0 additions & 6 deletions .idea/vcs.xml

This file was deleted.

Binary file modified application/.DS_Store
Binary file not shown.
2 changes: 2 additions & 0 deletions application/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
.idea
.env
53 changes: 53 additions & 0 deletions application/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# Architecture

Fanatic consists of three main parts, namely ```./fanatic-backend```, ```./frontend``` and ```./mobile``` that contain the respective codebase for backend,
frontend and mobile modules.

## Development

To build and start the app locally, run:

```
cd bounswe2024group8/application
docker-compose up --build
```

The script above builds and runs the images on the local Docker client to allow developers to develop and test the application simultaneously. If everything goes as intended, the application should be accessible on:

```
http://localhost:3000
```

## Deployment

Google Cloud Run is our choice of platform to deploy containers for this project. We deploy our project with the following steps:

1. Run a postgres instance in the Cloud App and create a database

2. To deploy backend, use the URL from 1. and run:

```
cd bounswe2024group8/application/fanatic-backend
gcloud run deploy
```

3. To deploy frontend, use the URL from 2. and run:

```
cd bounswe2024group8/application/frontend
gcloud run deploy
```


If everything goes as intended, the backend should be accessible at:

```
https://fanatic-backend-bjbpof6jaq-oa.a.run.app/
```

Frontend should be accessible at:

```
https://frontend-bjbpof6jaq-oa.a.run.app/
```

2 changes: 1 addition & 1 deletion application/docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ services:
context: ./frontend
dockerfile: Dockerfile
ports:
- "80:80"
- "3000:3000"
depends_on:
- backend

Expand Down
10 changes: 10 additions & 0 deletions application/fanatic-backend/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-validation</artifactId>
<version>3.2.1</version>
</dependency>
<dependency>
<groupId>org.projectlombok</groupId>
<artifactId>lombok</artifactId>
Expand Down Expand Up @@ -75,6 +80,11 @@
<type>pom</type>
<version>3.17.0</version>
</dependency>
<dependency>
<groupId>com.google.cloud.sql</groupId>
<artifactId>postgres-socket-factory</artifactId>
<version>1.18.0</version>
</dependency>
</dependencies>

<build>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Excepti
.requestMatchers(HttpMethod.GET, "/api/v1/auth/login").permitAll()
.requestMatchers(HttpMethod.POST, "/api/v1/auth/register").permitAll()
.requestMatchers("/api/v1/auth/**").permitAll()
.requestMatchers("/api/v1/communities").permitAll()
.anyRequest().authenticated()
)
.sessionManagement(session -> session.sessionCreationPolicy(STATELESS))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import com.example.fanaticbackend.payload.AuthenticationResponse;
import com.example.fanaticbackend.payload.RegisterRequest;
import com.example.fanaticbackend.service.AuthenticationService;
import jakarta.validation.Valid;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
Expand All @@ -23,7 +24,7 @@ public class AuthenticationController {

@PostMapping("/register")
public ResponseEntity<AuthenticationResponse> register(
@RequestBody RegisterRequest request
@Valid @RequestBody RegisterRequest request
) {
return ResponseEntity.ok(authenticationService.register(request));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.example.fanaticbackend.controller;

import com.example.fanaticbackend.model.User;
import com.example.fanaticbackend.payload.CommentResponse;
import com.example.fanaticbackend.service.CommentService;
import com.example.fanaticbackend.service.CommunityService;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/api/v1/comments")
@RequiredArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class CommentController {

final CommentService commentService;


@GetMapping("/post/{postId}")
public ResponseEntity<List<CommentResponse>> getComments(
@AuthenticationPrincipal UserDetails userDetails,
@PathVariable Long postId) {

List<CommentResponse> comments = commentService.getCommentsByPostId((User) userDetails, postId);

if (comments.isEmpty()) {
return ResponseEntity.notFound().build();
}

return ResponseEntity.ok(comments);

}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package com.example.fanaticbackend.controller;

import com.example.fanaticbackend.model.Community;
import com.example.fanaticbackend.service.CommunityService;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/communities")
@RequiredArgsConstructor
@FieldDefaults(level = AccessLevel.PRIVATE)
public class CommunityController {

final CommunityService communityService;


@GetMapping("{communityName}")
public ResponseEntity<Community> getCommunityByName(
@PathVariable String communityName
) {

Community community = communityService.findCommunityByTeamElseThrow(communityName);

return ResponseEntity.ok(community);
}


@PostMapping("")
public ResponseEntity<Boolean> createAll() {

communityService.createAllCommunities();

return ResponseEntity.ok(true);
}
}
Original file line number Diff line number Diff line change
@@ -1,13 +1,20 @@
package com.example.fanaticbackend.controller;

import com.example.fanaticbackend.model.Comment;
import com.example.fanaticbackend.model.Post;
import com.example.fanaticbackend.payload.PostCreateRequest;
import com.example.fanaticbackend.payload.SearchResponse;
import com.example.fanaticbackend.model.User;
import com.example.fanaticbackend.model.enums.ReactionType;
import com.example.fanaticbackend.payload.*;
import com.example.fanaticbackend.service.CommentService;
import com.example.fanaticbackend.service.PostService;
import com.example.fanaticbackend.service.UserService;
import jakarta.validation.Valid;
import lombok.AccessLevel;
import lombok.RequiredArgsConstructor;
import lombok.experimental.FieldDefaults;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.security.core.userdetails.UserDetails;
import org.springframework.web.bind.annotation.*;

import java.util.List;
Expand All @@ -19,21 +26,26 @@
public class PostController {

final PostService postService;
final CommentService commentService;

@PostMapping("")
public ResponseEntity<Post> create(
@RequestBody PostCreateRequest request) {
@AuthenticationPrincipal UserDetails userDetails,
@Valid @ModelAttribute PostCreateRequest request) {

Post savedPost = postService.create(request);
User user = (User) userDetails;

Post savedPost = postService.create(user, request);

return ResponseEntity.ok(savedPost);
}

@GetMapping("")
public ResponseEntity<SearchResponse> search(
@AuthenticationPrincipal UserDetails userDetails,
@RequestParam String param) {

var result = postService.searchPost(param);
var result = postService.searchPost((User) userDetails, param);

if (result.getPosts().isEmpty() && result.getTeam() == null) {
return ResponseEntity.notFound().build();
Expand All @@ -43,9 +55,60 @@ public ResponseEntity<SearchResponse> search(
}

@GetMapping("/feed")
public ResponseEntity<List<Post>> getFeed() {
public ResponseEntity<List<PostResponse>> getFeed(
@AuthenticationPrincipal UserDetails userDetails) {

List<PostResponse> posts = postService.getFeed((User) userDetails);

if (posts.isEmpty()) {
return ResponseEntity.notFound().build();
}

return ResponseEntity.ok(posts);
}

@PostMapping("/{postId}/react")
public ResponseEntity<ReactionResponse> reactPost(
@AuthenticationPrincipal UserDetails userDetails,
@Valid @RequestBody ReactionRequest request,
@PathVariable Long postId) {
// @oguz
ReactionResponse result = postService.reactToPost((User) userDetails, request, postId);


return ResponseEntity.ok(result);

}

@PostMapping("/comment")
public ResponseEntity<Comment> createComment(
@AuthenticationPrincipal UserDetails userDetails,
@RequestBody CommentCreateRequest request) {

User user = (User) userDetails;
Comment savedComment = commentService.createComment((User) userDetails, request);

return ResponseEntity.ok(savedComment);
}

@PostMapping("/comment/{commentId}/react")
public ResponseEntity<CommentReactionResponse> reactComment(
@AuthenticationPrincipal UserDetails userDetails,
@RequestParam ReactionType reactionType,
@PathVariable Long commentId) {
// @oguz
CommentReactionResponse result = commentService.reactToComment((User) userDetails, reactionType, commentId);

return ResponseEntity.ok(result);

}

@GetMapping("/community/{communityTeam}")
public ResponseEntity<List<PostResponse>> getPostsOfCommunity(
@AuthenticationPrincipal UserDetails userDetails,
@PathVariable String communityTeam) {

List<Post> posts = postService.getFeed();
List<PostResponse> posts = postService.getPostsByCommunity((User) userDetails, communityTeam);

if (posts.isEmpty()) {
return ResponseEntity.notFound().build();
Expand All @@ -54,5 +117,50 @@ public ResponseEntity<List<Post>> getFeed() {
return ResponseEntity.ok(posts);
}

@GetMapping("/user/{userId}")
public ResponseEntity<List<PostResponse>> getPostsOfUser(
@AuthenticationPrincipal UserDetails userDetails,
@PathVariable Long userId) {

List<PostResponse> posts = postService.getPostsByUser((User) userDetails, userId);

if (posts.isEmpty()) {
return ResponseEntity.notFound().build();
}

return ResponseEntity.ok(posts);
}


@GetMapping("/user/{userId}/reacted")
public ResponseEntity<List<PostResponse>> getPostsUserReactedTo(
@AuthenticationPrincipal UserDetails userDetails,
@PathVariable Long userId) {

List<PostResponse> posts = postService.getPostsUserReactedTo((User) userDetails, userId);

if (posts.isEmpty()) {
return ResponseEntity.notFound().build();
}

return ResponseEntity.ok(posts);
}

@GetMapping("/user/{userId}/bookmarked")
public ResponseEntity<List<PostResponse>> getBookmarkedPosts(
@AuthenticationPrincipal UserDetails userDetails,
@PathVariable Long userId) {

List<PostResponse> posts = postService.getBookmarkedPosts((User) userDetails, userId);

if (posts.isEmpty()) {
return ResponseEntity.notFound().build();
}

return ResponseEntity.ok(posts);
}




}
Loading

0 comments on commit a72dfe1

Please sign in to comment.