Skip to content

Commit

Permalink
Merge pull request #432 from bounswe/develop
Browse files Browse the repository at this point in the history
  • Loading branch information
mmtftr authored Oct 22, 2024
2 parents f252328 + 95937cb commit a6a0b1a
Show file tree
Hide file tree
Showing 6 changed files with 38 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/backend_test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,4 @@ jobs:
uses: actions/checkout@v4

- name: Test with Maven
run: docker compose -f dev.yml run --rm backend mvn test
run: docker compose -f dev.yml run --rm backend sh -c "mvn clean install -q && mvn test -B"
18 changes: 18 additions & 0 deletions .github/workflows/validate_pr.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
name: Validate PR to main

on:
pull_request:
branches:
- main

jobs:
validate_pr_source:
runs-on: ubuntu-latest
steps:
- name: Check PR source branch
run: |
if [ "${{ github.head_ref }}" != "develop" ]; then
echo "Error: Pull requests to main are only allowed from the develop branch."
echo "Current branch: ${{ github.head_ref }}"
exit 1
fi
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,8 @@ public ResponseEntity<GenericApiResponse<UserProfileResponseDto>> getUserById(@P
Optional<User> user = userService.getUserById(id);
if (user.isPresent()) {
UserProfileResponseDto userProfileResponseDto = modelMapper.map(user.get(), UserProfileResponseDto.class);
userProfileResponseDto.setSelfFollowing(userService.selfFollowing(user.get()));

GenericApiResponse<UserProfileResponseDto> response = ApiResponseBuilder.buildSuccessResponse(
userProfileResponseDto.getClass(),
"User retrieved successfully",
Expand Down Expand Up @@ -152,6 +154,8 @@ public ResponseEntity<GenericApiResponse<UserProfileResponseDto>> followUser(@Pa
User user = userContextService.getCurrentUser();
User followedUser = userService.followUser(user, id);
UserProfileResponseDto updatedUserProfileResponseDto = modelMapper.map(followedUser, UserProfileResponseDto.class);
updatedUserProfileResponseDto.setSelfFollowing(userService.selfFollowing(followedUser));

GenericApiResponse<UserProfileResponseDto> response = ApiResponseBuilder.buildSuccessResponse(
updatedUserProfileResponseDto.getClass(),
"User followed successfully",
Expand Down Expand Up @@ -195,6 +199,8 @@ public ResponseEntity<GenericApiResponse<UserProfileResponseDto>> unfollowUser(@
User user = userContextService.getCurrentUser();
User unfollowedUser = userService.unfollowUser(user, id);
UserProfileResponseDto updatedUserProfileResponseDto = modelMapper.map(unfollowedUser, UserProfileResponseDto.class);
updatedUserProfileResponseDto.setSelfFollowing(userService.selfFollowing(unfollowedUser));

GenericApiResponse<UserProfileResponseDto> response = ApiResponseBuilder.buildSuccessResponse(
updatedUserProfileResponseDto.getClass(),
"User unfollowed successfully",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,5 +16,6 @@ public class UserProfileResponseDto {
private Long answerCount;
private int followersCount;
private int followingCount;
private boolean selfFollowing;
private int reputationPoints;
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import com.group1.programminglanguagesforum.DTOs.Requests.UserProfileUpdateRequestDto;
import com.group1.programminglanguagesforum.Entities.User;
import com.group1.programminglanguagesforum.Exceptions.UnauthorizedAccessException;
import com.group1.programminglanguagesforum.Exceptions.UserNotFoundException;
import com.group1.programminglanguagesforum.Repositories.UserRepository;
import lombok.RequiredArgsConstructor;
Expand All @@ -15,6 +16,8 @@
@RequiredArgsConstructor
public class UserService {
private final UserRepository userRepository;
private final UserContextService userContextService;

public Optional<User> getUserById(Long id) {
return userRepository.findById(id);
}
Expand Down Expand Up @@ -59,6 +62,14 @@ public User unfollowUser(User user, Long id) throws UserNotFoundException {
return userRepository.save(userToUnfollow);
}

public boolean selfFollowing(User userToCheck) {
try {
return userContextService.getCurrentUser().getFollowing().contains(userToCheck);
} catch (UnauthorizedAccessException e) {
return false;
}
}

public List<User> getFollowers(User user) {
return user.getFollowers().stream().toList();
}
Expand Down
2 changes: 1 addition & 1 deletion compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ services:
ports:
- "8080:8080"
environment:
DB_HOST: db
DB_HOST: db:3306
DB_NAME: programmingforum-test
DB_USER: root
DB_PASSWORD: admin
Expand Down

0 comments on commit a6a0b1a

Please sign in to comment.