Skip to content

Commit

Permalink
Merge branch 'master' into feat/store-1115
Browse files Browse the repository at this point in the history
  • Loading branch information
eckrin authored Nov 17, 2023
2 parents 0436038 + 16e2ed7 commit d8121ea
Show file tree
Hide file tree
Showing 24 changed files with 273 additions and 39 deletions.
6 changes: 3 additions & 3 deletions .github/workflows/deploy.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,9 +5,9 @@ name: Deploy to Amazon EC2
# Controls when the workflow will run
on:
# Triggers the 'Deploy' workflow when the pull request closed but only for the "master" branch
pull_request:
types : [ closed ]
branches: [ master ]
# pull_request:
# types : [ closed ]
# branches: [ master ]
push:
branches: [ "master" ]
# Allows you to run this workflow manually from the Actions tab
Expand Down
9 changes: 4 additions & 5 deletions src/main/java/com/kusitms/jipbap/auth/AuthController.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,15 +19,14 @@ public class AuthController {
private final AuthService authService;

@Operation(summary = "일반 회원 가입")
@PostMapping("/signUp")
@PostMapping("/signup")
@ResponseStatus(HttpStatus.OK)
public CommonResponse<String> signUp(@Valid @RequestBody SignUpRequestDto dto) {
authService.signUp(dto);
return new CommonResponse<>("회원가입 성공");
public CommonResponse<SignUpResponseDto> signUp(@Valid @RequestBody SignUpRequestDto dto) {
return new CommonResponse<>(authService.signUp(dto));
}

@Operation(summary = "로그인")
@PostMapping("/signIn")
@PostMapping("/signin")
@ResponseStatus(HttpStatus.OK)
public CommonResponse<SignInResponseDto> signIn(@Valid @RequestBody SignInRequestDto dto) {
return new CommonResponse<>(authService.signIn(dto.getEmail(), dto.getPassword()));
Expand Down
16 changes: 7 additions & 9 deletions src/main/java/com/kusitms/jipbap/auth/AuthService.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,13 +4,11 @@
import com.fasterxml.jackson.databind.DeserializationFeature;
import com.fasterxml.jackson.databind.JsonMappingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.kusitms.jipbap.auth.dto.KakaoProfileDto;
import com.kusitms.jipbap.auth.dto.ReissueResponseDto;
import com.kusitms.jipbap.auth.dto.SignInResponseDto;
import com.kusitms.jipbap.auth.dto.SignUpRequestDto;
import com.kusitms.jipbap.auth.dto.*;
import com.kusitms.jipbap.auth.exception.*;
import com.kusitms.jipbap.security.jwt.JwtTokenProvider;
import com.kusitms.jipbap.security.jwt.TokenInfo;
import com.kusitms.jipbap.user.CountryPhoneCode;
import com.kusitms.jipbap.user.Role;
import com.kusitms.jipbap.user.User;
import com.kusitms.jipbap.user.UserRepository;
Expand Down Expand Up @@ -50,24 +48,24 @@ public class AuthService {
* @param dto
*/
@Transactional
public void signUp(SignUpRequestDto dto) {
public SignUpResponseDto signUp(SignUpRequestDto dto) {

if(userRepository.existsByEmail(dto.getEmail())) throw new EmailExistsException("이미 가입한 이메일입니다.");
if(userRepository.existsByUsername(dto.getUsername())) throw new UsernameExistsException("이미 존재하는 닉네임입니다.");
userRepository.save(
User user = userRepository.save(
User.builder()
.id(null)
.email(dto.getEmail())
.password(passwordEncoder.encode(dto.getPassword()))
.username(dto.getUsername())
.address(dto.getAddress())
.countryPhoneCode(dto.getCountryPhoneCode())
.phoneNum(dto.getPhoneNum())
.role(dto.getRole())
.refreshToken(null)
.oauth(INAPP)
.build()
);

return new SignUpResponseDto(user.getId(), user.getEmail(), user.getUsername());
}

/**
Expand Down Expand Up @@ -151,7 +149,7 @@ public SignInResponseDto kakaoAutoSignIn(KakaoProfileDto profile) {
kakaoUser.getEmail(),
kakaoUser.getPassword(),
kakaoUser.getUsername(),
kakaoUser.getAddress(),
CountryPhoneCode.KOREA, // 카카오
kakaoUser.getPhoneNum(),
Role.USER,
kakaoUser.getImage()
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.kusitms.jipbap.auth.dto;

import com.kusitms.jipbap.user.CountryPhoneCode;
import com.kusitms.jipbap.user.Role;
import lombok.AllArgsConstructor;
import lombok.Data;
Expand Down
19 changes: 12 additions & 7 deletions src/main/java/com/kusitms/jipbap/auth/dto/SignUpRequestDto.java
Original file line number Diff line number Diff line change
@@ -1,31 +1,36 @@
package com.kusitms.jipbap.auth.dto;

import com.kusitms.jipbap.user.CountryPhoneCode;
import com.kusitms.jipbap.user.Role;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.*;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;

@Data
@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class SignUpRequestDto {
@Email
@NotBlank
@Schema(description = "이메일", example = "[email protected]")
private String email;
@NotBlank
@Schema(description = "비밀번호", example = "1234abcd")
private String password;
@NotBlank
@Schema(description = "닉네임", example = "조파랑")
private String username;
@NotBlank
private String address;
@Schema(description = "국가 전화번호 코드", example = "KOREA")
private CountryPhoneCode countryPhoneCode;
@NotBlank
@Schema(description = "전화번호", example = "010-1234-5678")
private String phoneNum;
@NotBlank
@Schema(description = "역할", example = "USER")
private Role role;

private String imageUrl;

}
21 changes: 21 additions & 0 deletions src/main/java/com/kusitms/jipbap/auth/dto/SignUpResponseDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.kusitms.jipbap.auth.dto;

import com.kusitms.jipbap.user.CountryPhoneCode;
import com.kusitms.jipbap.user.Role;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import javax.validation.constraints.Email;
import javax.validation.constraints.NotBlank;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class SignUpResponseDto {
private Long id;
private String email;
private String username;
}
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,8 @@ public WebSecurityCustomizer webSecurityCustomizer() {
"/auth/**",
"/ws/**", //ws://localhost:8080/ws/chat
"/ws-stomp/**",
"/addresses/**"
"/addresses/**",
"/users/nickname"
);
}
}
9 changes: 7 additions & 2 deletions src/main/java/com/kusitms/jipbap/food/Food.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,8 +32,13 @@ public class Food extends DateEntity {

@Column(name = "food_name")
private String name;
private Long price;

private Long dollarPrice;
private Long canadaPrice;
private String image;
private String description;
private Long recommendCount;
private String image;
private String foodPackage; // 배달포장 모두 가능, 배달 모두 가능, 포장 모두 가능


}
9 changes: 8 additions & 1 deletion src/main/java/com/kusitms/jipbap/food/FoodController.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,10 +40,17 @@ public CommonResponse<FoodDto> registerFood(
@Operation(summary = "메뉴 하나 상세조회")
@GetMapping("/{foodId}")
@ResponseStatus(HttpStatus.OK)
public CommonResponse<FoodDto> getFoodDetail(@PathVariable Long foodId) {
public CommonResponse<FoodDetailResponse> getFoodDetail(@PathVariable Long foodId) {
return new CommonResponse<>(foodService.getFoodDetail(foodId));
}

@Operation(summary = "메뉴 당 옵션 상세조회")
@GetMapping("/{foodId}/option")
@ResponseStatus(HttpStatus.OK)
public CommonResponse<List<FoodOptionResponse>> getFoodDetailByOption(@PathVariable Long foodId ) {
return new CommonResponse<>(foodService.getFoodDetailByOption(foodId));
}

@Operation(summary = "홈에서 현재 지역 내에서 인기메뉴 조회하기")
@GetMapping("/home")
@ResponseStatus(HttpStatus.OK)
Expand Down
30 changes: 30 additions & 0 deletions src/main/java/com/kusitms/jipbap/food/FoodOption.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
package com.kusitms.jipbap.food;

import jakarta.persistence.*;
import lombok.*;

@Entity
@Table(name = "tb_food_option")
@Getter
@Setter
@Builder
@AllArgsConstructor
@NoArgsConstructor
public class FoodOption {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name ="id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "food_id")
private Food food;

private String name;

private Long dollarPrice;

private Long canadaPrice;

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.kusitms.jipbap.food;

import org.springframework.data.jpa.repository.JpaRepository;

import java.util.List;

public interface FoodOptionRepository extends JpaRepository<FoodOption, Long> {
List<FoodOption> findAllByFood(Food food);
}
51 changes: 45 additions & 6 deletions src/main/java/com/kusitms/jipbap/food/FoodService.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ public class FoodService {
private final FoodRepository foodRepository;
private final CategoryRepository categoryRepository;
private final OrderRepository orderRepository;
private final FoodOptionRepository foodOptionRepository;

private final AmazonS3 amazonS3;

Expand Down Expand Up @@ -72,14 +73,50 @@ public FoodDto registerFood(String email, RegisterFoodRequestDto dto, MultipartF
}

Food food = foodRepository.save(
new Food(null, store, category, dto.getName(), dto.getPrice(), dto.getDescription(), 0L, imageUri)
Food.builder()
.store(store)
.category(category)
.name(dto.getName())
.dollarPrice(dto.getDollarPrice())
.canadaPrice(dto.getCanadaPrice())
.description(dto.getDescription())
.recommendCount(0L)
.image(imageUri)
.foodPackage(dto.getFoodPackage())
.build()
);
return new FoodDto(food.getId(), store.getId(), category.getId(), food.getName(), food.getPrice(), food.getDescription(), food.getImage());

// FoodOption 저장
if (dto.getFoodOptionRequestList() != null && !dto.getFoodOptionRequestList().isEmpty()) {
for (FoodOptionRequest foodOptionRequest : dto.getFoodOptionRequestList()) {
FoodOption foodOption = FoodOption.builder()
.food(food)
.name(foodOptionRequest.getName())
.dollarPrice(foodOptionRequest.getDollarPrice())
.canadaPrice(foodOptionRequest.getCanadaPrice())
.build();

foodOptionRepository.save(foodOption);
}
}

return new FoodDto(food.getId(), store.getId(), category.getId(), food.getName(), food.getDollarPrice(), food.getCanadaPrice(), food.getDescription(), food.getImage());
}

public FoodDto getFoodDetail(Long foodId) {
public FoodDetailResponse getFoodDetail(Long foodId) {
Food food = foodRepository.findById(foodId).orElseThrow(()-> new FoodNotExistsException("해당 음식 Id는 유효하지 않습니다."));
return new FoodDto(food.getId(), food.getStore().getId(), food.getCategory().getId(), food.getName(), food.getPrice(), food.getDescription(), food.getImage());
List<FoodOptionResponse> foodOptionResponseList = foodOptionRepository.findAllByFood(food).stream()
.map(foodOption -> new FoodOptionResponse(foodOption.getId(), foodOption.getName(), foodOption.getDollarPrice(), foodOption.getCanadaPrice()))
.collect(Collectors.toList());
return new FoodDetailResponse(food.getId(), food.getStore().getId(), food.getCategory().getId(), food.getName(), food.getDollarPrice(), food.getCanadaPrice(), food.getDescription(), food.getImage(), foodOptionResponseList);
}

public List<FoodOptionResponse> getFoodDetailByOption(Long foodId) {
Food food = foodRepository.findById(foodId).orElseThrow(()-> new FoodNotExistsException("해당 음식 Id는 유효하지 않습니다."));
List<FoodOptionResponse> foodOptionResponseList = foodOptionRepository.findAllByFood(food).stream()
.map(foodOption -> new FoodOptionResponse(foodOption.getId(), foodOption.getName(), foodOption.getDollarPrice(), foodOption.getCanadaPrice()))
.collect(Collectors.toList());
return foodOptionResponseList;
}

public List<BestSellingFoodResponse> getBestSellingFoodByRegion(String email) {
Expand All @@ -91,7 +128,8 @@ public List<BestSellingFoodResponse> getBestSellingFoodByRegion(String email) {
.map(food -> new BestSellingFoodResponse(
food.getName(),
food.getStore().getName(),
food.getPrice()
food.getDollarPrice(),
food.getCanadaPrice()
))
.collect(Collectors.toList());

Expand All @@ -109,7 +147,8 @@ public List<FoodDto> getFoodByCategory(Long categoryId){
food.getStore().getId(),
food.getCategory().getId(),
food.getName(),
food.getPrice(),
food.getDollarPrice(),
food.getCanadaPrice(),
food.getDescription(),
food.getImage()
))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,5 +12,6 @@
public class BestSellingFoodResponse {
private String name;
private String storeName;
private Long price;
private Long dollarPrice;
private Long canadaPrice;
}
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,17 @@ public class FoodDetailByStoreResponse {
private Long id;
private Long categoryId;
private String name;
private Long price;
private Long dollarPrice;
private Long canadaPrice;
private String description;
private Long recommendCount;

public FoodDetailByStoreResponse(Food food){
this.id = food.getId();
this.categoryId = food.getCategory().getId();
this.name = food.getName();
this.price = food.getPrice();
this.dollarPrice = food.getDollarPrice();
this.canadaPrice = food.getCanadaPrice();
this.description = food.getDescription();
this.recommendCount = food.getRecommendCount();
}
Expand Down
24 changes: 24 additions & 0 deletions src/main/java/com/kusitms/jipbap/food/dto/FoodDetailResponse.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package com.kusitms.jipbap.food.dto;

import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NoArgsConstructor;
import lombok.Setter;

import java.util.List;

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
public class FoodDetailResponse {
private Long id;
private Long storeId;
private Long categoryId;
private String name;
private Long dollarPrice;
private Long canadaPrice;
private String description;
private String image;
private List<FoodOptionResponse> foodOptionResponseList;
}
3 changes: 2 additions & 1 deletion src/main/java/com/kusitms/jipbap/food/dto/FoodDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,8 @@ public class FoodDto {
private Long storeId;
private Long categoryId;
private String name;
private Long price;
private Long dollarPrice;
private Long canadaPrice;
private String description;
private String image;

Expand Down
Loading

0 comments on commit d8121ea

Please sign in to comment.