-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
144 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
2 changes: 1 addition & 1 deletion
2
src/main/java/ssu/eatssu/domain/admin/dto/RegisterMenuRequest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,4 @@ | ||
package ssu.eatssu.domain.admin.dto; | ||
|
||
public record RegisterMenuRequest(String menuName) { | ||
public record RegisterMenuRequest(String name, Integer price) { | ||
} |
30 changes: 30 additions & 0 deletions
30
src/main/java/ssu/eatssu/domain/admin/persistence/FindRestaurantRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
package ssu.eatssu.domain.admin.persistence; | ||
|
||
import com.querydsl.core.types.dsl.BooleanExpression; | ||
import com.querydsl.jpa.impl.JPAQueryFactory; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
import ssu.eatssu.domain.restaurant.entity.QRestaurant; | ||
import ssu.eatssu.domain.restaurant.entity.Restaurant; | ||
import ssu.eatssu.domain.restaurant.entity.RestaurantName; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
public class FindRestaurantRepository { | ||
private final JPAQueryFactory queryFactory; | ||
private final QRestaurant restaurant = QRestaurant.restaurant; | ||
|
||
public Restaurant findByRestaurantName(RestaurantName name) { | ||
return queryFactory | ||
.selectFrom(restaurant) | ||
.where( | ||
restaurantNameEq(name) | ||
) | ||
.fetchOne(); | ||
} | ||
|
||
private BooleanExpression restaurantNameEq(RestaurantName name) { | ||
return restaurant.restaurantName.eq(name); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
src/main/java/ssu/eatssu/domain/admin/persistence/ManageMenuRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
package ssu.eatssu.domain.admin.persistence; | ||
|
||
import jakarta.persistence.EntityManager; | ||
import jakarta.persistence.PersistenceContext; | ||
import org.springframework.data.jpa.repository.support.JpaEntityInformation; | ||
import org.springframework.data.jpa.repository.support.JpaEntityInformationSupport; | ||
import org.springframework.stereotype.Repository; | ||
import org.springframework.transaction.annotation.Transactional; | ||
import ssu.eatssu.domain.menu.entity.Menu; | ||
|
||
@Repository | ||
public class ManageMenuRepository { | ||
|
||
@PersistenceContext | ||
private final EntityManager em; | ||
|
||
private final JpaEntityInformation<Menu, ?> entityInformation; | ||
|
||
public ManageMenuRepository(EntityManager em) { | ||
this.em = em; | ||
this.entityInformation = | ||
JpaEntityInformationSupport.getEntityInformation(Menu.class, em); | ||
} | ||
|
||
@Transactional | ||
public Menu save(Menu menu) { | ||
if (entityInformation.isNew(menu)) { | ||
em.persist(menu); | ||
return menu; | ||
} else { | ||
return em.merge(menu); | ||
} | ||
} | ||
|
||
@Transactional | ||
public void delete(Menu menu) { | ||
|
||
if (entityInformation.isNew(menu)) { | ||
return; | ||
} | ||
|
||
Menu existing = em.find(Menu.class, menu.getId()); | ||
|
||
if (existing == null) { | ||
return; | ||
} | ||
|
||
em.remove(em.contains(menu) ? menu : em.merge(menu)); | ||
} | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters