-
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.
Merge pull request #76 from DSM-Repo/history
- Loading branch information
Showing
15 changed files
with
222 additions
and
0 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
20 changes: 20 additions & 0 deletions
20
src/main/java/com/example/whopper/application/history/impl/CreateHistoryService.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 com.example.whopper.application.history.impl; | ||
|
||
import com.example.whopper.application.history.usecase.CreateHistoryUseCase; | ||
import com.example.whopper.domain.history.HistoryModel; | ||
import com.example.whopper.domain.history.HistoryRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
class CreateHistoryService implements CreateHistoryUseCase { | ||
private final HistoryRepository historyRepository; | ||
|
||
@Override | ||
public void create(String date, String content) { | ||
final var newModel = new HistoryModel(date, content); | ||
|
||
historyRepository.save(newModel); | ||
} | ||
} |
17 changes: 17 additions & 0 deletions
17
src/main/java/com/example/whopper/application/history/impl/DeleteHistoryService.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,17 @@ | ||
package com.example.whopper.application.history.impl; | ||
|
||
import com.example.whopper.application.history.usecase.DeleteHistoryUseCase; | ||
import com.example.whopper.domain.history.HistoryRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
class DeleteHistoryService implements DeleteHistoryUseCase { | ||
private final HistoryRepository historyRepository; | ||
|
||
@Override | ||
public void deleteById(String historyId) { | ||
historyRepository.deleteById(historyId); | ||
} | ||
} |
22 changes: 22 additions & 0 deletions
22
src/main/java/com/example/whopper/application/history/impl/ViewHistoryService.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,22 @@ | ||
package com.example.whopper.application.history.impl; | ||
|
||
import com.example.whopper.application.history.usecase.ViewHistoryUseCase; | ||
import com.example.whopper.domain.history.HistoryRepository; | ||
import com.example.whopper.interfaces.history.dto.HistoryResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
class ViewHistoryService implements ViewHistoryUseCase { | ||
private final HistoryRepository historyRepository; | ||
|
||
@Override | ||
public List<HistoryResponse> viewAll() { | ||
return historyRepository.findAll() | ||
.map(history -> new HistoryResponse(history.id(), history.date(), history.content())) | ||
.toList(); | ||
} | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/example/whopper/application/history/usecase/CreateHistoryUseCase.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,5 @@ | ||
package com.example.whopper.application.history.usecase; | ||
|
||
public interface CreateHistoryUseCase { | ||
void create(String date, String content); | ||
} |
5 changes: 5 additions & 0 deletions
5
src/main/java/com/example/whopper/application/history/usecase/DeleteHistoryUseCase.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,5 @@ | ||
package com.example.whopper.application.history.usecase; | ||
|
||
public interface DeleteHistoryUseCase { | ||
void deleteById(String historyId); | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/example/whopper/application/history/usecase/ViewHistoryUseCase.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,9 @@ | ||
package com.example.whopper.application.history.usecase; | ||
|
||
import com.example.whopper.interfaces.history.dto.HistoryResponse; | ||
|
||
import java.util.List; | ||
|
||
public interface ViewHistoryUseCase { | ||
List<HistoryResponse> viewAll(); | ||
} |
11 changes: 11 additions & 0 deletions
11
src/main/java/com/example/whopper/domain/history/HistoryDataRepository.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 com.example.whopper.domain.history; | ||
|
||
import org.springframework.data.repository.Repository; | ||
|
||
import java.util.stream.Stream; | ||
|
||
interface HistoryDataRepository extends Repository<HistoryEntity, String> { | ||
Stream<HistoryEntity> findAll(); | ||
void save(HistoryEntity entity); | ||
void deleteById(String id); | ||
} |
21 changes: 21 additions & 0 deletions
21
src/main/java/com/example/whopper/domain/history/HistoryEntity.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 com.example.whopper.domain.history; | ||
|
||
import lombok.AccessLevel; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.data.mongodb.core.mapping.Document; | ||
|
||
@Document("history_repo") | ||
@Getter(value = AccessLevel.PACKAGE) | ||
@AllArgsConstructor(access = AccessLevel.PACKAGE) | ||
class HistoryEntity { | ||
@Id | ||
private String id; | ||
|
||
private String date; | ||
|
||
private String content; | ||
|
||
protected HistoryEntity() {} | ||
} |
10 changes: 10 additions & 0 deletions
10
src/main/java/com/example/whopper/domain/history/HistoryEntityMapper.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,10 @@ | ||
package com.example.whopper.domain.history; | ||
|
||
import org.mapstruct.Mapper; | ||
import org.mapstruct.ReportingPolicy; | ||
|
||
@Mapper(componentModel = "spring", unmappedSourcePolicy = ReportingPolicy.IGNORE) | ||
public interface HistoryEntityMapper { | ||
HistoryModel toModel(HistoryEntity entity); | ||
HistoryEntity toEntity(HistoryModel model); | ||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/example/whopper/domain/history/HistoryModel.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,14 @@ | ||
package com.example.whopper.domain.history; | ||
|
||
public record HistoryModel( | ||
String id, | ||
String date, | ||
String content | ||
) { | ||
public HistoryModel(String date, String content) { | ||
this(null, date, content); | ||
} | ||
public HistoryModel update(String date, String content) { | ||
return new HistoryModel(id, date, content); | ||
} | ||
} |
9 changes: 9 additions & 0 deletions
9
src/main/java/com/example/whopper/domain/history/HistoryRepository.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,9 @@ | ||
package com.example.whopper.domain.history; | ||
|
||
import java.util.stream.Stream; | ||
|
||
public interface HistoryRepository { | ||
void save(HistoryModel model); | ||
void deleteById(String historyId); | ||
Stream<HistoryModel> findAll(); | ||
} |
29 changes: 29 additions & 0 deletions
29
src/main/java/com/example/whopper/domain/history/HistoryRepositoryImpl.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,29 @@ | ||
package com.example.whopper.domain.history; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.stream.Stream; | ||
|
||
@Repository | ||
@RequiredArgsConstructor | ||
class HistoryRepositoryImpl implements HistoryRepository { | ||
private final HistoryDataRepository historyDataRepository; | ||
private final HistoryEntityMapper historyEntityMapper; | ||
|
||
@Override | ||
public void save(HistoryModel model) { | ||
historyDataRepository.save(historyEntityMapper.toEntity(model)); | ||
} | ||
|
||
@Override | ||
public void deleteById(String historyId) { | ||
historyDataRepository.deleteById(historyId); | ||
} | ||
|
||
@Override | ||
public Stream<HistoryModel> findAll() { | ||
return historyDataRepository.findAll() | ||
.map(historyEntityMapper::toModel); | ||
} | ||
} |
41 changes: 41 additions & 0 deletions
41
src/main/java/com/example/whopper/interfaces/history/HistoryController.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 com.example.whopper.interfaces.history; | ||
|
||
import com.example.whopper.application.history.usecase.CreateHistoryUseCase; | ||
import com.example.whopper.application.history.usecase.DeleteHistoryUseCase; | ||
import com.example.whopper.application.history.usecase.ViewHistoryUseCase; | ||
import com.example.whopper.common.annotation.OnlyTeacher; | ||
import com.example.whopper.interfaces.history.dto.HistoryResponse; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.web.bind.annotation.*; | ||
|
||
import java.util.List; | ||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/history") | ||
class HistoryController { | ||
private final CreateHistoryUseCase createHistoryUseCase; | ||
private final ViewHistoryUseCase viewHistoryUseCase; | ||
private final DeleteHistoryUseCase deleteHistoryUseCase; | ||
|
||
@OnlyTeacher | ||
@GetMapping | ||
List<HistoryResponse> viewAll() { | ||
return viewHistoryUseCase.viewAll(); | ||
} | ||
|
||
@OnlyTeacher | ||
@PostMapping | ||
void create(@RequestBody CreateHistoryRequest request) { | ||
createHistoryUseCase.create(request.date(), request.content()); | ||
} | ||
|
||
@OnlyTeacher | ||
@PutMapping("/del") | ||
void deleteById(@RequestBody DeleteHistoryRequest request) { | ||
deleteHistoryUseCase.deleteById(request.id()); | ||
} | ||
|
||
record DeleteHistoryRequest(String id) {} | ||
record CreateHistoryRequest(String date, String content) {} | ||
} |
4 changes: 4 additions & 0 deletions
4
src/main/java/com/example/whopper/interfaces/history/dto/HistoryResponse.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,4 @@ | ||
package com.example.whopper.interfaces.history.dto; | ||
|
||
public record HistoryResponse(String id, String date, String content) { | ||
} |