-
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.
* [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
Showing
5 changed files
with
84 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
28 changes: 28 additions & 0 deletions
28
...ava/org/hankki/hankkiserver/api/universitystore/controller/UniversityStoreController.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,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); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ki/hankkiserver/api/universitystore/controller/request/UniviersityStoreCreateRequest.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,7 @@ | ||
package org.hankki.hankkiserver.api.universitystore.controller.request; | ||
|
||
public record UniviersityStoreCreateRequest( | ||
Long storeId, | ||
Long universityId | ||
) { | ||
} |
33 changes: 33 additions & 0 deletions
33
...va/org/hankki/hankkiserver/api/universitystore/service/UniversityStoreCommandService.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,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)); | ||
} | ||
} |
11 changes: 11 additions & 0 deletions
11
...g/hankki/hankkiserver/api/universitystore/service/command/UniversityStorePostCommand.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,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); | ||
} | ||
} |