-
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.
- Loading branch information
Showing
39 changed files
with
429 additions
and
93 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
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
54 changes: 54 additions & 0 deletions
54
src/main/java/com/example/dreamvalutbackend/domain/like/controller/LikeController.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,54 @@ | ||
package com.example.dreamvalutbackend.domain.like.controller; | ||
|
||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.security.core.annotation.AuthenticationPrincipal; | ||
import org.springframework.web.bind.annotation.DeleteMapping; | ||
import org.springframework.web.bind.annotation.PathVariable; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
import com.example.dreamvalutbackend.domain.like.controller.request.LikeCreateRequestDto; | ||
import com.example.dreamvalutbackend.domain.like.controller.request.LikeDeleteRequestDto; | ||
import com.example.dreamvalutbackend.domain.like.controller.response.LikeResponseDto; | ||
import com.example.dreamvalutbackend.domain.like.service.LikeService; | ||
import com.example.dreamvalutbackend.domain.user.domain.UserDetailPrincipal; | ||
|
||
import lombok.RequiredArgsConstructor; | ||
@RestController | ||
@RequiredArgsConstructor | ||
public class LikeController { | ||
|
||
private final LikeService likeService; | ||
|
||
@PostMapping("/tracks/{trackId}/likes") | ||
public ResponseEntity<LikeResponseDto> createLike(@PathVariable Long trackId, @AuthenticationPrincipal | ||
UserDetailPrincipal userDetailPrincipal) { | ||
LikeCreateRequestDto requestDto = LikeCreateRequestDto.builder() | ||
.userId(userDetailPrincipal.getUserId()) | ||
.trackId(trackId) | ||
.build(); | ||
|
||
LikeResponseDto responseDto = likeService.addLike(requestDto); | ||
|
||
return ResponseEntity.ok(responseDto); | ||
} | ||
|
||
@DeleteMapping("/tracks/{trackId}/disLikes") | ||
public ResponseEntity<LikeResponseDto> deleteLike(@PathVariable Long trackId, @AuthenticationPrincipal | ||
UserDetailPrincipal userDetailPrincipal){ | ||
LikeDeleteRequestDto requestDto = LikeDeleteRequestDto.builder() | ||
.userId(userDetailPrincipal.getUserId()) | ||
.trackId(trackId) | ||
.build(); | ||
|
||
likeService.deleteLike(requestDto); | ||
|
||
return ResponseEntity.noContent().build(); //반환 내용이 없어서 204 | ||
} | ||
|
||
|
||
|
||
|
||
|
||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...va/com/example/dreamvalutbackend/domain/like/controller/request/LikeCreateRequestDto.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,23 @@ | ||
package com.example.dreamvalutbackend.domain.like.controller.request; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class LikeCreateRequestDto { | ||
@NotNull | ||
private Long userId; | ||
@NotNull | ||
private Long trackId; | ||
|
||
@Builder | ||
public LikeCreateRequestDto(Long userId, Long trackId) { | ||
this.userId = userId; | ||
this.trackId = trackId; | ||
} | ||
|
||
} |
23 changes: 23 additions & 0 deletions
23
...va/com/example/dreamvalutbackend/domain/like/controller/request/LikeDeleteRequestDto.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,23 @@ | ||
package com.example.dreamvalutbackend.domain.like.controller.request; | ||
|
||
import jakarta.validation.constraints.NotNull; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class LikeDeleteRequestDto { | ||
@NotNull | ||
private Long userId; | ||
@NotNull | ||
private Long trackId; | ||
|
||
@Builder | ||
public LikeDeleteRequestDto(Long userId, Long trackId) { | ||
this.userId = userId; | ||
this.trackId = trackId; | ||
} | ||
|
||
} |
28 changes: 28 additions & 0 deletions
28
...n/java/com/example/dreamvalutbackend/domain/like/controller/response/LikeResponseDto.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,28 @@ | ||
package com.example.dreamvalutbackend.domain.like.controller.response; | ||
|
||
import com.example.dreamvalutbackend.domain.like.domain.Like; | ||
|
||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
public class LikeResponseDto { | ||
private Long id; | ||
private Long userId; | ||
private Long trackId; | ||
|
||
@Builder | ||
public LikeResponseDto(Long id, Long userId, Long trackId) { | ||
this.id = id; | ||
this.userId = userId; | ||
this.trackId = trackId; | ||
} | ||
|
||
public static LikeResponseDto toDto(Like like) { | ||
return LikeResponseDto.builder() | ||
.id(like.getId()) | ||
.userId(like.getUser().getUserId()) | ||
.trackId(like.getTrack().getId()) | ||
.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
19 changes: 19 additions & 0 deletions
19
src/main/java/com/example/dreamvalutbackend/domain/like/repository/LikeRepository.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,19 @@ | ||
package com.example.dreamvalutbackend.domain.like.repository; | ||
|
||
import java.util.Optional; | ||
|
||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
|
||
import com.example.dreamvalutbackend.domain.like.domain.Like; | ||
import com.example.dreamvalutbackend.domain.track.domain.Track; | ||
import com.example.dreamvalutbackend.domain.user.domain.User; | ||
|
||
public interface LikeRepository extends JpaRepository<Like, Long> { | ||
Optional<Like> findByUserAndTrack(User user, Track track); | ||
|
||
Long countByTrackId(Long trackId); | ||
|
||
@Query("SELECT count(l) > 0 FROM Like l WHERE l.user.userId = :userId AND l.track.id = :trackId") | ||
Boolean existsByUserIdAndTrackId(Long userId, Long trackId); | ||
} |
Oops, something went wrong.