Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ repositories {
}

dependencies {
// MONGO
implementation 'org.springframework.boot:spring-boot-starter-data-mongodb'

//Hypersistence Utils
implementation 'io.hypersistence:hypersistence-utils-hibernate-63:3.7.3'

// REDIS
implementation 'org.springframework.boot:spring-boot-starter-data-redis'
Expand Down
43 changes: 21 additions & 22 deletions docker-compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,12 @@ services:
env_file:
- .env
depends_on:
mongodb:
condition: service_started
postgresql:
condition: service_started
redis:
condition: service_started
elasticsearch:
condition: service_started
environment:
- POSTGRES_DB=${POSTGRES_DB}
- POSTGRES_USER=${POSTGRES_USER}
Expand All @@ -24,10 +24,9 @@ services:

- SPRING_JPA_DDL_AUTO=${SPRING_JPA_DDL_AUTO}

# MongoDB 설정
- MONGO_DB_URI=${MONGO_DB_URI}

- ELASTICSEARCH_URL=${ELASTICSEARCH_URL}
- ELASTIC_USERNAME=${ELASTIC_USERNAME}
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}

- REDIS_URL=${REDIS_URL}

Expand All @@ -41,21 +40,6 @@ services:
networks:
- remedy-network

mongodb:
image: mongo:8.0
container_name: mongodb
ports:
- "27017:27017"
command: [--auth]
volumes:
- mongodb_data:/data/db
environment:
- MONGO_INITDB_ROOT_USERNAME=${MONGO_USER}
- MONGO_INITDB_ROOT_PASSWORD=${MONGO_PASSWORD}
- MONGO_INITDB_DATABASE=${MONGO_DB}
networks:
- remedy-network

postgresql:
image: postgres:17
container_name: postgresql
Expand All @@ -78,14 +62,29 @@ services:
networks:
- remedy-network

elasticsearch:
image: docker.elastic.co/elasticsearch/elasticsearch:8.11.0
container_name: elasticsearch
environment:
- discovery.type=single-node
- xpack.security.enabled=true
- ELASTIC_PASSWORD=${ELASTIC_PASSWORD}
ports:
- "9200:9200"
- "9300:9300"
volumes:
- elasticsearch_data:/usr/share/elasticsearch/data
networks:
- remedy-network

networks:
remedy-network:
driver: bridge

