-
Notifications
You must be signed in to change notification settings - Fork 0
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
29 changed files
with
409 additions
and
110 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
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
20 changes: 11 additions & 9 deletions
20
core/src/main/kotlin/com/core/adapter/in/web/MealController.kt
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,20 +1,22 @@ | ||
package com.core.adapter.`in`.web | ||
|
||
import com.core.adapter.`in`.web.dto.AdapterMealDto | ||
import com.core.application.port.`in`.GetMealUseCase | ||
import com.core.application.port.`in`.GetWeekMealUseCase | ||
import com.core.common.response.ApplicationResponse | ||
import org.springframework.web.bind.annotation.GetMapping | ||
import org.springframework.web.bind.annotation.RequestParam | ||
import org.springframework.web.bind.annotation.RestController | ||
|
||
@RestController | ||
class MealController(val getWeekMealUseCase: GetWeekMealUseCase) { | ||
|
||
@RestController("/api/v1/meals") | ||
class MealController(private val getMealUseCase: GetMealUseCase) { | ||
|
||
@GetMapping | ||
fun getMeal() : ApplicationResponse<List<AdapterMealDto.GetMealRes>> { | ||
val data = getMealUseCase.execute() | ||
val toResponse = AdapterMealDto.GetMealRes.toResponse(data) | ||
@GetMapping("/api/v1/meals/week") | ||
fun getWeekMeal( | ||
@RequestParam("restaurantName") restaurantName: String | ||
) : ApplicationResponse<List<AdapterMealDto.GetWeekMealRes>> { | ||
val data = getWeekMealUseCase(restaurantName) | ||
val toResponse = AdapterMealDto.GetWeekMealRes.from(data) | ||
return ApplicationResponse.ok(toResponse) | ||
} | ||
|
||
} | ||
} |
23 changes: 14 additions & 9 deletions
23
core/src/main/kotlin/com/core/adapter/in/web/dto/AdapterMealDto.kt
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
20 changes: 20 additions & 0 deletions
20
core/src/main/kotlin/com/core/adapter/out/persistence/MealPersistenceAdapter.kt
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,20 @@ | ||
package com.core.adapter.out.persistence | ||
|
||
import com.core.adapter.out.persistence.mapper.MealMapper | ||
import com.core.adapter.out.persistence.repository.MealRepository | ||
import com.core.application.domain.meal.model.Meal | ||
import com.core.application.port.out.GetWeekMealPort | ||
import org.springframework.stereotype.Component | ||
import java.time.LocalDate | ||
|
||
@Component | ||
class MealPersistenceAdapter( | ||
private val mealRepository: MealRepository, | ||
private val mealMapper: MealMapper | ||
) : GetWeekMealPort { | ||
override fun invoke(restaurantName: String, start: LocalDate, end: LocalDate): List<Meal> { | ||
val weekMeal = mealRepository.getWeekMeal(restaurantName, start, end) | ||
val applicationMeals = mealMapper.toDomain(weekMeal); | ||
return applicationMeals | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
core/src/main/kotlin/com/core/adapter/out/persistence/entity/CampusJpaEntity.kt
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,23 @@ | ||
package com.core.adapter.out.persistence.entity | ||
|
||
import com.core.common.BaseEntity | ||
import jakarta.persistence.* | ||
|
||
@Entity | ||
@Table(name = "campus", indexes = [ | ||
Index(name = "campus_idx_name", columnList = "name"), | ||
]) | ||
class CampusJpaEntity : BaseEntity() { | ||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
val idx: Long = 0 | ||
|
||
@Column(name = "name") | ||
val name: String = "DEFAULT" | ||
|
||
@Column(name = "address") | ||
val address: String = "DEFAULT" | ||
|
||
@Column(name = "is_deleted") | ||
val isDeleted: Boolean = false | ||
} |
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
4 changes: 4 additions & 0 deletions
4
core/src/main/kotlin/com/core/adapter/out/persistence/entity/ScrapJpaEntity.kt
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,4 @@ | ||
package com.core.adapter.out.persistence.entity | ||
|
||
class ScrapJpaEntity { | ||
} |
4 changes: 4 additions & 0 deletions
4
core/src/main/kotlin/com/core/adapter/out/persistence/entity/StoreJpaEntity.kt
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,4 @@ | ||
package com.core.adapter.out.persistence.entity | ||
|
||
class StoreJpaEntity { | ||
} |
22 changes: 0 additions & 22 deletions
22
core/src/main/kotlin/com/core/adapter/out/persistence/entity/UniversityJpaEntity.kt
This file was deleted.
Oops, something went wrong.
4 changes: 4 additions & 0 deletions
4
core/src/main/kotlin/com/core/adapter/out/persistence/entity/UserJpaEntity.kt
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,4 @@ | ||
package com.core.adapter.out.persistence.entity | ||
|
||
class UserJpaEntity { | ||
} |
40 changes: 40 additions & 0 deletions
40
core/src/main/kotlin/com/core/adapter/out/persistence/mapper/MealMapper.kt
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,40 @@ | ||
package com.core.adapter.out.persistence.mapper | ||
|
||
import com.core.adapter.out.persistence.entity.MealJpaEntity | ||
import com.core.adapter.out.persistence.enumerate.MealStatus | ||
import com.core.adapter.out.persistence.enumerate.MealType | ||
import com.core.application.domain.meal.model.Meal | ||
import org.springframework.stereotype.Component | ||
import java.math.BigDecimal | ||
import java.time.LocalDateTime | ||
|
||
@Component | ||
data class MealMapper( | ||
var idx: Long = 0, | ||
var meals: String = "", | ||
var type: MealType = MealType.LUNCH, | ||
var status: MealStatus = MealStatus.OPEN, | ||
var price: BigDecimal = BigDecimal.ZERO, | ||
var offeredAt: LocalDateTime = LocalDateTime.now(), | ||
val isDeleted: Boolean = false, | ||
val updatedAt: LocalDateTime = LocalDateTime.now(), | ||
val createdAt: LocalDateTime = LocalDateTime.now(), | ||
var restaurantName: String = "DEFAULT", | ||
) { | ||
fun toDomain(mealJpaEntities: List<MealJpaEntity>): List<Meal> { | ||
return mealJpaEntities.map { | ||
Meal( | ||
idx = it.idx, | ||
meals = it.meals, | ||
type = it.type, | ||
status = it.status, | ||
price = it.price, | ||
offeredAt = it.offeredAt, | ||
isDeleted = it.isDeleted, | ||
restaurantName = it.restaurantJpaEntity.name, | ||
updatedAt = it.updatedAt, | ||
createdAt = it.createdAt, | ||
) | ||
} | ||
} | ||
} |
18 changes: 17 additions & 1 deletion
18
core/src/main/kotlin/com/core/adapter/out/persistence/repository/MealRepository.kt
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,20 @@ | ||
package com.core.adapter.out.persistence.repository | ||
|
||
interface MealRepository { | ||
import com.core.adapter.out.persistence.entity.MealJpaEntity | ||
import org.springframework.data.jpa.repository.JpaRepository | ||
import org.springframework.data.jpa.repository.Query | ||
import org.springframework.stereotype.Repository | ||
import java.time.LocalDate | ||
import java.time.LocalDateTime | ||
|
||
@Repository | ||
interface MealRepository: JpaRepository<MealJpaEntity, Long> { | ||
|
||
@Query(""" | ||
SELECT m | ||
FROM MealJpaEntity m | ||
left join RestaurantJpaEntity r on r.name = :restaurantName | ||
WHERE m.isDeleted = false and m.offeredAt between :start and :end | ||
""") | ||
fun getWeekMeal(restaurantName: String, start: LocalDate, end: LocalDate): List<MealJpaEntity> | ||
} |
13 changes: 13 additions & 0 deletions
13
core/src/main/kotlin/com/core/application/domain/meal/model/Campus.kt
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,13 @@ | ||
package com.core.application.domain.meal.model | ||
|
||
import java.time.LocalDateTime | ||
|
||
data class Campus( | ||
val idx: Long = 0, | ||
val name: String = "DEFAULT", | ||
val address: String = "DEFAULT", | ||
val isDeleted: Boolean = false, | ||
val updatedDate: LocalDateTime = LocalDateTime.now(), | ||
val createdDate: LocalDateTime = LocalDateTime.now(), | ||
) { | ||
} |
21 changes: 15 additions & 6 deletions
21
core/src/main/kotlin/com/core/application/domain/meal/model/Meal.kt
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
14 changes: 14 additions & 0 deletions
14
core/src/main/kotlin/com/core/application/domain/meal/model/Restaurant.kt
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,14 @@ | ||
package com.core.application.domain.meal.model | ||
|
||
import java.time.LocalDateTime | ||
|
||
data class Restaurant( | ||
val idx: Long = 0, | ||
val name: String = "DEFAULT", | ||
val address: String = "DEFAULT", | ||
val isDeleted: Boolean = false, | ||
val campusJpaEntity: Campus = Campus(), | ||
val updatedDate: LocalDateTime = LocalDateTime.now(), | ||
val createdDate: LocalDateTime = LocalDateTime.now(), | ||
) { | ||
} |
Oops, something went wrong.