-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
88 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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<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); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
} | ||
} | ||
|
||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters