-
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] make command, request DTO * [feat] add static method in UniversityEntity * [feat] implements controller * [feat] implements service * [chore] update submodule * [refactor] change package * [chore] update submodule * [refactor] add a line break
- Loading branch information
1 parent
151dba5
commit 04e70b6
Showing
7 changed files
with
98 additions
and
2 deletions.
There are no files selected for viewing
Submodule server-yml
updated
from 1e7e3c to ffaf66
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
7 changes: 7 additions & 0 deletions
7
...va/org/hankki/hankkiserver/api/university/controller/request/UniversitiesPostRequest.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.university.controller.request; | ||
|
||
import java.util.List; | ||
|
||
public record UniversitiesPostRequest(List<UniversityRequest> universities) { | ||
public record UniversityRequest(String name, double longitude, double latitude) { } | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/hankki/hankkiserver/api/university/service/UniversityCommandService.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 org.hankki.hankkiserver.api.university.service; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.hankki.hankkiserver.api.university.service.command.UniversitiesPostCommand; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class UniversityCommandService { | ||
|
||
private final UniversityUpdater universityUpdater; | ||
|
||
@Transactional | ||
public void createUniversities(UniversitiesPostCommand universitiesPostCommand) { | ||
universityUpdater.saveAll(universitiesPostCommand.toEntityList()); | ||
} | ||
} |
18 changes: 18 additions & 0 deletions
18
src/main/java/org/hankki/hankkiserver/api/university/service/UniversityUpdater.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 org.hankki.hankkiserver.api.university.service; | ||
|
||
import java.util.List; | ||
import lombok.RequiredArgsConstructor; | ||
import org.hankki.hankkiserver.domain.university.model.University; | ||
import org.hankki.hankkiserver.domain.university.repository.UniversityRepository; | ||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
@RequiredArgsConstructor | ||
public class UniversityUpdater { | ||
|
||
private final UniversityRepository universityRepository; | ||
|
||
void saveAll(List<University> universities){ | ||
universityRepository.saveAll(universities); | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
.../java/org/hankki/hankkiserver/api/university/service/command/UniversitiesPostCommand.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,23 @@ | ||
package org.hankki.hankkiserver.api.university.service.command; | ||
|
||
import java.util.List; | ||
import org.hankki.hankkiserver.api.university.controller.request.UniversitiesPostRequest; | ||
import org.hankki.hankkiserver.domain.common.Point; | ||
import org.hankki.hankkiserver.domain.university.model.University; | ||
|
||
public record UniversitiesPostCommand(List<UniversityCommand> universityCommands) { | ||
|
||
record UniversityCommand(String name, double longitude, double latitude) { | ||
University toEntity() { | ||
return University.create(name, new Point(latitude, longitude)); | ||
} | ||
} | ||
|
||
public static UniversitiesPostCommand of(UniversitiesPostRequest universitiesPostRequest) { | ||
return new UniversitiesPostCommand(universitiesPostRequest.universities().stream().map(it -> new UniversityCommand(it.name(), it.longitude(), it.latitude())).toList()); | ||
} | ||
|
||
public List<University> toEntityList() { | ||
return universityCommands.stream().map(UniversityCommand::toEntity).toList(); | ||
} | ||
} |
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