Skip to content

Commit

Permalink
Merge branch 'develop' into staging
Browse files Browse the repository at this point in the history
  • Loading branch information
mmtftr committed May 17, 2024
2 parents b10e922 + ac8bef4 commit ae277fb
Show file tree
Hide file tree
Showing 24 changed files with 494 additions and 60 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ public ResponseEntity<?> getUserDetails(@AuthenticationPrincipal UserDetails use
return ResponseEntity.ok(new SuccessResponse<>(200, userProfile, "User profile fetched successfully"));
}
}
return ResponseEntity.ok(new ErrorResponse(204, "User not found"));
return ResponseEntity.status(HttpStatus.UNAUTHORIZED).body(new ErrorResponse(401,"Authentication required") );
}

@DeleteMapping("/{userId}/follow")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,7 @@
@AllArgsConstructor
public class UserUpdateFormDto {
private String username;
private String firstName;
private String lastName;
private String name;
private String bio;
private String gender;
private String profilePicture;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import java.util.Objects;

Expand All @@ -19,10 +21,12 @@ public class Bookmark {
private Integer id;

@ManyToOne
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "user_id", nullable = false)
private User user;

@ManyToOne
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "recipe_id", nullable = false)
private Recipe recipe;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@
import jakarta.persistence.*;
import lombok.*;
import org.apache.commons.lang3.builder.ToStringExclude;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import java.time.LocalDateTime;
import java.util.Date;
Expand All @@ -23,11 +25,13 @@ public class Comment {


@ManyToOne
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "user_id", nullable = false)
@ToString.Exclude
private User user;

@ManyToOne
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "recipe_id", nullable = false)
private Recipe recipe;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import java.util.Objects;

Expand All @@ -19,6 +21,7 @@ public class Ingredient {
private String name;
private String amount; // E.g. grams, cups, etc.
@ManyToOne
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "recipe_id") // This column in the Ingredient table will hold the foreign key to the Recipe
private Recipe recipe; // This is the 'recipe' field expected by the 'mappedBy' attribute
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import java.util.Objects;

Expand All @@ -18,10 +20,12 @@ public class Rating {
private Integer id;

@ManyToOne
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "user_id", nullable = false)
private User user;

@ManyToOne
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "recipe_id", nullable = false)
private Recipe recipe;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ public class Recipe {
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Integer id;
private String name;
@Column(length = 5000)
private String description;
@Column(length = 5000)
private String instructions;
private int prepTime;
private int cookTime;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.OnDelete;
import org.hibernate.annotations.OnDeleteAction;

import java.time.LocalDateTime;
import java.util.Objects;
Expand All @@ -19,11 +21,13 @@ public class Upvote {
private Integer id;

@ManyToOne
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "user_id", nullable = false)
private User user;
private LocalDateTime createdDate = LocalDateTime.now();

@ManyToOne
@OnDelete(action = OnDeleteAction.CASCADE)
@JoinColumn(name = "comment_id", nullable = false)
private Comment comment;
@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Set;
Expand Down Expand Up @@ -148,8 +149,9 @@ public UserProfileDto updateUserProfile(Integer userId, UserUpdateFormDto profil
User user = userRepository.findById(userId)
.orElseThrow(() -> new EntityNotFoundException("User not found"));

user.setFirstName(profileDto.getFirstName());
user.setLastName(profileDto.getLastName());
ArrayList<String> names = new ArrayList<>(List.of(profileDto.getName().split(" ")));
user.setLastName(names.remove(names.size() - 1));
user.setFirstName(String.join(" ", names));
user.setBio(profileDto.getBio());
user.setGender(profileDto.getGender());
user.setProfilePicture(profileDto.getProfilePicture());
Expand Down
67 changes: 67 additions & 0 deletions backend/src/test/java/com/group1/cuisines/DishControllerTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package com.group1.cuisines;

import com.group1.cuisines.controllers.DishController;
import com.group1.cuisines.dao.response.ErrorResponse;
import com.group1.cuisines.dao.response.SuccessResponse;
import com.group1.cuisines.dto.DishDto;
import com.group1.cuisines.services.DishService;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.mockito.junit.jupiter.MockitoExtension;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
public class DishControllerTest {

@InjectMocks
private DishController dishController;

@Mock
private DishService dishService;

@BeforeEach
void setUp() {
MockitoAnnotations.openMocks(this);
}

@Test
public void testGetDishById_Found() {
String dishId = "test-id";
DishDto mockDish = DishDto.builder()
.id(dishId)
.name("Test Dish")
.description("Delicious dish")
.image("./image.jpg")
.countries("USA")
.ingredients("Ingredients")
.foodTypes("Type")
.cuisines("Cuisine")
.build();

when(dishService.getDishById(dishId)).thenReturn(mockDish);

SuccessResponse<DishDto> response = (SuccessResponse<DishDto>) dishController.getDishById(dishId).getBody();

DishDto actualDish = response.getData();

assertEquals(200, response.getStatus());
assertEquals(mockDish, actualDish);
}

@Test
public void testGetDishById_NotFound() {
String dishId = "test-id";
when(dishService.getDishById(dishId)).thenReturn(null);

ErrorResponse response = (ErrorResponse) dishController.getDishById(dishId).getBody();

assertEquals(400, response.getStatus());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -104,7 +104,7 @@ void testGetUserDetails_UserNotFound() {

ResponseEntity<?> response = userController.getUserDetails(userDetails);

assertEquals(204, ((ErrorResponse) response.getBody()).getStatus());
assertEquals(401, ((ErrorResponse) response.getBody()).getStatus());
verify(userRepository).findByUsername(username);
}

Expand Down
1 change: 0 additions & 1 deletion frontend/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,6 @@
"lint-staged": {
"*/**/*.{js,jsx,ts,tsx}": [
"prettier --write",

"eslint --report-unused-disable-directives --max-warnings 0"
],
"*/**/*.{json,css,md}": [
Expand Down
Loading

0 comments on commit ae277fb

Please sign in to comment.