-
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.
Merge pull request #22 from GMD-music-recommend-app/millie
Millie
- Loading branch information
Showing
9 changed files
with
129 additions
and
19 deletions.
There are no files selected for viewing
34 changes: 28 additions & 6 deletions
34
src/main/java/com/sesac/gmd/src/Chart/ChartController.java
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,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())); | ||
} | ||
} | ||
} |
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,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); | ||
} | ||
} |
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); | ||
} | ||
} | ||
|
||
|
||
} |
14 changes: 14 additions & 0 deletions
14
src/main/java/com/sesac/gmd/src/Chart/model/GetChartReq.java
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 |
---|---|---|
@@ -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; | ||
} |
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
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
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