volumes:
mongodb_data:
driver: local
postgresql_data:
driver: local
redis_data:
driver: local
elasticsearch_data:
driver: local
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ public class CommentService {
@Transactional
public void createComment(String content, User user, String droppingId) {

Dropping dropping = droppingRepository.findById(droppingId)
Long droppingIdValue = parseDroppingId(droppingId);
Dropping dropping = droppingRepository.findById(droppingIdValue)
.orElseThrow(() -> DroppingNotFoundException.EXCEPTION);

Comment comment = CommentMapper.toEntity(content, user, droppingId);
Expand Down Expand Up @@ -63,7 +64,8 @@ public List<CommentResponse> getCommentsByDropping(String droppingId) {

List<Comment> comments = commentRepository.findAllByDroppingIdDesc(droppingId);

if (comments.isEmpty() && !droppingRepository.existsById(droppingId)) {
Long droppingIdValue = parseDroppingId(droppingId);
if (comments.isEmpty() && !droppingRepository.existsById(droppingIdValue)) {
throw DroppingNotFoundException.EXCEPTION;
}

Expand Down Expand Up @@ -105,10 +107,19 @@ private void validateCommentOwnership(Long userId, Comment comment) {
@Transactional(readOnly = true)
public long countByDroppingId(String droppingId) {

if (!droppingRepository.existsById(droppingId)) {
Long droppingIdValue = parseDroppingId(droppingId);
if (!droppingRepository.existsById(droppingIdValue)) {
throw DroppingNotFoundException.EXCEPTION;
}

return commentRepository.countByDroppingId(droppingId);
}

private Long parseDroppingId(String droppingId) {
try {
return Long.valueOf(droppingId);
} catch (NumberFormatException ex) {
throw DroppingNotFoundException.EXCEPTION;
}
}
Comment on lines +118 to +124
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟡 Minor

null/blank droppingId 처리 누락으로 NPE 가능 (Line 118-123).

Long.valueOf(null)NullPointerException을 발생시키므로, 현재 예외 매핑이 동작하지 않습니다. null/blank를 먼저 차단하는 것이 안전합니다.

🛠️ 수정 제안
 private Long parseDroppingId(String droppingId) {
+    if (droppingId == null || droppingId.isBlank()) {
+        throw DroppingNotFoundException.EXCEPTION;
+    }
     try {
         return Long.valueOf(droppingId);
     } catch (NumberFormatException ex) {
         throw DroppingNotFoundException.EXCEPTION;
     }
 }
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
private Long parseDroppingId(String droppingId) {
try {
return Long.valueOf(droppingId);
} catch (NumberFormatException ex) {
throw DroppingNotFoundException.EXCEPTION;
}
}
private Long parseDroppingId(String droppingId) {
if (droppingId == null || droppingId.isBlank()) {
throw DroppingNotFoundException.EXCEPTION;
}
try {
return Long.valueOf(droppingId);
} catch (NumberFormatException ex) {
throw DroppingNotFoundException.EXCEPTION;
}
}
🤖 Prompt for AI Agents
In
`@src/main/java/org/example/remedy/domain/comment/application/service/CommentService.java`
around lines 118 - 124, parseDroppingId currently calls Long.valueOf(droppingId)
which throws NPE for null and bypasses the NumberFormatException mapping; update
parseDroppingId to first check for null or blank (e.g., droppingId == null ||
droppingId.trim().isEmpty()) and throw DroppingNotFoundException.EXCEPTION for
those cases, and keep the existing try/catch for NumberFormatException to also
throw DroppingNotFoundException.EXCEPTION.

}
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ public record DroppingCreateRequest(
List<String> options,

//PLAYLIST
String playlistId,
Long playlistId,

String playlistName,
List<String> songIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

public interface DroppingResponse {
DroppingType type();
String droppingId();
Long droppingId();
Long userId();
Double latitude();
Double longitude();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import java.time.LocalDateTime;

public record MusicDroppingResponse(
String droppingId,
Long droppingId,
String songId,
Long userId,
String username,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@

public record MusicDroppingSearchResponse(
DroppingType type,
String droppingId,
Long droppingId,
Long userId,
String songId,
String title,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.List;

public record PlaylistDroppingResponse(
String droppingId,
Long droppingId,
Long userId,
String playlistName,
List<SongInfo> songs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public record PlaylistDroppingSearchResponse(
DroppingType type,
String droppingId,
Long droppingId,
Long userId,
String playlistName,
List<String> songIds,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import java.util.List;

public record VoteDroppingResponse(
String droppingId,
Long droppingId,
Long userId,
String topic,
List<VoteOptionInfo> options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

public record VoteDroppingSearchResponse(
DroppingType type,
String droppingId,
Long droppingId,
Long userId,
String topic,
List<String> options,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ public static DroppingSearchListResponse toDroppingSearchListResponse(
public static MusicDroppingResponse toMusicDroppingResponse(
Dropping dropping, String songId, String username, String albumImageUrl) {
return new MusicDroppingResponse(
dropping.getDroppingId(),
dropping.getId(),
songId,
dropping.getUserId(),
username,
Expand All @@ -42,7 +42,7 @@ public static MusicDroppingSearchResponse toMusicDroppingSearchResponse(

return new MusicDroppingSearchResponse(
DroppingType.MUSIC,
dropping.getDroppingId(),
dropping.getId(),
dropping.getUserId(),
payload.getSongId(),
song.getTitle(),
Expand All @@ -61,7 +61,7 @@ public static VoteDroppingSearchResponse toVoteDroppingSearchResponse(Dropping d

return new VoteDroppingSearchResponse(
DroppingType.VOTE,
dropping.getDroppingId(),
dropping.getId(),
dropping.getUserId(),
payload.getTopic(),
List.copyOf(payload.getOptionVotes().keySet()),
Expand All @@ -78,7 +78,7 @@ public static PlaylistDroppingSearchResponse toPlaylistDroppingSearchResponse(Dr

return new PlaylistDroppingSearchResponse(
DroppingType.PLAYLIST,
dropping.getDroppingId(),
dropping.getId(),
dropping.getUserId(),
payload.getPlaylistName(),
payload.getSongIds(),
Expand Down Expand Up @@ -119,7 +119,7 @@ public static VoteDroppingResponse toVoteDroppingResponse(
VoteCalculator.calculate(payload, currentUserId, songFinder);

return new VoteDroppingResponse(
dropping.getDroppingId(),
dropping.getId(),
dropping.getUserId(),
payload.getTopic(),
calc.options(),
Expand Down Expand Up @@ -172,7 +172,7 @@ public static PlaylistDroppingResponse toPlaylistDroppingResponse(
.toList();

return new PlaylistDroppingResponse(
dropping.getDroppingId(),
dropping.getId(),
dropping.getUserId(),
payload.getPlaylistName(),
songs,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public DroppingSearchListResponse searchDroppings(Long userId, double longitude,
return DroppingMapper.toDroppingSearchListResponse(droppings);
}

public Dropping getDroppingEntity(String droppingId) {
public Dropping getDroppingEntity(Long droppingId) {
return droppingRepository.findById(droppingId)
.orElseThrow(() -> DroppingNotFoundException.EXCEPTION);
}
Expand All @@ -63,7 +63,7 @@ private DroppingResponse convertToResponse(Dropping dropping, Long userId) {
}

@Transactional
public void deleteDropping(String droppingId, Long userId) {
public void deleteDropping(Long droppingId, Long userId) {
Dropping dropping = getDroppingEntity(droppingId);

if (!dropping.getUserId().equals(userId)) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public DroppingSearchListResponse searchDroppings(Long userId, double longitude,
return droppingQueryService.searchDroppings(userId, longitude, latitude, distance);
}

public Object getDropping(String droppingId, Long userId) {
public Object getDropping(Long droppingId, Long userId) {
Dropping dropping = droppingQueryService.getDroppingEntity(droppingId);

return switch (dropping.getDroppingType()) {
Expand All @@ -44,19 +44,19 @@ public DroppingSearchListResponse getUserDroppings(Long userId) {
return droppingQueryService.getUserDroppings(userId);
}

public void deleteDropping(String droppingId, Long userId) {
public void deleteDropping(Long droppingId, Long userId) {
droppingQueryService.deleteDropping(droppingId, userId);
}

public void cleanupExpiredDroppings() {
droppingQueryService.cleanupExpiredDroppings();
}

public void vote(String droppingId, Long userId, String songId) {
public void vote(Long droppingId, Long userId, String songId) {
voteDroppingService.vote(droppingId, userId, songId);
}

public void cancelVote(String droppingId, Long userId) {
public void cancelVote(Long droppingId, Long userId) {
voteDroppingService.cancelVote(droppingId, userId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void createDropping(AuthDetails authDetails, DroppingCreateRequest reques
publishDroppingCreatedEvent(authDetails.getUserId(), payload.getSongId());
}

public MusicDroppingResponse getMusicDropping(String droppingId) {
public MusicDroppingResponse getMusicDropping(Long droppingId) {
Dropping dropping = droppingRepository.findById(droppingId)
.orElseThrow(() -> DroppingNotFoundException.EXCEPTION);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public class PlaylistDroppingService {
public void createPlaylistDropping(AuthDetails authDetails, DroppingCreateRequest request) {
PlaylistDroppingPayload payload;

if (request.playlistId() != null && !request.playlistId().isBlank()) {
if (request.playlistId() != null) {

Playlist playlist = playlistRepository.findById(request.playlistId())
.orElseThrow(() -> PlaylistNotFoundException.EXCEPTION);
Expand All @@ -54,7 +54,7 @@ public void createPlaylistDropping(AuthDetails authDetails, DroppingCreateReques
droppingRepository.createDropping(dropping);
}

public PlaylistDroppingResponse getPlaylistDropping(String droppingId) {
public PlaylistDroppingResponse getPlaylistDropping(Long droppingId) {
Dropping dropping = droppingRepository.findById(droppingId)
.orElseThrow(() -> DroppingNotFoundException.EXCEPTION);
return DroppingMapper.toPlaylistDroppingResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,22 +33,22 @@ public void createVoteDropping(AuthDetails authDetails, DroppingCreateRequest re
}

@Transactional
public void vote(String droppingId, Long userId, String songId) {
public void vote(Long droppingId, Long userId, String songId) {
Dropping dropping = droppingRepository.findById(droppingId)
.orElseThrow(() -> DroppingNotFoundException.EXCEPTION);
dropping.vote(userId, songId);
droppingRepository.save(dropping);
}

@Transactional
public void cancelVote(String droppingId, Long userId) {
public void cancelVote(Long droppingId, Long userId) {
Dropping dropping = droppingRepository.findById(droppingId)
.orElseThrow(() -> DroppingNotFoundException.EXCEPTION);
dropping.cancelVote(userId);
droppingRepository.save(dropping);
}

public VoteDroppingResponse getVoteDropping(String droppingId, Long userId) {
public VoteDroppingResponse getVoteDropping(Long droppingId, Long userId) {
Dropping dropping = droppingRepository.findById(droppingId)
.orElseThrow(() -> DroppingNotFoundException.EXCEPTION);
return DroppingMapper.toVoteDroppingResponse(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,7 @@ private boolean validatePlaylistType(DroppingCreateRequest request, ConstraintVa
boolean isValid = true;

// playlistId와 (playlistName + songIds) 중 하나만 있어야 함
boolean hasPlaylistId = request.playlistId() != null && !request.playlistId().isBlank();
boolean hasPlaylistId = request.playlistId() != null;
boolean hasNewPlaylist = (request.playlistName() != null && !request.playlistName().isBlank()) ||
(request.songIds() != null && !request.songIds().isEmpty());

Expand Down
Loading