Skip to content

Commit

Permalink
Merge pull request #4 from mijin0721/devepole
Browse files Browse the repository at this point in the history
메뉴 품절 여부 컬럼 추가 및 공지사항 삭제 service 수정
  • Loading branch information
mijin0721 authored May 3, 2023
2 parents 58a37cc + 6fddde8 commit 21e7cb5
Show file tree
Hide file tree
Showing 9 changed files with 61 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,4 +39,10 @@ public Map<String, String> deleteMenu(@PathVariable(name = "mno") Long mno) {
String result = menuService.delete(mno);
return Map.of("result", result);
}

@PutMapping("sell/{mno}")
public Map<String, String> modifySell(@PathVariable(name = "mno") Long mno) {
String result = menuService.modifySoldOut(mno);
return Map.of("result", result);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.hallym.festival.domain.menu.dto;

import com.hallym.festival.domain.booth.entity.Booth;
import com.hallym.festival.domain.menu.entity.MenuSell;
import lombok.*;


Expand All @@ -14,4 +15,5 @@ public class MenuRequestDto {
private Long price;
private Boolean is_deleted;
private Booth booth;
private MenuSell menuSell;
}
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package com.hallym.festival.domain.menu.dto;

import com.hallym.festival.domain.menu.entity.MenuSell;
import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
Expand All @@ -13,4 +14,5 @@ public class MeunResponseDto {
private Long mno;
private String name;
private Long price;
private MenuSell menuSell;
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,17 @@ public class Menu extends BaseTimeEntity {
@JoinColumn(name = "bno")
private Booth booth;

@Enumerated(EnumType.STRING)
private MenuSell menuSell;

public void setIs_deleted(Boolean is_deleted) {
this.is_deleted = is_deleted;
}

public void setMenuSell(MenuSell menuSell) {
this.menuSell = menuSell;
}

public void updateMenu(Menu menu) {
this.name = menu.name;
this.price = menu.price;
Expand Down
12 changes: 12 additions & 0 deletions src/main/java/com/hallym/festival/domain/menu/entity/MenuSell.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
package com.hallym.festival.domain.menu.entity;

import com.fasterxml.jackson.annotation.JsonCreator;

public enum MenuSell {
SOID, SELL;

@JsonCreator
public static MenuSell from(String s) {
return MenuSell.valueOf(s);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,6 @@ public interface MenuService {
MeunResponseDto modify(Long mno, MenuRequestDto MenuRequestDto);

String delete(Long mno);

String modifySoldOut(Long mno);
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
import com.hallym.festival.domain.menu.dto.MenuRequestDto;
import com.hallym.festival.domain.menu.dto.MeunResponseDto;
import com.hallym.festival.domain.menu.entity.Menu;
import com.hallym.festival.domain.menu.entity.MenuSell;
import com.hallym.festival.domain.menu.repository.MenuRepository;
import com.hallym.festival.global.exception.WrongBoothId;
import lombok.RequiredArgsConstructor;
Expand All @@ -26,8 +27,9 @@ public class MenuServicelmpl implements MenuService {
@Transactional
public MeunResponseDto create(Long bno, MenuRequestDto menuRequestDto) {
Optional<Booth> booth = boothRepository.findById(bno);
menuRequestDto.setBooth(booth.get());
Menu newMenu = modelMapper.map(menuRequestDto, Menu.class);
newMenu.setBooth(booth.get());
newMenu.setMenuSell(MenuSell.SELL);
menuRepository.save(newMenu);
return modelMapper.map(newMenu, MeunResponseDto.class);
}
Expand Down Expand Up @@ -55,6 +57,24 @@ public String delete(Long mno) {
return "delete success";
}

@Override
public String modifySoldOut(Long mno) {
Optional<Menu> byMno = menuRepository.findById(mno);

Menu menu = byMno.orElseThrow();

if(menu.getMenuSell() == MenuSell.SELL) {
menu.setMenuSell(MenuSell.SOID);
menuRepository.save(menu);
return "Menu is sold out";
} else {
menu.setMenuSell(MenuSell.SELL);
menuRepository.save(menu);
return "Menu is sell";
}
}


public List<MeunResponseDto> getMenuList(List<Menu> all) {
return all.stream().map(menu -> this.toDto(menu)).collect(Collectors.toList());
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import javax.transaction.Transactional;
import java.util.List;
import java.util.Optional;
import java.util.stream.Collectors;

@RequiredArgsConstructor
Expand Down Expand Up @@ -55,7 +56,8 @@ public NoticeDto getNotice(Long nno) { //공지사항 상세 조회
}

public String delete(Long nno) { //공지사항 삭제
Notice notice = findByNotice(nno);
Optional<Notice> byNno = noticeRepository.findById(nno);
Notice notice = byNno.get();
notice.setIs_deleted(Boolean.TRUE);
return "delete success";
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,4 +89,10 @@ public void testInsertBoothAndMenu() {
menuService.create(bno, menuRequestDto);

}

@Test
public void testSoldOut() {
Long mno = 1L;
menuService.modifySoldOut(mno);
}
}

0 comments on commit 21e7cb5

Please sign in to comment.