

240726 정다정 반 CRUD
@72c3717c5905912050a43d89656089ca1022ac1f
--- src/main/java/com/takensoft/ai_lms/common/confing/SecurityConfig.java
+++ src/main/java/com/takensoft/ai_lms/common/confing/SecurityConfig.java
... | ... | @@ -67,6 +67,7 @@ |
67 | 67 |
.requestMatchers("/board/**").permitAll() // 게시판 정보 진입 허용 |
68 | 68 |
.requestMatchers("/book/**").permitAll() // 교재 정보 진입 허용 |
69 | 69 |
.requestMatchers("/file/**").permitAll() // 게시판 정보 진입 허용 |
70 |
+ .requestMatchers("/classes/**").permitAll() // 반 정보 진입 허용 |
|
70 | 71 |
.anyRequest().authenticated()); // 나머지 경로는 인증 필요 |
71 | 72 |
|
72 | 73 |
// jwt 필터 처리 적용 |
+++ src/main/java/com/takensoft/ai_lms/lms/classes/dao/ClassDAO.java
... | ... | @@ -0,0 +1,30 @@ |
1 | +package com.takensoft.ai_lms.lms.classes.dao; | |
2 | + | |
3 | +import com.takensoft.ai_lms.lms.classes.vo.ClassVO; | |
4 | +import org.apache.ibatis.annotations.Mapper; | |
5 | + | |
6 | +import java.util.List; | |
7 | + | |
8 | +/** | |
9 | + * @author : 정다정 | |
10 | + * @since : 2024.07.25 | |
11 | + * | |
12 | + * 반 관련 Mapper | |
13 | + */ | |
14 | +@Mapper() | |
15 | +public interface ClassDAO { | |
16 | + // 반 조회 | |
17 | + public List<ClassVO> selectClass(String userId) throws Exception; | |
18 | + | |
19 | + // 반 생성 | |
20 | + public int insertClass(ClassVO classVO) throws Exception; | |
21 | + | |
22 | + // 반 수정 | |
23 | + public int updateClass(ClassVO classVO) throws Exception; | |
24 | + | |
25 | + // 반 삭체 | |
26 | + public int deleteClass(String sclsId) throws Exception; | |
27 | + | |
28 | + // 반 아이디(scls_id) 존재 확인 | |
29 | + public int existsClassById(String sclsId) throws Exception; | |
30 | +} |
+++ src/main/java/com/takensoft/ai_lms/lms/classes/service/ClassService.java
... | ... | @@ -0,0 +1,28 @@ |
1 | +package com.takensoft.ai_lms.lms.classes.service; | |
2 | + | |
3 | +import com.takensoft.ai_lms.lms.classes.vo.ClassVO; | |
4 | + | |
5 | +import java.util.List; | |
6 | + | |
7 | +/** | |
8 | + * @author : 정다정 | |
9 | + * since : 2024.07.25 | |
10 | + * | |
11 | + * 반 조회 관련 인터페이스 | |
12 | + */ | |
13 | +public interface ClassService { | |
14 | + // 반 조회 | |
15 | + public List<ClassVO> selectClass(String userId) throws Exception; | |
16 | + | |
17 | + // 반 생성 | |
18 | + public int insertClass(ClassVO classVO) throws Exception; | |
19 | + | |
20 | + // 반 수정 | |
21 | + public int updateClass(ClassVO classVO) throws Exception; | |
22 | + | |
23 | + // 반 삭제 | |
24 | + public int deleteClass(String sclsId) throws Exception; | |
25 | + | |
26 | + // 반 아이디(scls_id) 존재 확인 | |
27 | + boolean existsClassById(String sclsId) throws Exception; | |
28 | +} |
+++ src/main/java/com/takensoft/ai_lms/lms/classes/service/Impl/ClassServiceImpl.java
... | ... | @@ -0,0 +1,67 @@ |
1 | +package com.takensoft.ai_lms.lms.classes.service.Impl; | |
2 | + | |
3 | +import com.takensoft.ai_lms.common.idgen.service.IdgenService; | |
4 | +import com.takensoft.ai_lms.lms.classes.dao.ClassDAO; | |
5 | +import com.takensoft.ai_lms.lms.classes.service.ClassService; | |
6 | +import com.takensoft.ai_lms.lms.classes.vo.ClassVO; | |
7 | +import lombok.RequiredArgsConstructor; | |
8 | +import org.springframework.stereotype.Service; | |
9 | +import org.springframework.transaction.annotation.Transactional; | |
10 | + | |
11 | +import java.util.List; | |
12 | + | |
13 | +@Service | |
14 | +@RequiredArgsConstructor | |
15 | +public class ClassServiceImpl implements ClassService { | |
16 | + | |
17 | + private final ClassDAO classDAO; | |
18 | + | |
19 | + private final IdgenService classIdgn; | |
20 | + | |
21 | + /** | |
22 | + * 반 조회 | |
23 | + */ | |
24 | + @Override | |
25 | + @Transactional | |
26 | + public List<ClassVO> selectClass(String userId) throws Exception{ | |
27 | + return classDAO.selectClass(userId); | |
28 | + } | |
29 | + | |
30 | + /** | |
31 | + * 반 생성 | |
32 | + */ | |
33 | + @Override | |
34 | + @Transactional | |
35 | + public int insertClass(ClassVO classVO) throws Exception{ | |
36 | + String sclsId = classIdgn.getNextStringId(); | |
37 | + classVO.setSclsId(sclsId); | |
38 | + return classDAO.insertClass(classVO); | |
39 | + } | |
40 | + | |
41 | + /** | |
42 | + * 반 수정 | |
43 | + */ | |
44 | + @Override | |
45 | + @Transactional | |
46 | + public int updateClass(ClassVO classVO) throws Exception{ | |
47 | + return classDAO.updateClass(classVO); | |
48 | + } | |
49 | + | |
50 | + /** | |
51 | + * 반 삭제 | |
52 | + */ | |
53 | + @Override | |
54 | + @Transactional | |
55 | + public int deleteClass(String sclsId) throws Exception { | |
56 | + return classDAO.deleteClass(sclsId); | |
57 | + } | |
58 | + | |
59 | + /** | |
60 | + * 반 아이디(scls_id) 존재 확인 | |
61 | + */ | |
62 | + @Override | |
63 | + @Transactional | |
64 | + public boolean existsClassById(String sclsId) throws Exception { | |
65 | + return classDAO.existsClassById(sclsId) > 0; | |
66 | + } | |
67 | +} |
+++ src/main/java/com/takensoft/ai_lms/lms/classes/vo/ClassVO.java
... | ... | @@ -0,0 +1,20 @@ |
1 | +package com.takensoft.ai_lms.lms.classes.vo; | |
2 | + | |
3 | +import lombok.AllArgsConstructor; | |
4 | +import lombok.Getter; | |
5 | +import lombok.NoArgsConstructor; | |
6 | +import lombok.Setter; | |
7 | + | |
8 | +@Setter | |
9 | +@Getter | |
10 | +@NoArgsConstructor | |
11 | +@AllArgsConstructor | |
12 | + | |
13 | +public class ClassVO { | |
14 | + // 반 아이디 | |
15 | + public String sclsId; | |
16 | + // 사용자 아이디(선생) | |
17 | + public String userId; | |
18 | + // 반 이름 | |
19 | + public String sclsNm; | |
20 | +} |
+++ src/main/java/com/takensoft/ai_lms/lms/classes/web/ClassController.java
... | ... | @@ -0,0 +1,174 @@ |
1 | +package com.takensoft.ai_lms.lms.classes.web; | |
2 | + | |
3 | +import com.google.gson.Gson; | |
4 | +import com.google.gson.JsonObject; | |
5 | +import com.takensoft.ai_lms.lms.classes.service.ClassService; | |
6 | +import com.takensoft.ai_lms.lms.classes.vo.ClassVO; | |
7 | +import io.swagger.v3.oas.annotations.Operation; | |
8 | +import lombok.RequiredArgsConstructor; | |
9 | +import lombok.extern.slf4j.Slf4j; | |
10 | +import org.springframework.web.bind.annotation.*; | |
11 | + | |
12 | +import java.util.List; | |
13 | +import java.util.Map; | |
14 | + | |
15 | +@RestController | |
16 | +@RequiredArgsConstructor | |
17 | +@Slf4j | |
18 | +@RequestMapping(value="/classes") | |
19 | +public class ClassController { | |
20 | + | |
21 | + private final ClassService classService; | |
22 | + | |
23 | + /** | |
24 | + * @author 정다정 | |
25 | + * @since 2024.07.25 | |
26 | + * param ClassDAO | |
27 | + * @return | |
28 | + * @throws Exception | |
29 | + * | |
30 | + * 반 조회 | |
31 | + */ | |
32 | + @PostMapping("/selectClass.json") | |
33 | + @Operation(summary = "반 조회") | |
34 | + public String selectClass(@RequestBody Map<String, Object> params) throws Exception { | |
35 | + Gson gson = new Gson(); | |
36 | + JsonObject response = new JsonObject(); | |
37 | + | |
38 | + try { | |
39 | + String userId = params.get("userId").toString(); | |
40 | + List<ClassVO> result = classService.selectClass(userId); | |
41 | + | |
42 | + response.addProperty("status", "success"); | |
43 | + response.add("data", gson.toJsonTree(result)); | |
44 | + | |
45 | + return gson.toJson(response); | |
46 | + } catch (Exception e) { | |
47 | + e.printStackTrace(); | |
48 | + | |
49 | + response.addProperty("status", "error"); | |
50 | + response.addProperty("message", e.getMessage()); | |
51 | + | |
52 | + return gson.toJson(response); | |
53 | + } | |
54 | + } | |
55 | + | |
56 | + /** | |
57 | + * @author 정다정 | |
58 | + * @since 2024.07.25 | |
59 | + * param ClassDAO | |
60 | + * @return | |
61 | + * @throws Exception | |
62 | + * | |
63 | + * 반 생성 | |
64 | + */ | |
65 | + @PostMapping("/insertClass.json") | |
66 | + @Operation(summary = "반 생성") | |
67 | + public String insertClass(@RequestBody ClassVO classVO) throws Exception{ | |
68 | + Gson gson = new Gson(); | |
69 | + JsonObject response = new JsonObject(); | |
70 | + | |
71 | + try{ | |
72 | + // userId 또는 sclsNm(반 이름)이 비어있으면 fail | |
73 | + if (classVO.getUserId() == null || classVO.getUserId().isEmpty() || | |
74 | + classVO.getSclsNm() == null || classVO.getSclsNm().isEmpty()) { | |
75 | + response.addProperty("status", "fail"); | |
76 | + response.addProperty("message", "userId 또는 반 이름이 비어있습니다."); | |
77 | + return gson.toJson(response); | |
78 | + } | |
79 | + | |
80 | + int result = classService.insertClass(classVO); | |
81 | + | |
82 | + if(result == -1){ | |
83 | + response.addProperty("status", "fail"); | |
84 | + return gson.toJson(response); | |
85 | + } | |
86 | + | |
87 | + response.addProperty("status", "success"); | |
88 | + return gson.toJson(response); | |
89 | + } catch (Exception e) { | |
90 | + e.printStackTrace(); | |
91 | + | |
92 | + response.addProperty("status", "error"); | |
93 | + response.addProperty("message", e.getMessage()); | |
94 | + | |
95 | + return gson.toJson(response); | |
96 | + } | |
97 | + } | |
98 | + | |
99 | + /** | |
100 | + * @author 정다정 | |
101 | + * @since 2024.07.25 | |
102 | + * param ClassDAO | |
103 | + * @return | |
104 | + * @throws Exception | |
105 | + * | |
106 | + * 반 수정 | |
107 | + */ | |
108 | + @PostMapping("/updateClass.json") | |
109 | + @Operation(summary = "반 수정") | |
110 | + public String updateClass(@RequestBody ClassVO classVO) throws Exception{ | |
111 | + Gson gson = new Gson(); | |
112 | + JsonObject response = new JsonObject(); | |
113 | + | |
114 | + try{ | |
115 | + // 반 아이디(scls_id)가 존재하는지 확인 | |
116 | + if (!classService.existsClassById(classVO.getSclsId())) { | |
117 | + // 반 아이디(scls_id)가 db에 존재 하지 않으면 수정 실패 | |
118 | + response.addProperty("status", "fail"); | |
119 | + response.addProperty("message", "존재 하지 않는 반 아이디(sclsId)입니다."); | |
120 | + return gson.toJson(response); | |
121 | + } | |
122 | + | |
123 | + int result = classService.updateClass(classVO); | |
124 | + | |
125 | + if(result == -1){ | |
126 | + response.addProperty("status", "fail"); | |
127 | + return gson.toJson(response); | |
128 | + } | |
129 | + | |
130 | + response.addProperty("status", "success"); | |
131 | + return gson.toJson(response); | |
132 | + } catch (Exception e) { | |
133 | + e.printStackTrace(); | |
134 | + | |
135 | + response.addProperty("status", "error"); | |
136 | + response.addProperty("message", e.getMessage()); | |
137 | + | |
138 | + return gson.toJson(response); | |
139 | + } | |
140 | + } | |
141 | + | |
142 | + | |
143 | + /** | |
144 | + * @author 정다정 | |
145 | + * @since 2024.07.25 | |
146 | + * param ClassDAO | |
147 | + * @return | |
148 | + * @throws Exception | |
149 | + * | |
150 | + * 반 삭제 | |
151 | + */ | |
152 | + @DeleteMapping("/deleteClass.json") | |
153 | + @Operation(summary = "반 삭제") | |
154 | + public String deleteClass(@RequestBody Map<String, Object> params) throws Exception{ | |
155 | + Gson gson = new Gson(); | |
156 | + JsonObject response = new JsonObject(); | |
157 | + | |
158 | + try { | |
159 | + String sclsId = params.get("sclsId").toString(); | |
160 | + classService.deleteClass(sclsId); | |
161 | + response.addProperty("status", "success"); | |
162 | + return gson.toJson(response); | |
163 | + } catch (Exception e) { | |
164 | + e.printStackTrace(); | |
165 | + | |
166 | + response.addProperty("status", "error"); | |
167 | + response.addProperty("message", e.getMessage()); | |
168 | + | |
169 | + return gson.toJson(response); | |
170 | + } | |
171 | + } | |
172 | + | |
173 | + | |
174 | +} |
+++ src/main/resources/mybatis/mapper/lms/classes-SQL.xml
... | ... | @@ -0,0 +1,79 @@ |
1 | +<?xml version="1.0" encoding="UTF-8"?> | |
2 | +<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd"> | |
3 | +<mapper namespace="com.takensoft.ai_lms.lms.classes.dao.ClassDAO"> | |
4 | + | |
5 | + <resultMap id="classMap" type="ClassVO"> | |
6 | + <result property="sclsId" column="scls_id"/> | |
7 | + <result property="userId" column="user_id"/> | |
8 | + <result property="sclsNm" column="scls_nm"/> | |
9 | + </resultMap> | |
10 | + | |
11 | + <!-- | |
12 | + 작성자 : 정다정 | |
13 | + 작성일 : 2024.07.25 | |
14 | + 내 용 : 반 조회 | |
15 | + --> | |
16 | + <select id="selectClass" parameterType="String" resultMap="classMap"> | |
17 | + SELECT scls_id | |
18 | + , user_id | |
19 | + , scls_nm | |
20 | + FROM | |
21 | + class | |
22 | + WHERE | |
23 | + user_id = #{userId} | |
24 | + </select> | |
25 | + | |
26 | + <!-- | |
27 | + 작성자 : 정다정 | |
28 | + 작성일 : 2024.07.26 | |
29 | + 내 용 : 반 생성 | |
30 | + --> | |
31 | + <insert id="insertClass" parameterType="ClassVO"> | |
32 | + INSERT INTO class( scls_id | |
33 | + , user_id | |
34 | + , scls_nm | |
35 | + ) VALUES ( #{sclsId} | |
36 | + , #{userId} | |
37 | + , #{sclsNm} | |
38 | + ); | |
39 | + </insert> | |
40 | + | |
41 | + <!-- | |
42 | + 작성자 : 정다정 | |
43 | + 작성일 : 2024.07.26 | |
44 | + 내 용 : 반 수정 | |
45 | + --> | |
46 | + <update id="updateClass" parameterType="ClassVO"> | |
47 | + UPDATE class | |
48 | + SET | |
49 | + scls_nm = #{sclsNm} | |
50 | + WHERE | |
51 | + scls_id = #{sclsId} | |
52 | + </update> | |
53 | + | |
54 | + <!-- | |
55 | + 작성자 : 정다정 | |
56 | + 작성일 : 2024.07.26 | |
57 | + 내 용 : 반 삭제 | |
58 | + --> | |
59 | + <delete id="deleteClass" parameterType="String"> | |
60 | + DELETE FROM class | |
61 | + WHERE | |
62 | + scls_id = #{sclsId} | |
63 | + </delete> | |
64 | + | |
65 | + <!-- | |
66 | + 작성자 : 정다정 | |
67 | + 작성일 : 2024.07.26 | |
68 | + 내 용 : 반 아이디(scls_id) 존재 확인 | |
69 | + --> | |
70 | + <select id="existsClassById" parameterType="String" resultType="int"> | |
71 | + SELECT | |
72 | + COUNT(*) | |
73 | + FROM | |
74 | + class | |
75 | + WHERE | |
76 | + scls_id = #{sclsId} | |
77 | + </select> | |
78 | + | |
79 | +</mapper>(No newline at end of file) |
Add a comment
Delete comment
Once you delete this comment, you won't be able to recover it. Are you sure you want to delete this comment?