-
Notifications
You must be signed in to change notification settings - Fork 1
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
[#25] [Feature] 반찬가게 API 구현 #27
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
73 changes: 73 additions & 0 deletions
73
application/app-api/src/main/java/core/startup/mealtoktok/api/dishstore/DishStoreApi.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,73 @@ | ||
package core.startup.mealtoktok.api.dishstore; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.security.core.userdetails.User; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.GetMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.PutMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import core.startup.mealtoktok.api.dishstore.request.DishStoreRequest; | ||
import core.startup.mealtoktok.api.dishstore.response.DishStoreResponse; | ||
import core.startup.mealtoktok.common.dto.Response; | ||
import core.startup.mealtoktok.domain.dishstore.DishStore; | ||
import core.startup.mealtoktok.domain.dishstore.DishStoreService; | ||
import core.startup.mealtoktok.domain.dishstore.TargetDishStore; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/api/v1") | ||
public class DishStoreApi implements DishStoreApiDocs { | ||
|
||
private final DishStoreService dishStoreService; | ||
|
||
@PostMapping("/admin/dish-stores") | ||
public Response<Void> createDishStore( | ||
@RequestBody DishStoreRequest dishStoreRequest, | ||
@AuthenticationPrincipal User currnetUser) { | ||
dishStoreService.createDishStore(dishStoreRequest.toDishStoreInfo()); | ||
return Response.success("반찬 가게 생성 성공"); | ||
} | ||
|
||
@DeleteMapping("/admin/dish-stores/{dishStoreId}") | ||
public Response<Void> deleteDishStore( | ||
@PathVariable("dishStoreId") Long dishStoreId, | ||
@AuthenticationPrincipal User currentUser) { | ||
dishStoreService.deleteDishStore(TargetDishStore.from(dishStoreId)); | ||
return Response.success("반찬 가게 삭제 성공"); | ||
} | ||
|
||
@PutMapping("/admin/dish-stores/{dishStoreId}") | ||
public Response<Void> updateDishStore( | ||
@PathVariable("dishStoreId") Long dishStoreId, | ||
@RequestBody DishStoreRequest dishStoreRequest, | ||
@AuthenticationPrincipal User currentUser) { | ||
dishStoreService.updateDishStore( | ||
TargetDishStore.from(dishStoreId), dishStoreRequest.toDishStoreInfo()); | ||
return Response.success("반찬 가게 수정 성공"); | ||
} | ||
|
||
@GetMapping("/dish-stores") | ||
public Response<List<DishStoreResponse>> readDishStores( | ||
@AuthenticationPrincipal User currentUser) { | ||
List<DishStoreResponse> dishStoreResponse = | ||
dishStoreService.readDishStores().stream().map(DishStoreResponse::from).toList(); | ||
return Response.success(dishStoreResponse); | ||
} | ||
|
||
@GetMapping("/dish-stores/{dishStoreId}") | ||
public Response<DishStoreResponse> readDishStores( | ||
@PathVariable("dishStoreId") Long dishStoreId, | ||
@AuthenticationPrincipal User currentUser) { | ||
DishStore dishStore = dishStoreService.readDishStore(TargetDishStore.from(dishStoreId)); | ||
return Response.success(DishStoreResponse.from(dishStore)); | ||
} | ||
} |
32 changes: 32 additions & 0 deletions
32
...ication/app-api/src/main/java/core/startup/mealtoktok/api/dishstore/DishStoreApiDocs.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,32 @@ | ||
package core.startup.mealtoktok.api.dishstore; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.security.core.userdetails.User; | ||
|
||
import core.startup.mealtoktok.api.dishstore.request.DishStoreRequest; | ||
import core.startup.mealtoktok.api.dishstore.response.DishStoreResponse; | ||
import core.startup.mealtoktok.common.dto.Response; | ||
|
||
import io.swagger.v3.oas.annotations.Operation; | ||
import io.swagger.v3.oas.annotations.tags.Tag; | ||
|
||
@Tag(name = "반찬 가게 API") | ||
public interface DishStoreApiDocs { | ||
|
||
@Operation(summary = "반찬 가게 생성") | ||
Response<Void> createDishStore(DishStoreRequest dishStoreRequest, User currentUser); | ||
|
||
@Operation(summary = "반찬 가게 삭제") | ||
Response<Void> deleteDishStore(Long dishStoreId, User currentUser); | ||
|
||
@Operation(summary = "반찬 가게 수정") | ||
Response<Void> updateDishStore( | ||
Long dishStoreId, DishStoreRequest dishStoreRequest, User currentUser); | ||
|
||
@Operation(summary = "반찬 가게 목록 조회") | ||
Response<List<DishStoreResponse>> readDishStores(User currentUser); | ||
|
||
@Operation(summary = "반찬 가게 상세 조회") | ||
Response<DishStoreResponse> readDishStores(Long dishStoreId, User currentUser); | ||
} |
21 changes: 21 additions & 0 deletions
21
...app-api/src/main/java/core/startup/mealtoktok/api/dishstore/request/DishStoreRequest.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,21 @@ | ||
package core.startup.mealtoktok.api.dishstore.request; | ||
|
||
import java.time.LocalTime; | ||
|
||
import core.startup.mealtoktok.domain.dishstore.DishStoreInfo; | ||
import core.startup.mealtoktok.domain.user.Address; | ||
|
||
public record DishStoreRequest( | ||
String storeName, | ||
String phoneNumber, | ||
Address address, | ||
Double latitude, | ||
Double longitude, | ||
LocalTime openTime, | ||
LocalTime closeTime) { | ||
|
||
public DishStoreInfo toDishStoreInfo() { | ||
return DishStoreInfo.of( | ||
storeName, phoneNumber, address, latitude, longitude, openTime, closeTime); | ||
} | ||
} |
26 changes: 26 additions & 0 deletions
26
...p-api/src/main/java/core/startup/mealtoktok/api/dishstore/response/DishStoreResponse.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,26 @@ | ||
package core.startup.mealtoktok.api.dishstore.response; | ||
|
||
import java.time.LocalTime; | ||
|
||
import core.startup.mealtoktok.domain.dishstore.DishStore; | ||
import core.startup.mealtoktok.domain.user.Address; | ||
|
||
public record DishStoreResponse( | ||
String storeName, | ||
String phoneNumber, | ||
Address address, | ||
Double latitude, | ||
Double longitude, | ||
LocalTime openTime, | ||
LocalTime closeTime) { | ||
public static DishStoreResponse from(DishStore dishStore) { | ||
return new DishStoreResponse( | ||
dishStore.getDishStoreInfo().storeName(), | ||
dishStore.getDishStoreInfo().phoneNumber(), | ||
dishStore.getDishStoreInfo().addressWithCoordinate().address(), | ||
dishStore.getDishStoreInfo().addressWithCoordinate().coordinate().latitude(), | ||
dishStore.getDishStoreInfo().addressWithCoordinate().coordinate().longitude(), | ||
dishStore.getDishStoreInfo().operatingHour().openTime(), | ||
dishStore.getDishStoreInfo().operatingHour().closeTime()); | ||
} | ||
} |
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
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
18 changes: 18 additions & 0 deletions
18
domain/src/main/java/core/startup/mealtoktok/domain/dishstore/DishStoreAppender.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,18 @@ | ||
package core.startup.mealtoktok.domain.dishstore; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class DishStoreAppender { | ||
|
||
private final DishStoreValidator dishStoreValidator; | ||
private final DishStoreRepository dishStoreRepository; | ||
|
||
public void append(DishStoreInfo dishStoreInfo) { | ||
dishStoreValidator.validate(dishStoreInfo.storeName()); | ||
dishStoreRepository.save(dishStoreInfo); | ||
} | ||
} |
35 changes: 35 additions & 0 deletions
35
domain/src/main/java/core/startup/mealtoktok/domain/dishstore/DishStoreInfo.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,35 @@ | ||
package core.startup.mealtoktok.domain.dishstore; | ||
|
||
import java.time.LocalTime; | ||
|
||
import core.startup.mealtoktok.domain.user.Address; | ||
import core.startup.mealtoktok.domain.user.AddressWithCoordinate; | ||
|
||
public record DishStoreInfo( | ||
String storeName, | ||
String phoneNumber, | ||
AddressWithCoordinate addressWithCoordinate, | ||
OperatingHour operatingHour) { | ||
public static DishStoreInfo of( | ||
String storeName, | ||
String phoneNumber, | ||
Address address, | ||
Double latitude, | ||
Double longitude, | ||
LocalTime openTime, | ||
LocalTime closeTime) { | ||
return new DishStoreInfo( | ||
storeName, | ||
phoneNumber, | ||
AddressWithCoordinate.of(address, latitude, longitude), | ||
OperatingHour.of(openTime, closeTime)); | ||
} | ||
|
||
public static DishStoreInfo of( | ||
String storeName, | ||
String phoneNumber, | ||
AddressWithCoordinate addressWithCoordinate, | ||
OperatingHour operatingHour) { | ||
return new DishStoreInfo(storeName, phoneNumber, addressWithCoordinate, operatingHour); | ||
} | ||
} |
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
16 changes: 16 additions & 0 deletions
16
domain/src/main/java/core/startup/mealtoktok/domain/dishstore/DishStoreRemover.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,16 @@ | ||
package core.startup.mealtoktok.domain.dishstore; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class DishStoreRemover { | ||
|
||
private final DishStoreRepository dishStoreRepository; | ||
|
||
public void remove(TargetDishStore targetDishStore) { | ||
dishStoreRepository.delete(targetDishStore); | ||
} | ||
} |
12 changes: 12 additions & 0 deletions
12
domain/src/main/java/core/startup/mealtoktok/domain/dishstore/DishStoreRepository.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,6 +1,18 @@ | ||
package core.startup.mealtoktok.domain.dishstore; | ||
|
||
import java.util.List; | ||
|
||
public interface DishStoreRepository { | ||
|
||
DishStore findById(TargetDishStore targetStore); | ||
|
||
void save(DishStoreInfo dishStoreInfo); | ||
|
||
boolean existsByDishStoreName(String dishStoreName); | ||
|
||
void delete(TargetDishStore targetDishStore); | ||
|
||
void update(TargetDishStore targetDishStore, DishStoreInfo dishStoreInfo); | ||
|
||
List<DishStore> findAll(); | ||
} |
41 changes: 41 additions & 0 deletions
41
domain/src/main/java/core/startup/mealtoktok/domain/dishstore/DishStoreService.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,41 @@ | ||
package core.startup.mealtoktok.domain.dishstore; | ||
|
||
import java.util.List; | ||
|
||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
@Transactional | ||
public class DishStoreService { | ||
|
||
private final DishStoreAppender dishStoreAppender; | ||
private final DishStoreRemover dishStoreRemover; | ||
private final DishStoreReader dishStoreReader; | ||
private final DishStoreUpdater dishStoreUpdater; | ||
|
||
public void createDishStore(DishStoreInfo dishStoreInfo) { | ||
dishStoreAppender.append(dishStoreInfo); | ||
} | ||
|
||
public void deleteDishStore(TargetDishStore targetDishStore) { | ||
dishStoreReader.read(targetDishStore); | ||
dishStoreRemover.remove(targetDishStore); | ||
} | ||
|
||
public void updateDishStore(TargetDishStore targetDishStore, DishStoreInfo dishStoreInfo) { | ||
dishStoreReader.read(targetDishStore); | ||
dishStoreUpdater.update(targetDishStore, dishStoreInfo); | ||
} | ||
|
||
public DishStore readDishStore(TargetDishStore targetDishStore) { | ||
return dishStoreReader.read(targetDishStore); | ||
} | ||
|
||
public List<DishStore> readDishStores() { | ||
return dishStoreReader.readAll(); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
domain/src/main/java/core/startup/mealtoktok/domain/dishstore/DishStoreUpdater.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,18 @@ | ||
package core.startup.mealtoktok.domain.dishstore; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class DishStoreUpdater { | ||
|
||
private final DishStoreValidator dishStoreValidator; | ||
private final DishStoreRepository dishStoreRepository; | ||
|
||
public void update(TargetDishStore targetDishStore, DishStoreInfo dishStoreInfo) { | ||
dishStoreValidator.validate(dishStoreInfo.storeName()); | ||
dishStoreRepository.update(targetDishStore, dishStoreInfo); | ||
} | ||
} |
20 changes: 20 additions & 0 deletions
20
domain/src/main/java/core/startup/mealtoktok/domain/dishstore/DishStoreValidator.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,20 @@ | ||
package core.startup.mealtoktok.domain.dishstore; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
|
||
import core.startup.mealtoktok.domain.dishstore.exception.DishStoreNameAlreadyExitsException; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class DishStoreValidator { | ||
|
||
private final DishStoreRepository dishStoreRepository; | ||
|
||
public void validate(String DishStoreName) { | ||
if (dishStoreRepository.existsByDishStoreName(DishStoreName)) { | ||
throw DishStoreNameAlreadyExitsException.EXCEPTION; | ||
} | ||
} | ||
} |
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
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
DishStore의 내용들을 DishStoreInfo로 래핑하셔서 DishStore에서 이 DTO를 사용하셔도 될꺼같아요
이거만 고치시고 merge하시면 될거같아요!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
넵 감사합니다~~