From 00d4582e958c16414ee9069039b3d993556c09c8 Mon Sep 17 00:00:00 2001 From: "hewon130@gmail.com" Date: Fri, 16 Dec 2022 15:24:15 +0900 Subject: [PATCH 1/2] =?UTF-8?q?modify:=20[=EA=B3=B5=EA=B0=90=ED=95=98?= =?UTF-8?q?=EA=B8=B0]=20=EA=B3=B5=EA=B0=90=ED=95=98=EA=B8=B0=20url=20?= =?UTF-8?q?=EC=88=98=EC=A0=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sesac/gmd/src/Chart/ChartController.java | 24 +++++++++++++++++-- .../com/sesac/gmd/src/Chart/ChartDao.java | 1 + .../gmd/src/Chart/model/GetChartReq.java | 15 ++++++++++++ .../sesac/gmd/src/song/SongController.java | 2 +- .../sesac/gmd/src/user/UserController.java | 1 + .../java/com/sesac/gmd/src/user/UserDao.java | 11 +++++---- .../gmd/src/user/model/GetCommentRes.java | 5 ++-- .../java/com/sesac/gmd/utils/Validation.java | 4 ++++ 8 files changed, 52 insertions(+), 11 deletions(-) create mode 100644 src/main/java/com/sesac/gmd/src/Chart/model/GetChartReq.java diff --git a/src/main/java/com/sesac/gmd/src/Chart/ChartController.java b/src/main/java/com/sesac/gmd/src/Chart/ChartController.java index 1814ca2..05639bb 100644 --- a/src/main/java/com/sesac/gmd/src/Chart/ChartController.java +++ b/src/main/java/com/sesac/gmd/src/Chart/ChartController.java @@ -1,9 +1,17 @@ package com.sesac.gmd.src.Chart; +import com.sesac.gmd.config.BaseException; +import com.sesac.gmd.config.BaseResponse; +import com.sesac.gmd.config.BaseResponseStatus; +import com.sesac.gmd.src.Chart.model.GetChartReq; +import com.sesac.gmd.src.Chart.model.GetChartRes; import com.sesac.gmd.utils.JwtService; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.web.bind.annotation.RequestMapping; -import org.springframework.web.bind.annotation.RestController; +import org.springframework.web.bind.annotation.*; + +import java.util.List; + +import static com.sesac.gmd.utils.Validation.locationValidation; @RestController @RequestMapping("/chart") @@ -17,4 +25,16 @@ public ChartController(ChartProvider chartProvider, JwtService jwtService){ this.chartProvider = chartProvider; this.jwtService = jwtService; } + + //@ResponseBody + //@GetMapping("") + /* public BaseResponse> getChart(@RequestParam double latitude, @RequestParam double longitude, GetChartReq getChartReq){ + try{ + BaseResponseStatus status = locationValidation(latitude, longitude); + getChartReq = new GetChartReq(latitude, longitude); + + } catch(BaseException exception){ + return new BaseResponse<>(exception.getStatus()); + } + } */ } diff --git a/src/main/java/com/sesac/gmd/src/Chart/ChartDao.java b/src/main/java/com/sesac/gmd/src/Chart/ChartDao.java index 2b6ea56..56b168f 100644 --- a/src/main/java/com/sesac/gmd/src/Chart/ChartDao.java +++ b/src/main/java/com/sesac/gmd/src/Chart/ChartDao.java @@ -4,4 +4,5 @@ @Repository public class ChartDao { + String query = "select pinIdx, count(pinIdx) as 'count_like' from pin_like_tbl group by pinIdx order by count_like desc"; } diff --git a/src/main/java/com/sesac/gmd/src/Chart/model/GetChartReq.java b/src/main/java/com/sesac/gmd/src/Chart/model/GetChartReq.java new file mode 100644 index 0000000..0091d85 --- /dev/null +++ b/src/main/java/com/sesac/gmd/src/Chart/model/GetChartReq.java @@ -0,0 +1,15 @@ +package com.sesac.gmd.src.Chart.model; + +import lombok.AllArgsConstructor; +import lombok.Getter; +import lombok.NoArgsConstructor; +import lombok.Setter; + +@Getter +@Setter +@AllArgsConstructor +@NoArgsConstructor +public class GetChartReq { + private double latitude; + private double longitude; +} diff --git a/src/main/java/com/sesac/gmd/src/song/SongController.java b/src/main/java/com/sesac/gmd/src/song/SongController.java index c0bb433..7f9e4b3 100644 --- a/src/main/java/com/sesac/gmd/src/song/SongController.java +++ b/src/main/java/com/sesac/gmd/src/song/SongController.java @@ -125,7 +125,7 @@ public BaseResponse> getPins(@RequestParam int radius, @Request @ApiImplicitParam(name = "X-ACCESS-TOKEN", required = true, dataType = "string", paramType = "header"), }) @ResponseBody - @PostMapping("/liking/{userIdx}/{pinIdx}") + @PostMapping("/like/{userIdx}/{pinIdx}") public BaseResponse likeSong(PostLikeReq postLikeReq, @PathVariable int userIdx, @PathVariable int pinIdx){ try{ int userIdxJwt = jwtService.getUserIdx(); diff --git a/src/main/java/com/sesac/gmd/src/user/UserController.java b/src/main/java/com/sesac/gmd/src/user/UserController.java index bf645c9..096d36a 100644 --- a/src/main/java/com/sesac/gmd/src/user/UserController.java +++ b/src/main/java/com/sesac/gmd/src/user/UserController.java @@ -161,6 +161,7 @@ public BaseResponse> getComment(@PathVariable int userIdx){ } /* 내가 단 댓글 삭제 API */ + @ApiOperation("내가 단 댓글 삭제") @ApiImplicitParams({ @ApiImplicitParam(name = "X-ACCESS-TOKEN", required = true, dataType = "string", paramType = "header"), }) diff --git a/src/main/java/com/sesac/gmd/src/user/UserDao.java b/src/main/java/com/sesac/gmd/src/user/UserDao.java index 3588333..a4b752e 100644 --- a/src/main/java/com/sesac/gmd/src/user/UserDao.java +++ b/src/main/java/com/sesac/gmd/src/user/UserDao.java @@ -70,20 +70,21 @@ public String patchLocation(PatchLocationReq patchLocationReq, int userIdx) { /* 댓글 리스트 반환 API */ public List getComment(int userIdx){ - String query = "select pct.commentIdx, pct.content, pct.userIdx, pct.pinIdx, pt.title, pt.singer, pt.album, pt.state, pt.city, pt.street from pin_comment_tbl as pct left join pin_tbl as pt on pct.userIdx = pt.userIdx where pct.userIdx = ?"; + String query = "select pct.commentIdx, pct.content, pct.userIdx, pct.pinIdx, pt.title, pt.artist, pt.albumTitle, pt.state, pt.city\n" + + "from pin_comment_tbl as pct left join pin_tbl as pt on pct.userIdx = pt.userIdx\n"+ + "where pct.userIdx = ? GROUP BY pt.title;"; return this.jdbcTemplate.query(query, (rs, rowNum) -> new GetCommentRes( rs.getInt("commentIdx"), rs.getInt("pinIdx"), rs.getInt("userIdx"), - rs.getString("album"), + rs.getString("albumTitle"), rs.getString("title"), - rs.getString("singer"), + rs.getString("artist"), rs.getString("content"), rs.getString("state"), - rs.getString("city"), - rs.getString("street") + rs.getString("city") ), userIdx); } diff --git a/src/main/java/com/sesac/gmd/src/user/model/GetCommentRes.java b/src/main/java/com/sesac/gmd/src/user/model/GetCommentRes.java index 718884d..b49bc23 100644 --- a/src/main/java/com/sesac/gmd/src/user/model/GetCommentRes.java +++ b/src/main/java/com/sesac/gmd/src/user/model/GetCommentRes.java @@ -15,13 +15,12 @@ public class GetCommentRes { private int commentIdx; private int pinIdx; private int userIdx; - private String singer; + private String artist; private String title; - private String album; + private String albumTitle; private String content; private String state; private String city; - private String street; } diff --git a/src/main/java/com/sesac/gmd/utils/Validation.java b/src/main/java/com/sesac/gmd/utils/Validation.java index b09e52f..8e00915 100644 --- a/src/main/java/com/sesac/gmd/utils/Validation.java +++ b/src/main/java/com/sesac/gmd/utils/Validation.java @@ -2,6 +2,7 @@ import com.sesac.gmd.config.BaseResponseStatus; import com.sesac.gmd.src.song.model.PostPinReq; +import com.sesac.gmd.src.user.model.GetCommentReq; import com.sesac.gmd.src.user.model.PostUserReq; import java.util.Objects; @@ -85,4 +86,7 @@ public static BaseResponseStatus locationValidation(double latitude, double long return SUCCESS; } + + + } From 7f66cabed4b5c856af571ecccecab8d9b9283213 Mon Sep 17 00:00:00 2001 From: "hewon130@gmail.com" Date: Mon, 19 Dec 2022 20:23:38 +0900 Subject: [PATCH 2/2] =?UTF-8?q?add:=20[=EC=9D=B8=EA=B8=B0=EC=B0=A8?= =?UTF-8?q?=ED=8A=B8]=20=EC=A7=80=EC=97=AD=EA=B5=AC=20=EB=82=B4=20?= =?UTF-8?q?=EC=9D=B8=EA=B8=B0=EC=B0=A8=ED=8A=B8=20=EB=B0=98=ED=99=98=20API?= =?UTF-8?q?=20=EC=B6=94=EA=B0=80?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../sesac/gmd/src/Chart/ChartController.java | 26 +++++++------ .../com/sesac/gmd/src/Chart/ChartDao.java | 39 ++++++++++++++++++- .../sesac/gmd/src/Chart/ChartProvider.java | 27 +++++++++++++ .../gmd/src/Chart/model/GetChartReq.java | 3 +- .../gmd/src/Chart/model/GetChartRes.java | 11 ++++-- 5 files changed, 88 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/sesac/gmd/src/Chart/ChartController.java b/src/main/java/com/sesac/gmd/src/Chart/ChartController.java index 05639bb..e6fe9b6 100644 --- a/src/main/java/com/sesac/gmd/src/Chart/ChartController.java +++ b/src/main/java/com/sesac/gmd/src/Chart/ChartController.java @@ -5,12 +5,15 @@ import com.sesac.gmd.config.BaseResponseStatus; import com.sesac.gmd.src.Chart.model.GetChartReq; import com.sesac.gmd.src.Chart.model.GetChartRes; +import com.sesac.gmd.src.song.model.GetPinsRes; import com.sesac.gmd.utils.JwtService; +import io.swagger.annotations.ApiOperation; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.web.bind.annotation.*; import java.util.List; +import static com.sesac.gmd.config.BaseResponseStatus.SUCCESS; import static com.sesac.gmd.utils.Validation.locationValidation; @RestController @@ -18,23 +21,22 @@ public class ChartController { @Autowired private ChartProvider chartProvider; - @Autowired - private JwtService jwtService; - public ChartController(ChartProvider chartProvider, JwtService jwtService){ + public ChartController(ChartProvider chartProvider){ this.chartProvider = chartProvider; - this.jwtService = jwtService; } - //@ResponseBody - //@GetMapping("") - /* public BaseResponse> getChart(@RequestParam double latitude, @RequestParam double longitude, GetChartReq getChartReq){ + /* 현 위치의 지역구 기준 인기차트 반환 */ + @ApiOperation("지역 내 인기차트 반환") + @ResponseBody + @GetMapping("") + public BaseResponse> getChart(@RequestBody GetChartReq getChartReq){ try{ - BaseResponseStatus status = locationValidation(latitude, longitude); - getChartReq = new GetChartReq(latitude, longitude); + List getChartRes = chartProvider.getChart(getChartReq); + return new BaseResponse<>(getChartRes); - } catch(BaseException exception){ - return new BaseResponse<>(exception.getStatus()); + }catch(BaseException exception){ + return new BaseResponse<>((exception.getStatus())); } - } */ + } } diff --git a/src/main/java/com/sesac/gmd/src/Chart/ChartDao.java b/src/main/java/com/sesac/gmd/src/Chart/ChartDao.java index 56b168f..c5c1517 100644 --- a/src/main/java/com/sesac/gmd/src/Chart/ChartDao.java +++ b/src/main/java/com/sesac/gmd/src/Chart/ChartDao.java @@ -1,8 +1,45 @@ package com.sesac.gmd.src.Chart; +import com.sesac.gmd.src.Chart.model.GetChartReq; +import com.sesac.gmd.src.Chart.model.GetChartRes; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.jdbc.core.JdbcTemplate; import org.springframework.stereotype.Repository; +import javax.sql.DataSource; +import java.util.List; + @Repository public class ChartDao { - String query = "select pinIdx, count(pinIdx) as 'count_like' from pin_like_tbl group by pinIdx order by count_like desc"; + private JdbcTemplate jdbcTemplate; + + @Autowired + public void setDataSource(DataSource dataSource) { + this.jdbcTemplate = new JdbcTemplate(dataSource); + } + + /* 현 위치의 지역구 기준 인기차트 반환 */ + public List getChart(GetChartReq getChartReq){ + String query = "select sct.pinIdx, sct.likeCount, pt.city, pt.state, pt.albumImage, pt.songTitle, pt.artist, rank() over (order by likeCount desc) as songRank\n" + + "from (select pinIdx, count(pinIdx) as 'likeCount' from pin_like_tbl as plt group by pinIdx order by likeCount desc) as sct\n" + + "right join pin_tbl as pt on sct.pinIdx = pt.pinIdx\n" + + "where pt.city = ? and likeCount is not null\n" + + "order by likeCount desc;"; + + Object[] params = new Object[]{ + getChartReq.getCity() + }; + + return this.jdbcTemplate.query(query, + (rs, rowNum) -> new GetChartRes( + rs.getInt("pinIdx"), + rs.getInt("likeCount"), + rs.getString("city"), + rs.getString("state"), + rs.getString("albumImage"), + rs.getString("songTitle"), + rs.getString("artist"), + rs.getInt("songRank") + ), params); + } } diff --git a/src/main/java/com/sesac/gmd/src/Chart/ChartProvider.java b/src/main/java/com/sesac/gmd/src/Chart/ChartProvider.java index 77fa12d..08d4fb1 100644 --- a/src/main/java/com/sesac/gmd/src/Chart/ChartProvider.java +++ b/src/main/java/com/sesac/gmd/src/Chart/ChartProvider.java @@ -1,7 +1,34 @@ package com.sesac.gmd.src.Chart; +import com.sesac.gmd.config.BaseException; +import com.sesac.gmd.config.BaseResponse; +import com.sesac.gmd.config.BaseResponseStatus; +import com.sesac.gmd.src.Chart.model.GetChartReq; +import com.sesac.gmd.src.Chart.model.GetChartRes; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.stereotype.Service; +import java.util.List; + +import static com.sesac.gmd.config.BaseResponseStatus.DATABASE_ERROR; + @Service public class ChartProvider { + @Autowired + private ChartDao chartDao; + + public ChartProvider(ChartDao chartDao){ + this.chartDao = chartDao; + } + + /* 현 위치의 지역구 기준 인기차트 반환 */ + public List getChart(GetChartReq getChartReq) throws BaseException{ + try{ + return chartDao.getChart(getChartReq); + }catch(Exception exception){ + throw new BaseException(DATABASE_ERROR); + } + } + + } diff --git a/src/main/java/com/sesac/gmd/src/Chart/model/GetChartReq.java b/src/main/java/com/sesac/gmd/src/Chart/model/GetChartReq.java index 0091d85..7a1d8ff 100644 --- a/src/main/java/com/sesac/gmd/src/Chart/model/GetChartReq.java +++ b/src/main/java/com/sesac/gmd/src/Chart/model/GetChartReq.java @@ -10,6 +10,5 @@ @AllArgsConstructor @NoArgsConstructor public class GetChartReq { - private double latitude; - private double longitude; + private String city; } diff --git a/src/main/java/com/sesac/gmd/src/Chart/model/GetChartRes.java b/src/main/java/com/sesac/gmd/src/Chart/model/GetChartRes.java index dbc8b5f..2230d05 100644 --- a/src/main/java/com/sesac/gmd/src/Chart/model/GetChartRes.java +++ b/src/main/java/com/sesac/gmd/src/Chart/model/GetChartRes.java @@ -10,8 +10,13 @@ @AllArgsConstructor @NoArgsConstructor public class GetChartRes { + //핀 인덱스, 순위, 앨범 커버, 제목, 가수, 공감 수 private int pinIdx; - private String albumCover; - private String title; - private String singer; + private int songRank; + private String albumImage; + private String songTitle; + private String artist; + private String city; + private String state; + private int likeCount; }