Skip to content

Commit

Permalink
Merge pull request #31 from team1-healthy-fb-hackerton/feat/issue-30-…
Browse files Browse the repository at this point in the history
…item-details

#30 아이템 상세 페이지
  • Loading branch information
hyeon-gyu authored May 4, 2024
2 parents 3b08efc + 06cf0ed commit 79d855b
Show file tree
Hide file tree
Showing 8 changed files with 129 additions and 132 deletions.
24 changes: 14 additions & 10 deletions src/main/java/team1/hackerton/controller/ItemController.java
Original file line number Diff line number Diff line change
@@ -1,14 +1,12 @@
package team1.hackerton.controller;

import io.swagger.v3.oas.annotations.Operation;
import jakarta.persistence.PreUpdate;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.security.core.annotation.AuthenticationPrincipal;
import org.springframework.web.bind.annotation.*;
import team1.hackerton.domain.Member;
import team1.hackerton.dto.request.CreateCategoryRequestDto;
import team1.hackerton.dto.request.CreateGradientRequestDto;
import team1.hackerton.dto.request.CreateItemRequestDto;
import team1.hackerton.dto.request.LikeItemRequestDto;
import team1.hackerton.dto.response.ItemDetailResponseDto;
Expand Down Expand Up @@ -40,14 +38,20 @@ public ResponseEntity<String> addItem(
return itemDetailService.addItem(dto);
}

@PostMapping("/addGredient")
@Operation(summary = "성분 생성", description = "성분 생성")
public ResponseEntity<String> addGradient(
@RequestBody CreateGradientRequestDto dto
){
return itemDetailService.addGradient(dto);
}

// @Operation(summary = "상품디테일")
// @GetMapping("/detail/{itemId}")
// public ResponseEntity<ItemDetailResponseDto.ItemDetailDto> readItemDetail(@AuthenticationPrincipal CustomUserDetails userDetails, @PathVariable(name="itemId") Long itemId){
//
// return itemDetailService.readItemDetail(userDetails, itemId);
//
// }

@Operation(summary = "상품 상세 목록")
@GetMapping("/detail/{itemId}")
public ResponseEntity<ItemDetailResponseDto> readItemDetail(@AuthenticationPrincipal CustomUserDetails userDetails, @PathVariable(name="itemId") Long itemId){
return itemDetailService.readItemDetail(userDetails, itemId);
}

@PostMapping("/detail")
@Operation(summary = "상품 좋아요")
Expand Down
54 changes: 0 additions & 54 deletions src/main/java/team1/hackerton/converter/ItemDetailConverter.java

This file was deleted.

10 changes: 9 additions & 1 deletion src/main/java/team1/hackerton/domain/Gradient.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import jakarta.persistence.*;
import lombok.*;
import team1.hackerton.domain.common.BaseEntity;
import team1.hackerton.domain.enums.Type;


@Entity
Expand All @@ -25,5 +26,12 @@ public class Gradient extends BaseEntity {

private String description;

private int type;
private Type type;

public Gradient(Item item, String name, String description, Type type) {
this.item = item;
this.name = name;
this.description = description;
this.type = type;
}
}
5 changes: 5 additions & 0 deletions src/main/java/team1/hackerton/domain/enums/Type.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
package team1.hackerton.domain.enums;

