Skip to content

Commit

Permalink
Merge pull request #62 from Tea-Bliss/dev
Browse files Browse the repository at this point in the history
완성차 기능 추가
  • Loading branch information
lemonticsoul authored Jun 19, 2024
2 parents f88b4dc + 1592f89 commit 7217068
Show file tree
Hide file tree
Showing 6 changed files with 229 additions and 2 deletions.
64 changes: 64 additions & 0 deletions src/main/java/store/teabliss/tea/controller/TeaController.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,10 +7,13 @@
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.apache.coyote.Response;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.server.ResponseStatusException;
import store.teabliss.tea.dto.TeaDto;
import store.teabliss.tea.dto.TeaFinalDto;
import store.teabliss.tea.dto.TeaPatchDto;
import store.teabliss.tea.dto.TeaSearchDto;
import store.teabliss.tea.entity.Tea;
import store.teabliss.tea.mapper.TeaMapper;
Expand Down Expand Up @@ -141,6 +144,67 @@ public ResponseEntity<?> category(@RequestParam("page") int page,@RequestParam("
return ResponseEntity.ok(response);
}

@GetMapping("season")
@Operation(summary = "시즌별 조회", description = "차 하나만 조회하는 로직")
public ResponseEntity<?> season(@RequestParam("page") int page,@RequestParam("limit") int limit,@RequestParam("season") String season){

List<TeaFinalDto> seasonsort=teaService.sortseason(page,limit,season);

int teacount=seasonsort.size();


Map<String,Object> response=new HashMap<>();
response.put("size",teacount);
response.put("tea",seasonsort);
return ResponseEntity.ok(response);

}

@GetMapping("caffeine")
@Operation(summary = "카페인 조회", description = "차 하나만 조회하는 로직")
public ResponseEntity<?> caffeine(@RequestParam("page") int page,@RequestParam("limit") int limit,@RequestParam("caffeine") boolean caffeine){

List<TeaFinalDto> caffeinesort=teaService.caffeinesort(page,limit,caffeine);

int teacount=caffeinesort.size();
Map<String,Object> response=new HashMap<>();
response.put("size",teacount);
response.put("tea",caffeinesort);
return ResponseEntity.ok(response);

}

@DeleteMapping("delete/{id}")
@Operation(summary = "완성차 삭제 ", description = "차 하나만 조회하는 로직")
public ResponseEntity<?> teaDelete(@PathVariable int id){

boolean delete=teaService.deletetea(id);
if (delete) {
return ResponseEntity.ok("삭제되었습니다.");
} else {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "삭제 실패!");
}
}

@PatchMapping("patch/{id}")
@Operation(summary = "완성차 수정 ", description = "차 하나만 조회하는 로직")
public ResponseEntity<?> teaPatch(TeaPatchDto teaPatchDto){



boolean patch=teaService.patchtea(teaPatchDto);

if (patch) {
return ResponseEntity.ok("수정되었습니다.");
} else {
throw new ResponseStatusException(HttpStatus.BAD_REQUEST, "수정 실패!");
}

}







