Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat : Shop 등록 & 조회 #95

Merged
merged 50 commits into from
Jan 13, 2024
Merged
Show file tree
Hide file tree
Changes from 32 commits
Commits
Show all changes
50 commits
Select commit Hold shift + click to select a range
ea664b7
feat : Shop dto 객체 & mapper
kkangh00n Jan 9, 2024
d93b70c
fix : Category 객체 검증 메서드 추가
kkangh00n Jan 9, 2024
ad58aad
feat : Shop 등록 기능 & api
kkangh00n Jan 9, 2024
2aa01a8
fix : Service를 Member와 Owner 각각 분리
kkangh00n Jan 9, 2024
6ee473f
feat : dto 추가
kkangh00n Jan 9, 2024
770d912
feat : Shop 전체 조회 & api
kkangh00n Jan 9, 2024
319a8b9
feat : Shop 단건 조회 기능 & api
kkangh00n Jan 9, 2024
73f7e53
fix : 컨트롤러 반환 타입 수정
kkangh00n Jan 9, 2024
175d5c0
chore : Query Dsl 의존성 & 설정 추가
kkangh00n Jan 9, 2024
5d1d275
refactor : dto 패키지 분리
kkangh00n Jan 9, 2024
ea00b50
chore : gitignore 수정 (Q클래스)
kkangh00n Jan 9, 2024
1d9ff22
feat : Shop 검색 dto
kkangh00n Jan 9, 2024
7613634
feat : Shop 검색 조회 기능 & api
kkangh00n Jan 9, 2024
3d8aed9
Merge branch 'dev' into feat/#86
kkangh00n Jan 10, 2024
6c974b1
fix : 메서드 네이밍 변경
kkangh00n Jan 10, 2024
4f29050
fix : 메서드 네이밍 변경
kkangh00n Jan 10, 2024
34571fe
fix : dto의 rating 타입 변경
kkangh00n Jan 10, 2024
6c09dfc
fix : dto의 rating 타입 변경
kkangh00n Jan 10, 2024
18470b9
feat : 테스트를 위한 더미데이터 추가
kkangh00n Jan 10, 2024
e96a130
feat : Shop ReservationTime 양방향 매핑
kkangh00n Jan 10, 2024
a45eb51
fix : Shop 단일 조회 시, ReservationTime fetchJoin
kkangh00n Jan 10, 2024
a0e7de2
feat : ShopService Test
kkangh00n Jan 10, 2024
fe8a19b
fix : Shop 조건 조회 시, null 체크 추가
kkangh00n Jan 10, 2024
cb84048
feat : ShopRepository Test
kkangh00n Jan 10, 2024
e32f2d7
feat : OwnerShopController Test (Shop 등록 테스트)
kkangh00n Jan 10, 2024
59e286b
fix : URL 수정
kkangh00n Jan 10, 2024
7c6f510
fix : Repository 메서드 쿼리 변경
kkangh00n Jan 10, 2024
0accad0
feat : MemberShopController Test
kkangh00n Jan 10, 2024
d6a1382
fix : ShopRepositoryTest 수정
kkangh00n Jan 10, 2024
0f8d07a
style : 코드 컨벤션 적용
kkangh00n Jan 10, 2024
acb72b8
fix : 각 테스트마다 Repository deleteAll
kkangh00n Jan 10, 2024
494bc3b
fix : deleteAll 추가
kkangh00n Jan 10, 2024
da5af41
fix : 예외 타입 변경
kkangh00n Jan 12, 2024
ab0f08d
refactor : ErrorCode static 화
kkangh00n Jan 12, 2024
cff88a6
fix : 테스트 검증 대상 수정
kkangh00n Jan 12, 2024
d32785b
style : 네이밍 컨벤션 적용
kkangh00n Jan 12, 2024
9ae1167
fix : 양방향 관계 제거
kkangh00n Jan 12, 2024
6d7f8a6
feat : 가게와 메뉴 양방향 관계, 가게와 예약 시간 단방향 관계 설정
kkangh00n Jan 12, 2024
a31053a
feat : 가게 등록 로직 수정
kkangh00n Jan 12, 2024
a953ba0
feat : 가게 update 쿼리
kkangh00n Jan 12, 2024
26a4c6b
feat : 가게 전체 조회 로직 수정
kkangh00n Jan 12, 2024
fde2c15
feat : 가게 단건 조회 로직 수정
kkangh00n Jan 12, 2024
f77bfdb
fix : 에러 메시지 변경
kkangh00n Jan 12, 2024
2edc483
fix : 필터 검색 시, 이름 동일성이 아닌 포함 여부 확인
kkangh00n Jan 12, 2024
73e322d
fix : conflict resolve
kkangh00n Jan 12, 2024
6779292
Merge branch 'dev' into feat/#86
kkangh00n Jan 12, 2024
eb44b18
fix : Shop & Menu 연관 관계 세팅 방식 수정
kkangh00n Jan 12, 2024
7155a3f
fix : 필드에 맞게 dto 수정
kkangh00n Jan 12, 2024
fa46040
fix : ShopServiceTest 변경사항 수정
kkangh00n Jan 12, 2024
9a2218e
fix : MemberShopControllerTest 변경사항 수정
kkangh00n Jan 12, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,5 @@ out/
### VS Code ###
.vscode/
application.yaml
.DS_Store
.DS_Store
src/main/generated/**
21 changes: 21 additions & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -62,9 +62,30 @@ dependencies {

implementation group: 'org.json', name: 'json', version: '20231013'

//Query Dsl
implementation 'com.querydsl:querydsl-jpa:5.0.0:jakarta'

annotationProcessor "com.querydsl:querydsl-apt:${dependencyManagement.importedProperties['querydsl.version']}:jakarta"
annotationProcessor "jakarta.annotation:jakarta.annotation-api"
annotationProcessor "jakarta.persistence:jakarta.persistence-api"
}

//Query Dsl
def querydslDir = "src/main/generated"

sourceSets {
main.java.srcDirs += [querydslDir]
}

tasks.withType(JavaCompile) {
options.getGeneratedSourceOutputDirectory().set(file(querydslDir))
}

clean.doLast {
file(querydslDir).deleteDir()
}
//Query Dsl

tasks.named('test') {
useJUnitPlatform()
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,13 +29,12 @@
@Slf4j
public class NotificationService {

@Value("${slack.token}")
private String slackToken;

private final NotificationMemberRepository notificationMemberRepository;
private final NotificationOwnerRepository notificationOwnerRepository;
private final MemberRepository memberRepository; // 추후 삭제 예정
private final OwnerRepository ownerRepository; // 추후 삭제 예정
@Value("${slack.token}")
private String slackToken;
private JSONObject jsonObject;

public void sendMessageAndSave(Member member, NotificationContent content) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ public ReservationTime(LocalDateTime time) {

public void insertShop(Shop shop) {
this.shop = shop;
shop.getReservationTimeList().add(this);
}

public void setOccupiedTrue() {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package com.prgrms.catchtable.shop.controller;

import com.prgrms.catchtable.shop.dto.request.ShopSearchCondition;
import com.prgrms.catchtable.shop.dto.response.GetAllShopResponse;
import com.prgrms.catchtable.shop.dto.response.GetShopResponse;
import com.prgrms.catchtable.shop.service.MemberShopService;
import lombok.RequiredArgsConstructor;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/shops")
public class MemberShopController {

private final MemberShopService memberShopService;

@GetMapping
public ResponseEntity<GetAllShopResponse> getAll() {
return ResponseEntity.ok(memberShopService.getAll());
}

@GetMapping("/{shopId}")
public ResponseEntity<GetShopResponse> getById(@PathVariable("shopId") Long id) {
return ResponseEntity.ok(memberShopService.getById(id));
}

@GetMapping("/search")
public ResponseEntity<GetAllShopResponse> getBySearch(
@ModelAttribute ShopSearchCondition condition) {
return ResponseEntity.ok(memberShopService.getBySearch(condition));
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.prgrms.catchtable.shop.controller;

import com.prgrms.catchtable.common.login.LogIn;
import com.prgrms.catchtable.owner.domain.Owner;
import com.prgrms.catchtable.shop.dto.request.RegistShopRequest;
import com.prgrms.catchtable.shop.dto.response.RegistShopResponse;
import com.prgrms.catchtable.shop.service.OwnerShopService;
import jakarta.validation.Valid;
import lombok.RequiredArgsConstructor;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequiredArgsConstructor
@RequestMapping("/owners")
public class OwnerShopController {

private final OwnerShopService shopService;

@PostMapping("/shops")
public ResponseEntity<RegistShopResponse> registShop(
kkangh00n marked this conversation as resolved.
Show resolved Hide resolved
@Valid @RequestBody RegistShopRequest request, @LogIn
Owner owner) {
RegistShopResponse registShopResponse = shopService.registShop(request, owner);
return ResponseEntity.status(HttpStatus.CREATED).body(registShopResponse);
}

kkangh00n marked this conversation as resolved.
Show resolved Hide resolved
}
15 changes: 14 additions & 1 deletion src/main/java/com/prgrms/catchtable/shop/domain/Category.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
package com.prgrms.catchtable.shop.domain;

import com.prgrms.catchtable.common.exception.ErrorCode;
import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException;
import java.util.Arrays;
import lombok.Getter;
import lombok.RequiredArgsConstructor;

Expand All @@ -11,6 +14,16 @@ public enum Category {
CHINESE_FOOD("중식"),
WESTERN_FOOD("양식");

private final String description;
private final String type;

public static Category of(String input) {
return Arrays.stream(values())
.filter(category -> category.isEqual(input))
.findAny()
.orElseThrow(() -> new BadRequestCustomException(ErrorCode.INVALID_INPUT_TYPE));
kkangh00n marked this conversation as resolved.
Show resolved Hide resolved
}

private boolean isEqual(String input) {
return type.equals(input);
}
}
8 changes: 8 additions & 0 deletions src/main/java/com/prgrms/catchtable/shop/domain/Shop.java
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,22 @@

import com.prgrms.catchtable.common.BaseEntity;
import com.prgrms.catchtable.common.exception.custom.BadRequestCustomException;
import com.prgrms.catchtable.reservation.domain.ReservationTime;
import jakarta.persistence.Column;
import jakarta.persistence.Embedded;
import jakarta.persistence.Entity;
import jakarta.persistence.Enumerated;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.Id;
import jakarta.persistence.OneToMany;
import java.math.BigDecimal;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
import org.hibernate.annotations.BatchSize;

@Getter
@NoArgsConstructor(access = PROTECTED)
Expand Down Expand Up @@ -51,6 +56,9 @@ public class Shop extends BaseEntity {
@Column(name = "closing_time")
private LocalTime closingTime;

@BatchSize(size = 30)
@OneToMany(mappedBy = "shop")
private List<ReservationTime> reservationTimeList = new ArrayList<>();

kkangh00n marked this conversation as resolved.
Show resolved Hide resolved
@Builder
public Shop(String name, BigDecimal rating, Category category, Address address, int capacity,
Expand Down
63 changes: 63 additions & 0 deletions src/main/java/com/prgrms/catchtable/shop/dto/ShopMapper.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
package com.prgrms.catchtable.shop.dto;

import com.prgrms.catchtable.shop.domain.Address;
import com.prgrms.catchtable.shop.domain.Category;
import com.prgrms.catchtable.shop.domain.Shop;
import com.prgrms.catchtable.shop.dto.request.RegistShopRequest;
import com.prgrms.catchtable.shop.dto.response.GetAllShopResponse;
import com.prgrms.catchtable.shop.dto.response.GetShopResponse;
import com.prgrms.catchtable.shop.dto.response.RegistShopResponse;
import java.util.List;

public class ShopMapper {

public static Shop toEntity(RegistShopRequest registShopRequest) {

return Shop.builder()
.name(registShopRequest.name())
.rating(registShopRequest.rating())
.category(Category.of(registShopRequest.category()))
.address(Address.builder()
.city(registShopRequest.city())
.district(registShopRequest.district())
.build())
.capacity(registShopRequest.capacity())
.openingTime(registShopRequest.openingTime())
.closingTime(registShopRequest.closingTime())
.build();
}

public static RegistShopResponse toRegistShopResponse(Shop shop) {
return RegistShopResponse.builder()
.name(shop.getName())
.rating(shop.getRating())
.category(shop.getCategory().getType())
.city(shop.getAddress().getCity())
.district(shop.getAddress().getDistrict())
.capacity(shop.getCapacity())
.openingTime(shop.getOpeningTime())
.closingTime(shop.getClosingTime())
.build();
}

public static GetAllShopResponse toGetAllShopResponse(List<Shop> shops) {
return new GetAllShopResponse(shops.stream()
.map(ShopMapper::toGetShopResponse)
.toList());
}

public static GetShopResponse toGetShopResponse(Shop shop) {
return GetShopResponse.builder()
.id(shop.getId())
.name(shop.getName())
.rating(shop.getRating())
.category(shop.getCategory().getType())
.city(shop.getAddress().getCity())
.district(shop.getAddress().getDistrict())
.capacity(shop.getCapacity())
.openingTime(shop.getOpeningTime())
.closingTime(shop.getClosingTime())
.build();
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
package com.prgrms.catchtable.shop.dto.request;

import com.fasterxml.jackson.annotation.JsonFormat;
import jakarta.validation.constraints.Max;
import jakarta.validation.constraints.Min;
import java.math.BigDecimal;
import java.time.LocalTime;
import lombok.Builder;

@Builder
public record RegistShopRequest(

String name,
@Min(0)
@Max(5)
BigDecimal rating,
String category,
String city,
String district,
int capacity,
@JsonFormat(pattern = "kk:mm:ss")
LocalTime openingTime,
@JsonFormat(pattern = "kk:mm:ss")
LocalTime closingTime

) {
kkangh00n marked this conversation as resolved.
Show resolved Hide resolved

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.prgrms.catchtable.shop.dto.request;

public record ShopSearchCondition(
String name,
String category,
String city
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.prgrms.catchtable.shop.dto.response;

import java.util.List;

public record GetAllShopResponse(
List<GetShopResponse> shopResponses
) {

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
package com.prgrms.catchtable.shop.dto.response;

import java.math.BigDecimal;
import java.time.LocalTime;
import lombok.Builder;

@Builder
public record GetShopResponse(

Long id,
String name,
BigDecimal rating,
String category,
String city,
String district,
int capacity,
LocalTime openingTime,
LocalTime closingTime

) {
kkangh00n marked this conversation as resolved.
Show resolved Hide resolved

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.prgrms.catchtable.shop.dto.response;

import com.fasterxml.jackson.annotation.JsonFormat;
import java.math.BigDecimal;
import java.time.LocalTime;
import lombok.Builder;

@Builder
public record RegistShopResponse(

String name,
BigDecimal rating,
String category,
String city,
String district,
int capacity,
@JsonFormat(pattern = "kk:mm:ss")
LocalTime openingTime,
@JsonFormat(pattern = "kk:mm:ss")
LocalTime closingTime
) {

}
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package com.prgrms.catchtable.shop.repository;

import com.prgrms.catchtable.shop.domain.Shop;
import java.util.Optional;
import org.springframework.data.jpa.repository.EntityGraph;
import org.springframework.data.jpa.repository.JpaRepository;

public interface ShopRepository extends JpaRepository<Shop, Long> {
public interface ShopRepository extends JpaRepository<Shop, Long>, ShopRepositoryCustom {

@EntityGraph(attributePaths = "reservationTimeList")
Optional<Shop> findShopById(Long id);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
package com.prgrms.catchtable.shop.repository;

import com.prgrms.catchtable.shop.domain.Shop;
import com.prgrms.catchtable.shop.dto.request.ShopSearchCondition;
import java.util.List;

public interface ShopRepositoryCustom {

List<Shop> findSearch(ShopSearchCondition condition);

}
Loading