public enum Type {
HEALTHY, CAREFUL, LEAK
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package team1.hackerton.dto.process;

import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor

public class ItemDetailProcessDto {

private Long itemId;
private int zeroSugar;
private int zeroKcal;
private String itemUrl;
private String company;
private String store;
private String name;
private int price;
private String nutritionUrl;
private int like;
private String infoUrl;

@Builder
public ItemDetailProcessDto(Long itemId, int zeroSugar, int zeroKcal, String itemUrl, String company, String store, String name, int price, String nutritionUrl, int like, String infoUrl) {
this.itemId = itemId;
this.zeroSugar = zeroSugar;
this.zeroKcal = zeroKcal;
this.itemUrl = itemUrl;
this.company = company;
this.store = store;
this.name = name;
this.price = price;
this.nutritionUrl = nutritionUrl;
this.like = like;
this.infoUrl = infoUrl;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
package team1.hackerton.dto.request;


import lombok.Getter;
import lombok.NoArgsConstructor;
import team1.hackerton.domain.enums.Rate;
import team1.hackerton.domain.enums.Type;

@Getter
@NoArgsConstructor
public class CreateGradientRequestDto {

private Type type ;
private String name;
private String description;
private Long itemId;

public CreateGradientRequestDto(Type type, String name, String description, Long itemId) {
this.type = type;
this.name = name;
this.description = description;
this.itemId = itemId;
}
}
Original file line number Diff line number Diff line change
@@ -1,60 +1,22 @@
package team1.hackerton.dto.response;

import lombok.Builder;

import lombok.Getter;
import lombok.NoArgsConstructor;
import team1.hackerton.domain.Gradient;
import team1.hackerton.dto.process.ItemDetailProcessDto;

import java.time.LocalDateTime;
import java.util.List;

@Getter
@NoArgsConstructor
public class ItemDetailResponseDto {

@Builder
public static class ItemDetailDto{

private Long itemId;

private boolean zeroSugar;

private boolean zeroKcal;

private String itemUrl;

private String company;

private String store;

private String name;

private int price;

private String nutritionUrl;

private int gradientCnt;

private boolean like;


private String infoUrl;

private LocalDateTime createdAt;

private LocalDateTime updatedAt;

private List<GradientDto> gradientDto;
}

@Builder
public static class GradientDto{
private Long gradientId;

private Long itemId;

private String name;

private String description;

private int type;
private ItemDetailProcessDto detail;
private List<Gradient> gradientList;

public ItemDetailResponseDto(ItemDetailProcessDto detail, List<Gradient> gradientList) {
this.detail = detail;
this.gradientList = gradientList;
}

}
46 changes: 28 additions & 18 deletions src/main/java/team1/hackerton/service/ItemDetailService.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,17 @@
import team1.hackerton.domain.*;
import team1.hackerton.dto.process.TotListProcessDto;
import team1.hackerton.dto.request.CreateCategoryRequestDto;
import team1.hackerton.dto.request.CreateGradientRequestDto;
import team1.hackerton.dto.request.CreateItemRequestDto;
import team1.hackerton.dto.request.LikeItemRequestDto;
import team1.hackerton.dto.process.ItemDetailProcessDto;
import team1.hackerton.dto.response.ItemDetailResponseDto;
import team1.hackerton.dto.response.TotListResponseDto;
import team1.hackerton.repository.*;
import team1.hackerton.security.CustomUserDetails;

import java.util.ArrayList;
import java.util.List;
import java.util.Optional;

@Service
@RequiredArgsConstructor
Expand All @@ -36,23 +37,25 @@ public class ItemDetailService {
@Value("${cloud.aws.s3.uploadPath}")
private String defaultUrl;

// public ResponseEntity<ItemDetailResponseDto.ItemDetailDto> readItemDetail(CustomUserDetails userDetails, Long itemId) {
// Long memberId = userDetails.getMemberId();
// Member member = memberRepository.findById(memberId).orElseThrow(() -> new EntityNotFoundException("에러"));
// Item item = itemRepository.findById(itemId).orElseThrow(() -> new EntityNotFoundException("에러"));
//
// List<Gradient> gradientList = gradientRepository.findByItem(item);
//
//
// MemberItem memberItem = memberItemRepository.findByMemberAndItem(member, item);
// if (memberItem.getItem() == null) {
// ItemDetailResponseDto.ItemDetailDto dto = ItemDetailConverter.toDto(item, gradientList, false);
// return ResponseEntity.ok(dto);
// }
//
// ItemDetailResponseDto.ItemDetailDto dto = ItemDetailConverter.toDto(item, gradientList, true);
// return ResponseEntity.ok(dto);
// }
public ResponseEntity<ItemDetailResponseDto> readItemDetail(CustomUserDetails userDetails, Long itemId) {

Item item = itemRepository.findById(itemId).orElseThrow(() -> new EntityNotFoundException("에러"));
ItemDetailProcessDto processDto = ItemDetailProcessDto.builder()
.itemId(item.getItemId())
.zeroKcal(item.getZeroKcal())
.zeroSugar(item.getZeroSugar())
.itemUrl(item.getUrl())
.company(item.getCompany())
.store(item.getStore())
.name(item.getName())
.price(item.getPrice())
.nutritionUrl(item.getNutritionUrl())
.like(item.getLikeCnt())
.infoUrl(item.getInfoUrl()).build();

List<Gradient> gradientList = item.getGradientList();
return ResponseEntity.ok(new ItemDetailResponseDto(processDto, gradientList));
}

public ResponseEntity<String> likeItem(CustomUserDetails userDetails, LikeItemRequestDto dto){
Long memberId = userDetails.getMemberId();
Expand Down Expand Up @@ -103,4 +106,11 @@ public ResponseEntity<String> addItem(CreateItemRequestDto dto){
return ResponseEntity.ok("ok");
}

public ResponseEntity<String> addGradient(CreateGradientRequestDto dto){
Item item = itemRepository.findById(dto.getItemId()).orElseThrow(() -> new EntityNotFoundException("에러"));
Gradient gradient = new Gradient(item, dto.getName(), dto.getDescription(), dto.getType());
gradientRepository.save(gradient);
return ResponseEntity.ok("ok");
}

}

0 comments on commit 79d855b

Please sign in to comment.