Skip to content

Commit

Permalink
Merge pull request #22 from GMD-music-recommend-app/millie
Browse files Browse the repository at this point in the history
Millie
  • Loading branch information
joeun-01 authored Dec 19, 2022
2 parents e1f9bcb + 9b3b15b commit 3674c2a
Show file tree
Hide file tree
Showing 9 changed files with 129 additions and 19 deletions.
34 changes: 28 additions & 6 deletions src/main/java/com/sesac/gmd/src/Chart/ChartController.java
Original file line number Diff line number Diff line change
@@ -1,20 +1,42 @@
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.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.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
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
@RequestMapping("/chart")
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;
}

/* 현 위치의 지역구 기준 인기차트 반환 */
@ApiOperation("지역 내 인기차트 반환")
@ResponseBody
@GetMapping("")
public BaseResponse<List<GetChartRes>> getChart(@RequestBody GetChartReq getChartReq){
try{
List<GetChartRes> getChartRes = chartProvider.getChart(getChartReq);
return new BaseResponse<>(getChartRes);

}catch(BaseException exception){
return new BaseResponse<>((exception.getStatus()));
}
}
}
38 changes: 38 additions & 0 deletions src/main/java/com/sesac/gmd/src/Chart/ChartDao.java
Original file line number Diff line number Diff line change
@@ -1,7 +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 {
private JdbcTemplate jdbcTemplate;

@Autowired
public void setDataSource(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}

/* 현 위치의 지역구 기준 인기차트 반환 */
public List<GetChartRes> 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);
}
}
27 changes: 27 additions & 0 deletions src/main/java/com/sesac/gmd/src/Chart/ChartProvider.java
Original file line number Diff line number Diff line change
@@ -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<GetChartRes> getChart(GetChartReq getChartReq) throws BaseException{
try{
return chartDao.getChart(getChartReq);
}catch(Exception exception){
throw new BaseException(DATABASE_ERROR);
}
}


}
14 changes: 14 additions & 0 deletions src/main/java/com/sesac/gmd/src/Chart/model/GetChartReq.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
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 String city;
}
11 changes: 8 additions & 3 deletions src/main/java/com/sesac/gmd/src/Chart/model/GetChartRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
2 changes: 1 addition & 1 deletion src/main/java/com/sesac/gmd/src/user/UserController.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,7 +207,7 @@ public BaseResponse<List<GetCommentRes>> getComment(@PathVariable int userIdx){
}

/* 내가 단 댓글 삭제 API */
@ApiOperation("댓글 삭제")
@ApiOperation("내가 단 댓글 삭제")
@ApiImplicitParams({
@ApiImplicitParam(name = "X-ACCESS-TOKEN", required = true, dataType = "string", paramType = "header"),
})
Expand Down
11 changes: 6 additions & 5 deletions src/main/java/com/sesac/gmd/src/user/UserDao.java
Original file line number Diff line number Diff line change
Expand Up @@ -106,20 +106,21 @@ public String deletePin(int pinIdx) {

/* 댓글 리스트 반환 API */
public List<GetCommentRes> getComment(int userIdx){
String query = "select pct.commentIdx, pct.content, pct.userIdx, pct.pinIdx, pt.songTitle, 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.songTitle, 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("songTitle"),
rs.getString("singer"),
rs.getString("artist"),
rs.getString("content"),
rs.getString("state"),
rs.getString("city"),
rs.getString("street")
rs.getString("city")
), userIdx);
}

Expand Down
7 changes: 3 additions & 4 deletions src/main/java/com/sesac/gmd/src/user/model/GetCommentRes.java
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,10 @@ public class GetCommentRes {
private int commentIdx;
private int pinIdx;
private int userIdx;
private String singer;
private String songTitle;
private String album;
private String artist;
private String title;
private String albumTitle;
private String content;
private String state;
private String city;
private String street;
}
4 changes: 4 additions & 0 deletions src/main/java/com/sesac/gmd/utils/Validation.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -85,4 +86,7 @@ public static BaseResponseStatus locationValidation(double latitude, double long

return SUCCESS;
}



}

0 comments on commit 3674c2a

Please sign in to comment.