Skip to content

Commit 8f497a7

Browse files
committed
feat: 활동 연혁 서비스 로직 구현 (DASOMBE-15)
1 parent 6899774 commit 8f497a7

File tree

2 files changed

+78
-0
lines changed

2 files changed

+78
-0
lines changed
Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package dmu.dasom.api.domain.activity.service;
2+
3+
import dmu.dasom.api.domain.activity.dto.ActivityHistoryRequestDto;
4+
import dmu.dasom.api.domain.activity.dto.ActivityHistoryResponseDto;
5+
import dmu.dasom.api.domain.activity.dto.GroupedActivityHistoryDto;
6+
7+
import java.util.List;
8+
9+
public interface ActivityHistoryService {
10+
11+
List<GroupedActivityHistoryDto> getAllHistories();
12+
13+
ActivityHistoryResponseDto createHistory(ActivityHistoryRequestDto requestDto);
14+
15+
ActivityHistoryResponseDto updateHistory(Long id, ActivityHistoryRequestDto requestDto);
16+
17+
void deleteHistory(Long id);
18+
}
Lines changed: 60 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,60 @@
1+
package dmu.dasom.api.domain.activity.service;
2+
3+
import dmu.dasom.api.domain.activity.dto.ActivityHistoryRequestDto;
4+
import dmu.dasom.api.domain.activity.dto.ActivityHistoryResponseDto;
5+
import dmu.dasom.api.domain.activity.dto.GroupedActivityHistoryDto;
6+
import dmu.dasom.api.domain.activity.entity.ActivityHistory;
7+
import dmu.dasom.api.domain.activity.repository.ActivityHistoryRepository;
8+
import dmu.dasom.api.domain.common.exception.CustomException;
9+
import dmu.dasom.api.domain.common.exception.ErrorCode;
10+
import lombok.RequiredArgsConstructor;
11+
import org.springframework.stereotype.Service;
12+
import org.springframework.transaction.annotation.Transactional;
13+
14+
import java.util.List;
15+
16+
@Service
17+
@RequiredArgsConstructor
18+
@Transactional
19+
public class ActivityHistoryServiceImpl implements ActivityHistoryService {
20+
21+
private final ActivityHistoryRepository historyRepository;
22+
23+
@Override
24+
@Transactional(readOnly = true)
25+
public List<GroupedActivityHistoryDto> getAllHistories() {
26+
List<ActivityHistory> histories = historyRepository.findAll();
27+
return GroupedActivityHistoryDto.groupedActivityHistoryDto(histories);
28+
}
29+
30+
@Override
31+
public ActivityHistoryResponseDto createHistory(ActivityHistoryRequestDto requestDto) {
32+
ActivityHistory history = requestDto.toEntity();
33+
ActivityHistory savedHistory = historyRepository.save(history);
34+
return ActivityHistoryResponseDto.toDto(savedHistory);
35+
}
36+
37+
@Override
38+
public ActivityHistoryResponseDto updateHistory(Long id, ActivityHistoryRequestDto requestDto) {
39+
ActivityHistory history = historyRepository.findById(id)
40+
// CustomException 사용
41+
.orElseThrow(() -> new CustomException(ErrorCode.NOT_FOUND));
42+
43+
history.update(
44+
requestDto.getYear(),
45+
requestDto.getSection(),
46+
requestDto.getTitle(),
47+
requestDto.getAward()
48+
);
49+
return ActivityHistoryResponseDto.toDto(history);
50+
}
51+
52+
@Override
53+
public void deleteHistory(Long id) {
54+
// CustomException 사용
55+
if (!historyRepository.existsById(id)) {
56+
throw new CustomException(ErrorCode.NOT_FOUND);
57+
}
58+
historyRepository.deleteById(id);
59+
}
60+
}

0 commit comments

Comments
 (0)