Skip to content

Commit

Permalink
feat: 내 근처 재치 조회 관련 SQL문 수정 #19
Browse files Browse the repository at this point in the history
  • Loading branch information
plum-king committed Apr 2, 2023
1 parent fda1f40 commit 922bdbe
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 6 deletions.
3 changes: 3 additions & 0 deletions src/main/java/com/zatch/zatchserver/domain/ViewNearZatch.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package com.zatch.zatchserver.domain;

import lombok.Getter;

import java.util.Date;

@Getter
public class ViewNearZatch {
private Long categoryId;
private Boolean isFree;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,17 @@
import java.util.List;

@Repository
public class MainRepositoryImpl implements MainRepository{
public class MainRepositoryImpl implements MainRepository {
private final JdbcTemplate jdbcTemplate;

public MainRepositoryImpl(DataSource dataSource) {this.jdbcTemplate = new JdbcTemplate(dataSource);}
public MainRepositoryImpl(DataSource dataSource) {
this.jdbcTemplate = new JdbcTemplate(dataSource);
}

@Override
public List<ViewNearZatch> getNearZatch(Long userId){
public List<ViewNearZatch> getNearZatch(Long userId) {
List<ViewNearZatch> results = jdbcTemplate.query(
"SELECT user.user_id, zatch.zatch_id, zatch.category_id, zatch.is_free, zatch.item_name, zatch.content, quantity, purchase_date, expiration_date, is_opened, allow_any_zatch, zatch.like_count, user.town1, user.town2, user.town3, zatch_img.zatch_img_url FROM zatch join zatch_img on zatch.zatch_id = zacth_img.zatch_id join user on zatch.user_id = user.user_id where (town1 = (select town1, town2, town3 from user where user.user_id = ?)) or (town2 = (select town1, town2, town3 from user where user.user_id = ?)) or (town3 = (select town1, town2, town3 from user where user.user_id = ?))",
"SELECT user.user_id, zatch.zatch_id, zatch.category_id, zatch.is_free, zatch.item_name, zatch.content, zatch.updated_at, quantity, purchase_date, expiration_date, is_opened, allow_any_zatch, zatch.like_count, user.town1, user.town2, user.town3, zatch_img.zatch_img_url FROM zatch LEFT OUTER JOIN zatch_img ON zatch.zatch_id = zatch_img.zatch_id JOIN user ON zatch.user_id = user.user_id WHERE ((town1 IN (SELECT town1 or town2 or town3 FROM user)) or (town2 IN (SELECT town1 or town2 or town3 FROM user)) or (town3 IN (SELECT town1 or town2 or town3 FROM user))) and user.user_id != ?",
new RowMapper<ViewNearZatch>() {
@Override
public ViewNearZatch mapRow(ResultSet rs, int rowNum) throws SQLException {
Expand All @@ -39,10 +41,10 @@ public ViewNearZatch mapRow(ResultSet rs, int rowNum) throws SQLException {
rs.getString("town1"),
rs.getString("town2"),
rs.getString("town3")
);
);
return nearZatch;
}
}, userId, userId, userId);
}, userId);
return results.isEmpty() ? null : results;
}
}

0 comments on commit 922bdbe

Please sign in to comment.