-
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.
Browse files
Browse the repository at this point in the history
…dback(swm-392) Feat/#139/develop material user feedback(swm 392)
- Loading branch information
Showing
43 changed files
with
654 additions
and
75 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
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
47 changes: 47 additions & 0 deletions
47
src/main/java/com/m9d/sroom/common/entity/MaterialFeedbackEntity.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,47 @@ | ||
package com.m9d.sroom.common.entity; | ||
|
||
import com.m9d.sroom.material.model.MaterialType; | ||
import lombok.Builder; | ||
import lombok.Data; | ||
import org.springframework.data.annotation.Id; | ||
import org.springframework.jdbc.core.RowMapper; | ||
|
||
@Data | ||
@Builder | ||
public class MaterialFeedbackEntity { | ||
|
||
@Id | ||
private Long feedbackId; | ||
|
||
private Long memberId; | ||
|
||
private Long contentId; | ||
|
||
private int contentType; | ||
|
||
private boolean satisfactory; | ||
|
||
public static RowMapper<MaterialFeedbackEntity> getRowMapper() { | ||
return (rs, rowNum) -> MaterialFeedbackEntity.builder() | ||
.feedbackId(rs.getLong("feedback_id")) | ||
.memberId(rs.getLong("member_id")) | ||
.contentId(rs.getLong("content_id")) | ||
.contentType(rs.getInt("content_type")) | ||
.satisfactory(rs.getBoolean("rating")) | ||
.build(); | ||
} | ||
|
||
public MaterialType getContentType() { | ||
return MaterialType.from(contentType); | ||
} | ||
|
||
public static MaterialFeedbackEntity createForSave(Long memberId, MaterialType type, Long contentId, | ||
boolean satisfactory) { | ||
return MaterialFeedbackEntity.builder() | ||
.memberId(memberId) | ||
.contentType(type.getValue()) | ||
.contentId(contentId) | ||
.satisfactory(satisfactory) | ||
.build(); | ||
} | ||
} |
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
46 changes: 46 additions & 0 deletions
46
.../com/m9d/sroom/common/repository/materialfeedback/MaterialFeedbackJdbcRepositoryImpl.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,46 @@ | ||
package com.m9d.sroom.common.repository.materialfeedback; | ||
|
||
import com.m9d.sroom.common.entity.MaterialFeedbackEntity; | ||
import org.springframework.dao.EmptyResultDataAccessException; | ||
import org.springframework.jdbc.core.JdbcTemplate; | ||
import org.springframework.stereotype.Repository; | ||
|
||
import java.util.Optional; | ||
|
||
@Repository | ||
public class MaterialFeedbackJdbcRepositoryImpl implements MaterialFeedbackRepository { | ||
|
||
private final JdbcTemplate jdbcTemplate; | ||
|
||
public MaterialFeedbackJdbcRepositoryImpl(JdbcTemplate jdbcTemplate) { | ||
this.jdbcTemplate = jdbcTemplate; | ||
} | ||
|
||
@Override | ||
public MaterialFeedbackEntity save(MaterialFeedbackEntity feedbackEntity) { | ||
jdbcTemplate.update(MaterialFeedbackRepositorySql.SAVE, | ||
feedbackEntity.getMemberId(), | ||
feedbackEntity.getContentId(), | ||
feedbackEntity.getContentType().getValue(), | ||
feedbackEntity.isSatisfactory()); | ||
return getById(jdbcTemplate.queryForObject(MaterialFeedbackRepositorySql.GET_LAST_ID, Long.class)); | ||
} | ||
|
||
@Override | ||
public MaterialFeedbackEntity getById(Long id) { | ||
return jdbcTemplate.queryForObject(MaterialFeedbackRepositorySql.GET_BY_ID, | ||
MaterialFeedbackEntity.getRowMapper(), id); | ||
} | ||
|
||
@Override | ||
public Optional<MaterialFeedbackEntity> findByMemberIdAndTypeAndMaterialId(Long memberId, int materialType, | ||
Long materialId) { | ||
try { | ||
return Optional.ofNullable(jdbcTemplate.queryForObject( | ||
MaterialFeedbackRepositorySql.GET_BY_MEMBER_ID_AND_TYPE_AND_MATERIAL_ID, | ||
MaterialFeedbackEntity.getRowMapper(), memberId, materialType, materialId)); | ||
} catch (EmptyResultDataAccessException e) { | ||
return Optional.empty(); | ||
} | ||
} | ||
} |
15 changes: 15 additions & 0 deletions
15
...ain/java/com/m9d/sroom/common/repository/materialfeedback/MaterialFeedbackRepository.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,15 @@ | ||
package com.m9d.sroom.common.repository.materialfeedback; | ||
|
||
import com.m9d.sroom.common.entity.MaterialFeedbackEntity; | ||
|
||
import java.util.Optional; | ||
|
||
public interface MaterialFeedbackRepository { | ||
|
||
MaterialFeedbackEntity save(MaterialFeedbackEntity feedbackEntity); | ||
|
||
MaterialFeedbackEntity getById(Long id); | ||
|
||
Optional<MaterialFeedbackEntity> findByMemberIdAndTypeAndMaterialId(Long memberId, int materialType, | ||
Long materialId); | ||
} |
37 changes: 37 additions & 0 deletions
37
...ava/com/m9d/sroom/common/repository/materialfeedback/MaterialFeedbackRepositorySql.groovy
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,37 @@ | ||
package com.m9d.sroom.common.repository.materialfeedback | ||
|
||
class MaterialFeedbackRepositorySql { | ||
|
||
public static final String GET_LAST_ID = """ | ||
SELECT LAST_INSERT_ID() | ||
""" | ||
|
||
public static final String GET_BY_ID = """ | ||
SELECT | ||
feedback_id, member_id, content_id, content_type, rating | ||
FROM MATERIAL_FEEDBACK | ||
WHERE feedback_id = ? | ||
""" | ||
|
||
public static final String SAVE = """ | ||
INSERT | ||
INTO MATERIAL_FEEDBACK (member_id, content_id, content_type, rating) | ||
VALUES (?, ?, ?, ?) | ||
""" | ||
|
||
public static final String GET_BY_MEMBER_ID = """ | ||
SELECT | ||
feedback_id, member_id, content_id, content_type, rating | ||
FROM MATERIAL_FEEDBACK | ||
WHERE member_id = ? | ||
""" | ||
|
||
public static final String GET_BY_MEMBER_ID_AND_TYPE_AND_MATERIAL_ID = """ | ||
SELECT | ||
feedback_id, member_id, content_id, content_type, rating | ||
FROM MATERIAL_FEEDBACK | ||
WHERE member_id = ? | ||
AND content_type = ? | ||
AND content_id = ? | ||
""" | ||
} |
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
Oops, something went wrong.