diff --git a/src/main/java/org/hankki/hankkiserver/api/store/controller/StoreController.java b/src/main/java/org/hankki/hankkiserver/api/store/controller/StoreController.java index 9b342035..1c2172f5 100644 --- a/src/main/java/org/hankki/hankkiserver/api/store/controller/StoreController.java +++ b/src/main/java/org/hankki/hankkiserver/api/store/controller/StoreController.java @@ -7,22 +7,17 @@ import org.hankki.hankkiserver.api.store.controller.request.StorePostRequest; import org.hankki.hankkiserver.api.store.parameter.PriceCategory; import org.hankki.hankkiserver.api.store.parameter.SortOption; +import org.hankki.hankkiserver.api.store.service.HeartCommandService; import org.hankki.hankkiserver.api.store.service.StoreCommandService; import org.hankki.hankkiserver.api.store.service.StoreQueryService; +import org.hankki.hankkiserver.api.store.service.command.HeartDeleteCommand; +import org.hankki.hankkiserver.api.store.service.command.HeartPostCommand; import org.hankki.hankkiserver.api.store.service.command.StorePostCommand; +import org.hankki.hankkiserver.api.store.service.command.StoreValidationCommand; import org.hankki.hankkiserver.api.store.service.response.*; +import org.hankki.hankkiserver.auth.UserId; import org.hankki.hankkiserver.common.code.CommonSuccessCode; import org.hankki.hankkiserver.domain.store.model.StoreCategory; -import org.springframework.web.bind.annotation.GetMapping; -import org.springframework.web.bind.annotation.PathVariable; -import org.hankki.hankkiserver.auth.UserId; -import org.hankki.hankkiserver.api.store.service.HeartCommandService; -import org.hankki.hankkiserver.api.store.service.command.StoreValidationCommand; -import org.hankki.hankkiserver.api.store.service.command.HeartDeleteCommand; -import org.hankki.hankkiserver.api.store.service.command.HeartPostCommand; -import org.springframework.web.bind.annotation.PostMapping; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; import org.springframework.web.bind.annotation.*; import org.springframework.web.multipart.MultipartFile; diff --git a/src/main/java/org/hankki/hankkiserver/api/universitystore/controller/UniversityStoreController.java b/src/main/java/org/hankki/hankkiserver/api/universitystore/controller/UniversityStoreController.java new file mode 100644 index 00000000..0daa93a6 --- /dev/null +++ b/src/main/java/org/hankki/hankkiserver/api/universitystore/controller/UniversityStoreController.java @@ -0,0 +1,28 @@ +package org.hankki.hankkiserver.api.universitystore.controller; + +import lombok.RequiredArgsConstructor; +import org.hankki.hankkiserver.api.dto.HankkiResponse; +import org.hankki.hankkiserver.api.universitystore.controller.request.UniviersityStoreCreateRequest; +import org.hankki.hankkiserver.api.universitystore.service.UniversityStoreCommandService; +import org.hankki.hankkiserver.api.universitystore.service.command.UniversityStorePostCommand; +import org.hankki.hankkiserver.auth.UserId; +import org.hankki.hankkiserver.common.code.CommonSuccessCode; +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("/api/v1") +public class UniversityStoreController { + + private final UniversityStoreCommandService universitystoreCommandService; + + @PostMapping("/university-stores") + public HankkiResponse createStore(@UserId final Long userId, + @RequestBody final UniviersityStoreCreateRequest request) { + universitystoreCommandService.createUniversityStore(UniversityStorePostCommand.of(userId, request.storeId(), request.universityId())); + return HankkiResponse.success(CommonSuccessCode.CREATED); + } +} diff --git a/src/main/java/org/hankki/hankkiserver/api/universitystore/controller/request/UniviersityStoreCreateRequest.java b/src/main/java/org/hankki/hankkiserver/api/universitystore/controller/request/UniviersityStoreCreateRequest.java new file mode 100644 index 00000000..625eb7ea --- /dev/null +++ b/src/main/java/org/hankki/hankkiserver/api/universitystore/controller/request/UniviersityStoreCreateRequest.java @@ -0,0 +1,7 @@ +package org.hankki.hankkiserver.api.universitystore.controller.request; + +public record UniviersityStoreCreateRequest( + Long storeId, + Long universityId +) { +} diff --git a/src/main/java/org/hankki/hankkiserver/api/universitystore/service/UniversityStoreCommandService.java b/src/main/java/org/hankki/hankkiserver/api/universitystore/service/UniversityStoreCommandService.java new file mode 100644 index 00000000..69b45b21 --- /dev/null +++ b/src/main/java/org/hankki/hankkiserver/api/universitystore/service/UniversityStoreCommandService.java @@ -0,0 +1,33 @@ +package org.hankki.hankkiserver.api.universitystore.service; + +import lombok.RequiredArgsConstructor; +import org.hankki.hankkiserver.api.auth.service.UserFinder; +import org.hankki.hankkiserver.api.report.service.ReportUpdater; +import org.hankki.hankkiserver.api.store.service.StoreFinder; +import org.hankki.hankkiserver.api.university.service.UniversityFinder; +import org.hankki.hankkiserver.api.universitystore.service.command.UniversityStorePostCommand; +import org.hankki.hankkiserver.domain.report.model.Report; +import org.hankki.hankkiserver.domain.store.model.Store; +import org.hankki.hankkiserver.domain.university.model.University; +import org.hankki.hankkiserver.domain.universitystore.model.UniversityStore; +import org.springframework.stereotype.Service; +import org.springframework.transaction.annotation.Transactional; + +@Service +@RequiredArgsConstructor +public class UniversityStoreCommandService { + + private final StoreFinder storeFinder; + private final UniversityFinder universityFinder; + private final UniversityStoreUpdater universityStoreUpdater; + private final UserFinder userFinder; + private final ReportUpdater reportUpdater; + + @Transactional + public void createUniversityStore(final UniversityStorePostCommand command) { + Store store = storeFinder.findByIdWhereDeletedIsFalse(command.storeId()); + University university = universityFinder.findById(command.universityId()); + universityStoreUpdater.save(UniversityStore.create(store,university)); + reportUpdater.save(Report.create(userFinder.getUser(command.userId()), store, university)); + } +} diff --git a/src/main/java/org/hankki/hankkiserver/api/universitystore/service/command/UniversityStorePostCommand.java b/src/main/java/org/hankki/hankkiserver/api/universitystore/service/command/UniversityStorePostCommand.java new file mode 100644 index 00000000..481610ad --- /dev/null +++ b/src/main/java/org/hankki/hankkiserver/api/universitystore/service/command/UniversityStorePostCommand.java @@ -0,0 +1,11 @@ +package org.hankki.hankkiserver.api.universitystore.service.command; + +public record UniversityStorePostCommand( + Long userId, + Long storeId, + Long universityId +) { + public static UniversityStorePostCommand of(final Long userId, final Long storeId, final Long universityId) { + return new UniversityStorePostCommand(userId, storeId, universityId); + } +}