Skip to content

Commit

Permalink
[feat] 식당 등록 API (#155)
Browse files Browse the repository at this point in the history
* [feat] dto for request

* [feat] logic for create universityStore

* [refac] move logic to university store package

* [feat] logic for add store in report table
  • Loading branch information
kgy1008 authored Aug 12, 2024
1 parent 20dda6c commit 437d39c
Show file tree
Hide file tree
Showing 5 changed files with 84 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down
Original file line number Diff line number Diff line change
@@ -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<Void> createStore(@UserId final Long userId,
@RequestBody final UniviersityStoreCreateRequest request) {
universitystoreCommandService.createUniversityStore(UniversityStorePostCommand.of(userId, request.storeId(), request.universityId()));
return HankkiResponse.success(CommonSuccessCode.CREATED);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
package org.hankki.hankkiserver.api.universitystore.controller.request;

public record UniviersityStoreCreateRequest(
Long storeId,
Long universityId
) {
}
Original file line number Diff line number Diff line change
@@ -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));
}
}
Original file line number Diff line number Diff line change
@@ -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);
}
}

0 comments on commit 437d39c

Please sign in to comment.