Skip to content

Commit

Permalink
Merge pull request #2 from mijin0721/devepole
Browse files Browse the repository at this point in the history
Devepole
  • Loading branch information
mijin0721 authored Apr 10, 2023
2 parents 27fab68 + 132ad58 commit f6ad23d
Show file tree
Hide file tree
Showing 13 changed files with 104 additions and 69 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -16,27 +16,27 @@ public class MenuController {
private final MenuService menuService;

@PostMapping("/{bno}")
public Map<String, String> createMenu(@PathVariable(name = "bno") Long boothId,
public Map<String, String> createMenu(@PathVariable(name = "bno") Long bno,
@RequestBody MenuRequestDto menuRequestDto) {
menuService.create(boothId, menuRequestDto);
menuService.create(bno, menuRequestDto);
return Map.of("result","create success");
}

@GetMapping("/{bno}")
public List<MeunResponseDto> getMenuList(@PathVariable(name = "bno") Long boothId) throws Exception {
return menuService.getAll(boothId);
public List<MeunResponseDto> getMenuList(@PathVariable(name = "bno") Long bno) throws Exception {
return menuService.getAll(bno);
}

@PutMapping("/{id}")
@PutMapping("/{mno}")
public Map<String, String> updateMenu(@RequestBody MenuRequestDto menuRequestDto,
@PathVariable (name = "id") Long id) {
menuService.modify(id, menuRequestDto);
@PathVariable (name = "mno") Long mno) {
menuService.modify(mno, menuRequestDto);
return Map.of("result","update success");
}

@DeleteMapping("/{id}")
public Map<String, String> deleteMenu(@PathVariable(name = "id") Long id) {
String result = menuService.delete(id);
@DeleteMapping("/{mno}")
public Map<String, String> deleteMenu(@PathVariable(name = "mno") Long mno) {
String result = menuService.delete(mno);
return Map.of("result", result);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
@AllArgsConstructor
@NoArgsConstructor
public class MenuRequestDto {
private Long id;
private Long mno;
private String name;
private Long price;
private Boolean is_deleted;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
@AllArgsConstructor
@NoArgsConstructor
public class MeunResponseDto {
private Long id;
private Long mno;
private String name;
private Long price;
}
12 changes: 10 additions & 2 deletions src/main/java/com/hallym/festival/domain/menu/entity/Menu.java
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public class Menu extends BaseTimeEntity {

@GeneratedValue(strategy = GenerationType.IDENTITY)
@Id
private Long id;
private Long mno;

private String name;

Expand All @@ -32,7 +32,7 @@ public class Menu extends BaseTimeEntity {

@JsonBackReference
@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "booth_id")
@JoinColumn(name = "bno")
private Booth booth;

public void setIs_deleted(Boolean is_deleted) {
Expand All @@ -43,4 +43,12 @@ public void updateMenu(Menu menu) {
this.name = menu.name;
this.price = menu.price;
}

public void setBooth(Booth booth) {
if(this.booth != null) {
this.booth.getMenus().remove(this);
}
this.booth = booth;
booth.getMenus().add(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,11 +7,11 @@
import java.util.List;

public interface MenuService {
MeunResponseDto create (Long id, MenuRequestDto MenuRequestDto);
MeunResponseDto create (Long bno, MenuRequestDto MenuRequestDto);

List<MeunResponseDto> getAll(Long boothId) throws Exception;
List<MeunResponseDto> getAll(Long bno) throws Exception;

MeunResponseDto modify(Long id, MenuRequestDto MenuRequestDto);
MeunResponseDto modify(Long mno, MenuRequestDto MenuRequestDto);

String delete(Long id);
String delete(Long mno);
}
Original file line number Diff line number Diff line change
Expand Up @@ -24,32 +24,32 @@ public class MenuServicelmpl implements MenuService {
private final ModelMapper modelMapper;

@Transactional
public MeunResponseDto create(Long boothId, MenuRequestDto menuRequestDto) {
Optional<Booth> booth = boothRepository.findById(boothId);
public MeunResponseDto create(Long bno, MenuRequestDto menuRequestDto) {
Optional<Booth> booth = boothRepository.findById(bno);
menuRequestDto.setBooth(booth.get());
Menu newMenu = modelMapper.map(menuRequestDto, Menu.class);
menuRepository.save(newMenu);
return modelMapper.map(newMenu, MeunResponseDto.class);
}

public List<MeunResponseDto> getAll(Long boothId) throws Exception {
Optional<Booth> booth = boothRepository.findById(boothId);
List<Menu> menuList = menuRepository.findByBooth_Bno(booth.get().getBno(), Boolean.FALSE);
public List<MeunResponseDto> getAll(Long bno) throws Exception {
Optional<Booth> booth = boothRepository.findById(bno);
List<Menu> menuList = menuRepository.findByBooth_Bno(bno, Boolean.FALSE);
return getMenuList(menuList);
}

@Transactional
public MeunResponseDto modify(Long id, MenuRequestDto menuRequestDto) {
Menu menu = menuRepository.findById(id).orElseThrow(() ->
public MeunResponseDto modify(Long mno, MenuRequestDto menuRequestDto) {
Menu menu = menuRepository.findById(mno).orElseThrow(() ->
new WrongBoothId());
menu.updateMenu(modelMapper.map(menuRequestDto, Menu.class));
menuRepository.save(menu);
return modelMapper.map(menu, MeunResponseDto.class);
}

@Transactional
public String delete(Long id) {
Menu menu = menuRepository.findById(id).orElseThrow(() ->
public String delete(Long mno) {
Menu menu = menuRepository.findById(mno).orElseThrow(() ->
new WrongBoothId());
menu.setIs_deleted(Boolean.TRUE);
return "delete success";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,20 @@ public PageResponseDTO<NoticeDto> getNoticeListPage(PageRequestDTO pageRequestDT
return responseDTO;
}

@GetMapping("/{id}")
public NoticeDto getNotice(@PathVariable("id") Long id) {
return noticeService.getNotice(id);
@GetMapping("/{nno}")
public NoticeDto getNotice(@PathVariable("nno") Long nno) {
return noticeService.getNotice(nno);
}

@DeleteMapping("/{id}")
public Map<String, String> deleteNotice(@PathVariable("id") Long id) {
String result = noticeService.delete(id);
@DeleteMapping("/{nno}")
public Map<String, String> deleteNotice(@PathVariable("nno") Long nno) {
String result = noticeService.delete(nno);
return Map.of("result", result);
}

@PutMapping("/{id}")
public Map<String, String> updateNotice(@RequestBody NoticeDto noticeDto, @PathVariable("id") Long id) {
noticeService.modify(id, noticeDto);
@PutMapping("/{nno}")
public Map<String, String> updateNotice(@RequestBody NoticeDto noticeDto, @PathVariable("nno") Long nno) {
noticeService.modify(nno, noticeDto);
return Map.of("result", "update success");
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
@AllArgsConstructor
@NoArgsConstructor
public class NoticeDto {
private Long id;
private Long nno;

private String title;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
public class Notice extends BaseTimeEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long id;
private Long nno;
@NotNull
private String title;
@NotNull
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@ public interface NoticeService {

PageResponseDTO<NoticeDto> getNoticeListPage(PageRequestDTO pageRequestDTO);

NoticeDto getNotice(Long id);
NoticeDto getNotice(Long nno);

String delete(Long id);
String delete(Long nno);

NoticeDto modify(Long id, NoticeDto noticeDto);
NoticeDto modify(Long nno, NoticeDto noticeDto);

PageResponseDTO<NoticeDto> searchPage(String keyword, PageRequestDTO pageRequestDTO);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,19 +49,19 @@ public PageResponseDTO<NoticeDto> getNoticeListPage(PageRequestDTO pageRequestDT
.build();
}

public NoticeDto getNotice(Long id) { //공지사항 상세 조회
Notice notice = findByNotice(id);
public NoticeDto getNotice(Long nno) { //공지사항 상세 조회
Notice notice = findByNotice(nno);
return modelMapper.map(notice, NoticeDto.class);
}

public String delete(Long id) { //공지사항 삭제
Notice notice = findByNotice(id);
public String delete(Long nno) { //공지사항 삭제
Notice notice = findByNotice(nno);
notice.setIs_deleted(Boolean.TRUE);
return "delete success";
}

public NoticeDto modify(Long id, NoticeDto noticeDto) { //공지사항 수정
Notice notice = findByNotice(id);
public NoticeDto modify(Long nno, NoticeDto noticeDto) { //공지사항 수정
Notice notice = findByNotice(nno);
Notice newnotice = modelMapper.map(noticeDto, Notice.class);
notice.updateNotice(newnotice);
noticeRepository.save(notice);
Expand All @@ -87,8 +87,8 @@ public PageResponseDTO<NoticeDto> searchPage(String keyword, PageRequestDTO page
.build();
}

public Notice findByNotice(Long id) {
return noticeRepository.findById(id).orElseThrow(() -> new WrongBoothId());
public Notice findByNotice(Long nno) {
return noticeRepository.findById(nno).orElseThrow(() -> new WrongBoothId());
}

public NoticeDto toDto(Notice notice) {
Expand Down
47 changes: 37 additions & 10 deletions src/test/java/com/hallym/festival/service/MenuServiceTests.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,12 @@
package com.hallym.festival.service;

import com.hallym.festival.domain.booth.dto.BoothDTO;
import com.hallym.festival.domain.booth.entity.BoothType;
import com.hallym.festival.domain.booth.service.BoothService;
import com.hallym.festival.domain.booth.service.BoothServiceImpl;
import com.hallym.festival.domain.menu.dto.MenuRequestDto;
import com.hallym.festival.domain.menu.dto.MeunResponseDto;
import com.hallym.festival.domain.menu.service.MenuService;
import com.hallym.festival.domain.menu.service.MenuServicelmpl;
import lombok.extern.log4j.Log4j2;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -17,49 +22,71 @@
@DisplayName("메뉴 서비스 테스트")
public class MenuServiceTests {
@Autowired
MenuServicelmpl menuService;
MenuService menuService;
@Autowired
BoothService boothService;

@Test
@DisplayName("메뉴 생성")
public void testCreate() {
Long BoothID = 1L;
IntStream.rangeClosed(1,5).forEach(i -> {
Long bno = 1L;
IntStream.rangeClosed(1,2).forEach(i -> {
MenuRequestDto menuRequestDto =
MenuRequestDto.builder()
.name("떡복이" + i)
.price(7000L * i).build();
menuService.create(BoothID, menuRequestDto);
menuService.create(bno, menuRequestDto);
});
System.out.println("----------작성완료!----------");
}

@Test
@DisplayName("부스별로 메뉴 목록 조회")
public void testGetList() throws Exception {
Long BoothId = 1L;
List<MeunResponseDto> menuList = menuService.getAll(BoothId);
Long bno = 1L;
List<MeunResponseDto> menuList = menuService.getAll(bno);
System.out.println(menuList.size());
System.out.println("----------출력완료!----------");
}

@Test
@DisplayName("메뉴 수정")
public void testUpdate() {
Long id = 3L;
Long mno = 1L;
MenuRequestDto menuRequestDto =
MenuRequestDto.builder()
.name("부대찌개")
.price(15000L)
.build();
menuService.modify(id, menuRequestDto);
menuService.modify(mno, menuRequestDto);
System.out.println("----------수정완료!----------");
}

@Test
@DisplayName("메뉴 삭제")
public void testDelete() {
Long id = 1L;
menuService.delete(id);
Long mno = 1L;
menuService.delete(mno);
System.out.println("----------삭제완료!----------");
}

@Test
public void testInsertBoothAndMenu() {
BoothDTO boothDTO = BoothDTO.builder()
.booth_title("타코야끼")
.booth_content("새벽 4시 45분")
.writer("주펄")
.booth_type(BoothType.푸드트럭)
.build();

Long bno = boothService.register(boothDTO);

MenuRequestDto menuRequestDto =
MenuRequestDto.builder()
.name("떡복이")
.price(7000L).build();

menuService.create(bno, menuRequestDto);

}
}
Loading

0 comments on commit f6ad23d

Please sign in to comment.