Expand Down
3 changes: 3 additions & 0 deletions src/main/java/store/teabliss/tea/dto/TeaFinalDto.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ public class TeaFinalDto {

private boolean isLastPage = false;

private boolean caffeine ;

private String season;

private String name;
Expand All @@ -57,6 +59,7 @@ public static List<TeaFinalDto> of(List<Tea> list){
.sale(tea.getSale())
.rating(tea.getRating())
.rate(tea.getRate())
.caffeine(tea.isCaffeine())
.season(tea.getSeason())
.name(tea.getName())
.nameEng(tea.getNameEng())
Expand Down
22 changes: 22 additions & 0 deletions src/main/java/store/teabliss/tea/dto/TeaPatchDto.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package store.teabliss.tea.dto;

import lombok.Getter;
import lombok.Setter;

@Getter
@Setter
public class TeaPatchDto {

private Long id ;

private Long price;
private String category ;

private String name ;
private String nameEng;
private boolean caffeine;
private String description;
private String img;
private Long inventory ;

}
10 changes: 9 additions & 1 deletion src/main/java/store/teabliss/tea/mapper/TeaMapper.java
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public interface TeaMapper {

Long countByCategory(String category);

Tea search(Long id);
Tea search(String product);

void saveIngredient(TeaIngredient ingredient);
void saveFlavor(TeaFlavor flavor);
Expand All @@ -44,6 +44,14 @@ public interface TeaMapper {
ArrayList<Long> findbyflavor(int id);


List<Tea> seasonsort(String season);

List<Tea> caffeinesort(boolean caffeine);

boolean deletetea(int id);
boolean patchtea(Tea tea);



// List<Tea> category();

Expand Down
89 changes: 89 additions & 0 deletions src/main/java/store/teabliss/tea/service/TeaService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
import com.fasterxml.jackson.core.JsonProcessingException;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
import store.teabliss.ingredient.entity.Ingredient;
import store.teabliss.tea.dto.TeaDto;
import store.teabliss.tea.dto.TeaFinalDto;
import store.teabliss.tea.dto.TeaPatchDto;
import store.teabliss.tea.dto.TeaSearchDto;
import store.teabliss.tea.entity.TeaFlavor;
import store.teabliss.tea.entity.TeaIngredient;
Expand Down Expand Up @@ -290,5 +292,92 @@ public Long categorycount(String category){
return count;
}

public List<TeaFinalDto> sortseason(int page,int limit,String season){


List<Tea> categorylist=teaMapper.seasonsort(season);
double all=categorylist.size();

int limitpage= (int) Math.ceil(all/limit);

List<Tea> new_recommend=new ArrayList<>();

for (int i =limit*(page-1);i<(page*limit);i++){
if (i==all) {
break;
}
if (page==limitpage){
categorylist.get(i).setIsLastPage(true);
new_recommend.add(categorylist.get(i));

} else {
categorylist.get(i).setIsLastPage(false);
new_recommend.add(categorylist.get(i));

}

}

return TeaFinalDto.of(new_recommend);

}

public List<TeaFinalDto> caffeinesort(int page,int limit,boolean caffeine){

List<Tea> categorylist=teaMapper.caffeinesort(caffeine);

double all=categorylist.size();

int limitpage= (int) Math.ceil(all/limit);

List<Tea> new_recommend=new ArrayList<>();

for (int i =limit*(page-1);i<(page*limit);i++){
if (i==all) {
break;
}
if (page==limitpage){
categorylist.get(i).setIsLastPage(true);
new_recommend.add(categorylist.get(i));

} else {
categorylist.get(i).setIsLastPage(false);
new_recommend.add(categorylist.get(i));

}

}

return TeaFinalDto.of(new_recommend);
}

public boolean deletetea(int id){

boolean result=teaMapper.deletetea(id);

return result;
}

public boolean patchtea(TeaPatchDto teaPatchDto){

Tea updatetea = Tea.builder()
.id(teaPatchDto.getId())
.price(teaPatchDto.getPrice())
.category(teaPatchDto.getCategory())
.name(teaPatchDto.getName())
.nameEng(teaPatchDto.getNameEng())
.caffeine(teaPatchDto.isCaffeine())
.description(teaPatchDto.getDescription())
.img(teaPatchDto.getImg())
.inventory(teaPatchDto.getInventory())
.build();


boolean result=teaMapper.patchtea(updatetea);

return result;
}



}
43 changes: 42 additions & 1 deletion src/main/resources/mapper/TeaMapper.xml
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@
<select id="search">
SELECT img, name, name_eng, price
FROM TEA
WHERE id = #{id}
WHERE name=#{product}
</select>

<select id="findbyid">
Expand All @@ -97,6 +97,47 @@

</select>

<select id="seasonsort">
SELECT *
FROM TEA
WHERE season=#{season}
</select>

<select id="caffeinesort">
SELECT *
FROM TEA
WHERE caffeine=#{caffeine}
</select>

<delete id="deletetea">
DELETE FROM TEA
WHERE 1=1
AND id= #{id}
</delete>

<update id="patchtea">
UPDATE TEA
SET quality= IFNULL(#{quantity}, quantity),
type = IFNULL(#{type}, type)
WHERE id=#{id}
</update>

<update id="updateIngredient" parameterType="Ingredient">
UPDATE TEA
SET
price = IFNULL(#{price}, price),
category = IFNULL(#{category}, category),
name = IFNULL(#{name}, name),
name_eng = IFNULL(#{nameEng}, name_eng),
caffeine = IFNULL(#{caffeine}, caffeine),
description = IFNULL(#{description}, description),
img = IFNULL(#{img}, img),
inventory = IFNULL(#{inventory}, inventory)

WHERE 1=1
AND id= #{id}
</update>




Expand Down

0 comments on commit 7217068

Please sign in to comment.