diff --git a/src/main/java/com/zatch/zatchserver/domain/ViewNearZatch.java b/src/main/java/com/zatch/zatchserver/domain/ViewNearZatch.java index eab6e82..9f6fb82 100644 --- a/src/main/java/com/zatch/zatchserver/domain/ViewNearZatch.java +++ b/src/main/java/com/zatch/zatchserver/domain/ViewNearZatch.java @@ -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; diff --git a/src/main/java/com/zatch/zatchserver/repository/MainRepositoryImpl.java b/src/main/java/com/zatch/zatchserver/repository/MainRepositoryImpl.java index 6bcfdd3..6fd2379 100644 --- a/src/main/java/com/zatch/zatchserver/repository/MainRepositoryImpl.java +++ b/src/main/java/com/zatch/zatchserver/repository/MainRepositoryImpl.java @@ -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 getNearZatch(Long userId){ + public List getNearZatch(Long userId) { List 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() { @Override public ViewNearZatch mapRow(ResultSet rs, int rowNum) throws SQLException { @@ -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; } }