Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit b217ea7

Browse files
committed
20221118 sm class들 DTO , Entity 분리 및 코드정리
1 parent c78c5ad commit b217ea7

File tree

17 files changed

+203
-107
lines changed

17 files changed

+203
-107
lines changed
Lines changed: 14 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package com.singer.application.controller.sm;
22

33
import com.singer.application.controller.BaseController;
4-
5-
import java.util.List;
4+
import com.singer.application.dto.sm.SM02ListResponse;
5+
import com.singer.application.dto.sm.SM02Request;
6+
import com.singer.application.dto.sm.SM02Response;
67

78
import org.springframework.beans.factory.annotation.Autowired;
89
import javax.servlet.http.HttpServletRequest;
@@ -11,15 +12,14 @@
1112
import org.springframework.http.HttpStatus;
1213
import org.springframework.http.ResponseEntity;
1314
import org.springframework.stereotype.Controller;
14-
import org.springframework.web.bind.annotation.ModelAttribute;
15+
import org.springframework.web.bind.annotation.PathVariable;
1516
import org.springframework.web.bind.annotation.RequestBody;
1617
import org.springframework.web.bind.annotation.RequestMapping;
1718
import org.springframework.web.bind.annotation.RequestMethod;
1819
import org.springframework.web.bind.annotation.ResponseBody;
1920
import org.springframework.web.servlet.ModelAndView;
2021

2122
import com.singer.application.service.sm.SM02Service;
22-
import com.singer.domain.entity.sm.SM02Entity;
2323

2424
import lombok.extern.slf4j.Slf4j;
2525

@@ -38,48 +38,39 @@ public ModelAndView showSM02() throws Exception {
3838

3939
@ResponseBody
4040
@RequestMapping(value = "/sm02/{nowPage}", method = RequestMethod.GET)
41-
public ResponseEntity<SM02Entity> selectSM02Vo(@ModelAttributeSM02Entitysm02Entity, HttpServletRequest request)
41+
public ResponseEntity<SM02ListResponse> selectSM02(@PathVariableintnowPage, HttpServletRequest request)
4242
throws Exception {
4343
log.debug("enter sm02 get");
4444

4545
String userid = getSessionId(request);
46-
List<SM02Entity> list = sm02Service.selectSM02Vo(sm02Entity, userid);
47-
sm02Entity.setList(list);
46+
SM02ListResponse listResponse = sm02Service.selectSM02List(nowPage, userid);
4847

4948
log.debug("exit sm02 get");
50-
return new ResponseEntity<>(sm02Entity, HttpStatus.OK);
49+
return new ResponseEntity<>(listResponse, HttpStatus.OK);
5150
}
5251

5352
@ResponseBody
5453
@RequestMapping(value = "/sm02/{seq}", method = RequestMethod.DELETE)
55-
public ResponseEntity<SM02Entity> deleteSM02Vo(@ModelAttribute SM02Entity sm02Entity, HttpServletRequest request)
56-
throws Exception {
54+
public ResponseEntity<SM02Response> deleteSM02(@PathVariable int seq, HttpServletRequest request) throws Exception {
5755
log.debug("enter sm02 delete");
5856
String userid = getSessionId(request);
5957

60-
sm02Service.deleteSM02Vo(sm02Entity, userid);
61-
62-
sm02Entity.setNowPage(1);
63-
List<SM02Entity> list = sm02Service.selectSM02Vo(sm02Entity, userid);
64-
sm02Entity.setList(list);
58+
sm02Service.deleteSM02(seq, userid);
6559

6660
log.debug("exit sm02 delete");
67-
return new ResponseEntity<>(sm02Entity, HttpStatus.OK);
61+
return new ResponseEntity<>(HttpStatus.NO_CONTENT);
6862
}
6963

7064
@ResponseBody
7165
@RequestMapping(value = "/sm02", method = RequestMethod.POST)
72-
public ResponseEntity<SM02Entity> insertSM02Vo(@RequestBody @Valid SM02Entitysm02Entity, HttpServletRequestrequest)
73-
throws Exception {
66+
public ResponseEntity<SM02Response> insertSM02(@RequestBody @Valid SM02Requestsm02Request,
67+
HttpServletRequestrequest) throws Exception {
7468
log.debug("enter sm02 post");
7569

7670
String userid = getSessionId(request);
77-
sm02Service.insertSM02Vo(sm02Entity, userid);
78-
79-
List<SM02Entity> list = sm02Service.selectSM02Vo(sm02Entity, userid);
80-
sm02Entity.setList(list);
71+
SM02Response response = sm02Service.insertSM02(sm02Request, userid);
8172

8273
log.debug("exit sm02 post");
83-
return new ResponseEntity<>(sm02Entity, HttpStatus.CREATED);
74+
return new ResponseEntity<>(response, HttpStatus.CREATED);
8475
}
8576
}
Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,5 @@
11
package com.singer.application.controller.sm;
22

3-
import java.util.List;
4-
53
import org.springframework.beans.factory.annotation.Autowired;
64

75
import org.springframework.http.HttpStatus;
@@ -13,16 +11,15 @@
1311
import org.springframework.web.bind.annotation.ResponseBody;
1412
import org.springframework.web.servlet.ModelAndView;
1513

14+
import com.singer.application.dto.sm.SMI1ListResponse;
1615
import com.singer.application.service.sm.SMI1Service;
17-
import com.singer.domain.entity.sm.SM01Entity;
1816

1917
import lombok.extern.slf4j.Slf4j;
2018

2119
@Controller
2220
@Slf4j
2321
public class SMI1Controller {
2422

25-
2623
@Autowired
2724
private SMI1Service smi1Service;
2825

@@ -35,15 +32,13 @@ public ModelAndView page() {
3532

3633
@ResponseBody
3734
@RequestMapping(value = "/smi1", method = RequestMethod.GET)
38-
public ResponseEntity<SM01Entity> selectSMI1Vo(@RequestParam(value = "searchCode") String searchCode,
35+
public ResponseEntity<SMI1ListResponse> selectSMI1(@RequestParam(value = "searchCode") String searchCode,
3936
@RequestParam(value = "searchParam") String searchParam) throws Exception {
4037
log.debug("enter smi1 get");
4138

42-
List<SM01Entity> list = smi1Service.selectSMI1Vo(searchCode, searchParam);
43-
SM01Entity sm01Entity = new SM01Entity();
44-
sm01Entity.setList(list);
39+
SMI1ListResponse listResponse = smi1Service.selectSMI1List(searchCode, searchParam);
4540

4641
log.debug("exit smi1 get");
47-
return new ResponseEntity<SM01Entity>(sm01Entity, HttpStatus.OK);
42+
return new ResponseEntity<>(listResponse, HttpStatus.OK);
4843
}
4944
}

‎src/main/java/com/singer/application/dto/sb/SB02Composer.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ public static SB02ListResponse entityListToResponse(List<SB02Entity> list, int p
4949

5050
List<SB02Response> responseList = new ArrayList<>();
5151

52-
for (SB02Entity vo : list) {
53-
responseList.add(new SB02Response(vo.getSeq(), vo.getSeq01(), vo.getUserid(), vo.getText(), vo.getGood(),
54-
vo.getReply(), vo.getRegdate(), vo.isDeleteYn()));
52+
for (SB02Entity entity : list) {
53+
responseList.add(new SB02Response(entity.getSeq(), entity.getSeq01(), entity.getUserid(), entity.getText(), entity.getGood(),
54+
entity.getReply(), entity.getRegdate(), entity.isDeleteYn()));
5555
}
5656

5757
return new SB02ListResponse(responseList, parents, nowPage, totCnt);
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
package com.singer.application.dto.sm;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import com.singer.common.util.CommonUtil;
7+
import com.singer.common.util.DateUtil;
8+
import com.singer.domain.entity.sm.SM02Entity;
9+
10+
public class SM02Composer {
11+
12+
public static SM02ListResponse entityListToResponse(List<SM02Entity> list) {
13+
List<SM02Response> responseList = new ArrayList<>();
14+
for (SM02Entity entity : list) {
15+
responseList
16+
.add(new SM02Response(entity.getTitle(), entity.getText(), entity.getRegdate(), entity.getSeq()));
17+
}
18+
int totCnt = 0;
19+
int nowPage = 0;
20+
if (list.size() != 0) {
21+
totCnt = CommonUtil.getPageCnt(list.get(0).getTotCnt());
22+
nowPage = list.get(0).getNowPage();
23+
}
24+
return new SM02ListResponse(responseList, nowPage, totCnt);
25+
}
26+
27+
public static SM02Entity requestToEntity(SM02Request request, String userid) {
28+
SM02Entity entity = new SM02Entity();
29+
entity.setTitle(request.getTitle());
30+
entity.setText(request.getText());
31+
entity.setUserid(userid);
32+
entity.setRegdate(DateUtil.getTodayTime());
33+
return entity;
34+
}
35+
36+
public static SM02Response entityToResponse(SM02Entity entity) {
37+
return new SM02Response(entity.getTitle(), entity.getText(), entity.getRegdate(), entity.getSeq());
38+
}
39+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package com.singer.application.dto.sm;
2+
3+
import java.util.List;
4+
import lombok.Value;
5+
6+
@Value
7+
public class SM02ListResponse {
8+
9+
List<SM02Response> list;
10+
11+
int nowPage;
12+
13+
int totCnt;
14+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
package com.singer.application.dto.sm;
2+
3+
import javax.validation.constraints.NotEmpty;
4+
5+
import com.singer.common.exception.ExceptionMsg;
6+
7+
import lombok.Getter;
8+
import lombok.NoArgsConstructor;
9+
import lombok.Setter;
10+
11+
@NoArgsConstructor
12+
@Setter
13+
@Getter
14+
public class SM02Request {
15+
16+
@NotEmpty(message = ExceptionMsg.EXT_MSG_INPUT_1)
17+
String title;
18+
19+
@NotEmpty(message = ExceptionMsg.EXT_MSG_INPUT_2)
20+
String text;
21+
22+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.singer.application.dto.sm;
2+
3+
import lombok.Value;
4+
5+
@Value
6+
public class SM02Response {
7+
8+
String title;
9+
10+
String text;
11+
12+
String regdate;
13+
14+
int seq;
15+
16+
}
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package com.singer.application.dto.sm;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import com.singer.domain.entity.sm.SM01Entity;
7+
8+
public class SMI1Composer {
9+
10+
public static SMI1ListResponse entityListToResponse(List<SM01Entity> list) {
11+
List<SMI1Response> responseList = new ArrayList<>();
12+
for (SM01Entity entity : list) {
13+
responseList.add(new SMI1Response(entity.getUsername(), entity.getUserid(), entity.getBrth(),
14+
entity.getRegdate(), entity.getPfnum(), entity.getPcnum(), entity.getPbnum(), entity.getEmail()));
15+
}
16+
return new SMI1ListResponse(responseList);
17+
18+
}
19+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package com.singer.application.dto.sm;
2+
3+
import java.util.List;
4+
import lombok.Value;
5+
6+
@Value
7+
public class SMI1ListResponse {
8+
9+
List<SMI1Response> list;
10+
11+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.singer.application.dto.sm;
2+
3+
import lombok.Value;
4+
5+
@Value
6+
public class SMI1Response {
7+
8+
String username;
9+
10+
String userid;
11+
12+
String brth;
13+
14+
String regdate;
15+
16+
String pfnum;
17+
18+
String pcnum;
19+
20+
String pbnum;
21+
22+
String email;
23+
}

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /