Skip to content

Commit 435d7e7

Browse files
authored
Merge pull request #16 from hykim02/main
Redis 관련 설정 파일 추가
2 parents 8ddb68e + c8e52dc commit 435d7e7

File tree

6 files changed

+91
-106
lines changed

6 files changed

+91
-106
lines changed

build.gradle

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,9 +39,11 @@ jar {
3939
}
4040

4141
dependencies {
42+
// 캐싱 redis 설정
4243
implementation 'org.springframework.boot:spring-boot-starter-data-jpa'
4344
implementation 'org.springframework.boot:spring-boot-starter-web'
4445
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
46+
4547
implementation 'io.sentry:sentry-spring-boot-starter-jakarta:8.3.0'
4648
implementation 'javax.enterprise:cdi-api:2.0'
4749
developmentOnly 'org.springframework.boot:spring-boot-devtools'

src/main/java/com/example/Jinus/config/RedisConfig.java

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,8 @@ public class RedisConfig {
2323
@Value("${spring.data.redis.password}") // 비밀번호 추가
2424
private String password;
2525

26+
27+
// redis DB와 연결
2628
@Bean
2729
public RedisConnectionFactory redisConnectionFactory() {
2830
RedisStandaloneConfiguration configuration = new RedisStandaloneConfiguration(host, port);
@@ -31,9 +33,11 @@ public RedisConnectionFactory redisConnectionFactory() {
3133
return new LettuceConnectionFactory(configuration);
3234
}
3335

36+
// redis 데이터에 접근
3437
@Bean
35-
public RedisTemplate<String, String> redisTemplate() {
36-
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>();
38+
public RedisTemplate<String, Object> redisTemplate() {
39+
RedisTemplate<String, Object> redisTemplate = new RedisTemplate<>();
40+
// spring-redis간 데이터 직렬화를 위해 설정, 설정하지 않아도 동작에 문제는 없음.
3741
redisTemplate.setKeySerializer(new StringRedisSerializer());
3842
redisTemplate.setValueSerializer(new StringRedisSerializer());
3943
redisTemplate.setConnectionFactory(redisConnectionFactory());

src/main/java/com/example/Jinus/controller/v2/DietControllerV2.java

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,4 @@ public class DietControllerV2 {
1818
public String handleRequest(@RequestBody RequestDto requestDto) {
1919
return dietServiceV2.requestHandler(requestDto);
2020
}
21-
22-
// @PostMapping("/dish")
23-
// public void handleRequest(@RequestBody String requestDto) {
24-
// System.out.println(requestDto);
25-
// }
2621
}
Lines changed: 5 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,31 @@
11
package com.example.Jinus.controller.v2;
22

33
import com.example.Jinus.dto.request.RequestDto;
4-
import com.example.Jinus.dto.response.*;
5-
import com.example.Jinus.entity.notice.NoticeCategoryEntity;
64
import com.example.Jinus.service.v2.notice.CategoryServiceV2;
75
import com.example.Jinus.service.v2.notice.NoticeServiceV2;
86
import com.example.Jinus.service.v2.userInfo.DepartmentServiceV2;
97
import com.example.Jinus.service.v2.userInfo.UserServiceV2;
10-
import com.example.Jinus.utility.JsonUtils;
11-
import com.example.Jinus.utility.TextCardResponse;
8+
import lombok.RequiredArgsConstructor;
129
import org.springframework.web.bind.annotation.PostMapping;
1310
import org.springframework.web.bind.annotation.RequestBody;
1411
import org.springframework.web.bind.annotation.RequestMapping;
1512
import org.springframework.web.bind.annotation.RestController;
1613

17-
import java.util.ArrayList;
18-
import java.util.List;
19-
20-
import static java.lang.String.valueOf;
21-
2214
@RestController
15+
@RequiredArgsConstructor
2316
@RequestMapping("/api/spring")
2417
public class NoticeControllerV2 {
2518

2619
private final NoticeServiceV2 noticeServiceV2;
27-
private final CategoryServiceV2 noticeCategoryServiceV2;
2820
private final DepartmentServiceV2 departmentServiceV2;
2921
private final UserServiceV2 userServiceV2;
3022

31-
public NoticeControllerV2(NoticeServiceV2 noticeServiceV2,
32-
CategoryServiceV2 noticeCategoryServiceV2,
33-
DepartmentServiceV2 departmentServiceV2,
34-
UserServiceV2 userServiceV2) {
35-
this.noticeServiceV2 = noticeServiceV2;
36-
this.noticeCategoryServiceV2 = noticeCategoryServiceV2;
37-
this.departmentServiceV2 = departmentServiceV2;
38-
this.userServiceV2 = userServiceV2;
39-
}
40-
4123
// 학교 공지사항 조회
4224
@PostMapping("/v2/main-notice")
4325
public String getMainNotice() {
4426
int departmentId = 117; // 학교 공지사항 id
4527
String departmentEng = "main"; // 학과 영문명
46-
return existUserReturnNotice(departmentEng, departmentId);
28+
return noticeServiceV2.existUserReturnNotice(departmentEng, departmentId);
4729
}
4830

4931
// 학과 공지사항 조회
@@ -55,64 +37,9 @@ public String responseDepartmentNotice(@RequestBody RequestDto requestDto) {
5537
String departmentEng = departmentServiceV2.getDepartmentEng(departmentId);
5638
// 사용자 학과 정보가 존재한다면
5739
if (departmentId != -1) {
58-
return existUserReturnNotice(departmentEng, departmentId);
59-
} else {
60-
return doesNotExistUserReturnBlock();
61-
}
62-
}
63-
64-
// db에 학과정보가 있는 경우 -> 공지리스트 반환
65-
public String existUserReturnNotice(String departmentEng, int departmentId) {
66-
// 학과 공지 카테고리들 가져오기
67-
List<NoticeCategoryEntity> categoryEntities = noticeCategoryServiceV2.getCategoryEntity(departmentId);
68-
69-
// 카테고리 존재 여부 확인
70-
if (!categoryEntities.isEmpty()) {
71-
return mappingCarouselItems(categoryEntities, departmentEng);
40+
return noticeServiceV2.existUserReturnNotice(departmentEng, departmentId);
7241
} else {
73-
return thereIsNoCategory();
74-
}
75-
}
76-
77-
// 공지가 존재하는 경우
78-
public String mappingCarouselItems(List<NoticeCategoryEntity> categoryEntities, String departmentEng) {
79-
// 카테고리 리스트 생성 (캐로셀 아이템 리스트)
80-
List<CarouselItemDto> categoryList = new ArrayList<>();
81-
for (NoticeCategoryEntity entity : categoryEntities) {
82-
// 해당 카테고리의 공지 ListCard 생성
83-
List<ListItemDto> noticeItemList = noticeServiceV2.getNoticeList(
84-
entity.getId(), valueOf(entity.getMi()), valueOf(entity.getBbsId()), departmentEng);
85-
// ListCard 버튼 생성
86-
List<ButtonDto> buttonList = noticeServiceV2.makeButton(
87-
departmentEng, valueOf(entity.getMi()), valueOf(entity.getBbsId()));
88-
// 카테고리 제목 header 객체 생성
89-
HeaderDto title = new HeaderDto(entity.getCategory());
90-
// 하나의 카테고리 아이템 생성
91-
CarouselItemDto carouselItem = new CarouselItemDto(title, noticeItemList, buttonList);
92-
categoryList.add(carouselItem);
42+
return noticeServiceV2.doesNotExistUserReturnBlock();
9343
}
94-
CarouselDto carousel = new CarouselDto("listCard", categoryList);
95-
List<ComponentDto> componentList = new ArrayList<>();
96-
componentList.add(new ComponentDto(carousel));
97-
TemplateDto templateDto = new TemplateDto(componentList);
98-
ResponseDto responseDto = new ResponseDto("2.0", templateDto);
99-
return JsonUtils.toJsonResponse(responseDto);
100-
}
101-
102-
// 공지가 존재하지 않는 경우 예외처리
103-
public String thereIsNoCategory() {
104-
List<ButtonDto> buttonList = new ArrayList<>();
105-
ButtonDto buttonDto = new ButtonDto("게시판 등록 요청", "webLink", "https://forms.gle/cSMheFmmGDe7P3RD6");
106-
buttonList.add(buttonDto);
107-
return TextCardResponse.textCardResponse("최근에 등록된 공지사항이 없어!", buttonList);
108-
}
109-
110-
// 사용자 학과 정보가 없는 경우 학과인증 블록 리턴 예외처리
111-
public String doesNotExistUserReturnBlock() {
112-
List<ButtonDto> buttonList = new ArrayList<>();
113-
// 블록 버튼 생성
114-
ButtonDto buttonDto = new ButtonDto("학과 등록", "block", null,"66cf0c8ae5715f75b254dfea");
115-
buttonList.add(buttonDto);
116-
return TextCardResponse.textCardResponse("학과 등록이 필요한 서비스야! 학과 등록을 진행해줘.", buttonList);
11744
}
11845
}

src/main/java/com/example/Jinus/service/v2/cafeteria/CafeteriaServiceV2.java

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -26,21 +26,6 @@ public CafeteriaServiceV2(
2626
this.campusServiceV2 = campusServiceV2;
2727
}
2828

29-
// 사용자의 campusId와 동일한 식당리스트 찾기
30-
public List<Object[]> getCafeteriaList(int campusId) {
31-
return cafeteriaRepositoryV2.findCafeteriaListByCampusId(campusId);
32-
}
33-
34-
// 캠퍼스에 식당이 존재한다면 cafeteriaId 찾기
35-
public int getCafeteriaId(String cafeteriaName, int campusId) {
36-
return cafeteriaRepositoryV2.findCafeteriaId(cafeteriaName, campusId).orElse(-1);
37-
}
38-
39-
// 식당 imgUrl 찾기
40-
public String getImgUrl(int cafeteriaId) {
41-
return cafeteriaRepositoryV2.findImgUrlByCafeteriaId(cafeteriaId);
42-
}
43-
4429
// 반환 조건 설정
4530
public String campusOrCafeteria(int campusId, int sysCampusId) {
4631
// 더보기 버튼 누른 경우
@@ -54,7 +39,7 @@ public String campusOrCafeteria(int campusId, int sysCampusId) {
5439
}
5540

5641
// 사용자가 원하는 캠퍼스가 없을 때
57-
return (campusId != -1)
42+
return (campusId != -1) // 사용자 존재 여부
5843
? makeCafeteriaListCard(campusId)
5944
: campusServiceV2.makeCampusListCard();
6045
}
@@ -97,4 +82,19 @@ public List<ButtonDto> mappingButtonDto() {
9782
buttonDto.add(button);
9883
return buttonDto;
9984
}
85+
86+
// 사용자의 campusId와 동일한 식당리스트 찾기
87+
public List<Object[]> getCafeteriaList(int campusId) {
88+
return cafeteriaRepositoryV2.findCafeteriaListByCampusId(campusId);
89+
}
90+
91+
// 캠퍼스에 식당이 존재한다면 cafeteriaId 찾기
92+
public int getCafeteriaId(String cafeteriaName, int campusId) {
93+
return cafeteriaRepositoryV2.findCafeteriaId(cafeteriaName, campusId).orElse(-1);
94+
}
95+
96+
// 식당 imgUrl 찾기
97+
public String getImgUrl(int cafeteriaId) {
98+
return cafeteriaRepositoryV2.findImgUrlByCafeteriaId(cafeteriaId);
99+
}
100100
}

src/main/java/com/example/Jinus/service/v2/notice/NoticeServiceV2.java

Lines changed: 62 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,79 @@
11
package com.example.Jinus.service.v2.notice;
22

3-
import com.example.Jinus.dto.response.ButtonDto;
4-
import com.example.Jinus.dto.response.LinkItemDto;
5-
import com.example.Jinus.dto.response.ListItemDto;
3+
import com.example.Jinus.dto.response.*;
4+
import com.example.Jinus.entity.notice.NoticeCategoryEntity;
65
import com.example.Jinus.entity.notice.NoticeEntity;
76
import com.example.Jinus.repository.v2.notice.NoticeRepositoryV2;
7+
import com.example.Jinus.utility.JsonUtils;
8+
import com.example.Jinus.utility.TextCardResponse;
9+
import lombok.RequiredArgsConstructor;
810
import org.springframework.stereotype.Service;
911

1012
import java.util.ArrayList;
1113
import java.util.List;
1214

15+
import static java.lang.String.valueOf;
16+
1317
@Service
18+
@RequiredArgsConstructor
1419
public class NoticeServiceV2 {
1520

1621
private final NoticeRepositoryV2 noticeRepositoryV2;
22+
private final CategoryServiceV2 categoryServiceV2;
23+
24+
// db에 학과정보가 있는 경우 -> 공지리스트 반환
25+
public String existUserReturnNotice(String departmentEng, int departmentId) {
26+
// 학과 공지 카테고리들 가져오기
27+
List<NoticeCategoryEntity> categoryEntities = categoryServiceV2.getCategoryEntity(departmentId);
28+
29+
// 카테고리 존재 여부 확인
30+
if (!categoryEntities.isEmpty()) {
31+
return mappingCarouselItems(categoryEntities, departmentEng);
32+
} else {
33+
return thereIsNoCategory();
34+
}
35+
}
36+
37+
// 사용자 학과 정보가 없는 경우 학과인증 블록 리턴 예외처리
38+
public String doesNotExistUserReturnBlock() {
39+
List<ButtonDto> buttonList = new ArrayList<>();
40+
// 블록 버튼 생성
41+
ButtonDto buttonDto = new ButtonDto("학과 등록", "block", null,"66cf0c8ae5715f75b254dfea");
42+
buttonList.add(buttonDto);
43+
return TextCardResponse.textCardResponse("학과 등록이 필요한 서비스야! 학과 등록을 진행해줘.", buttonList);
44+
}
45+
46+
// 공지가 존재하는 경우
47+
public String mappingCarouselItems(List<NoticeCategoryEntity> categoryEntities, String departmentEng) {
48+
// 카테고리 리스트 생성 (캐로셀 아이템 리스트)
49+
List<CarouselItemDto> categoryList = new ArrayList<>();
50+
for (NoticeCategoryEntity entity : categoryEntities) {
51+
// 해당 카테고리의 공지 ListCard 생성
52+
List<ListItemDto> noticeItemList = getNoticeList(
53+
entity.getId(), valueOf(entity.getMi()), valueOf(entity.getBbsId()), departmentEng);
54+
// ListCard 버튼 생성
55+
List<ButtonDto> buttonList = makeButton(
56+
departmentEng, valueOf(entity.getMi()), valueOf(entity.getBbsId()));
57+
// 카테고리 제목 header 객체 생성
58+
HeaderDto title = new HeaderDto(entity.getCategory());
59+
// 하나의 카테고리 아이템 생성
60+
CarouselItemDto carouselItem = new CarouselItemDto(title, noticeItemList, buttonList);
61+
categoryList.add(carouselItem);
62+
}
63+
CarouselDto carousel = new CarouselDto("listCard", categoryList);
64+
List<ComponentDto> componentList = new ArrayList<>();
65+
componentList.add(new ComponentDto(carousel));
66+
TemplateDto templateDto = new TemplateDto(componentList);
67+
ResponseDto responseDto = new ResponseDto("2.0", templateDto);
68+
return JsonUtils.toJsonResponse(responseDto);
69+
}
1770

18-
public NoticeServiceV2(NoticeRepositoryV2 noticeRepositoryV2){
19-
this.noticeRepositoryV2 = noticeRepositoryV2;
71+
// 공지가 존재하지 않는 경우 예외처리
72+
public String thereIsNoCategory() {
73+
List<ButtonDto> buttonList = new ArrayList<>();
74+
ButtonDto buttonDto = new ButtonDto("게시판 등록 요청", "webLink", "https://forms.gle/cSMheFmmGDe7P3RD6");
75+
buttonList.add(buttonDto);
76+
return TextCardResponse.textCardResponse("최근에 등록된 공지사항이 없어!", buttonList);
2077
}
2178

2279
// categoryId에 해당하는 공지 찾아 itemList 객체 생성

0 commit comments

Comments
 (0)