-
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.
feature / Record add API(read, update, delete, recent read, report) #14
- Loading branch information
1 parent
99ca826
commit a771830
Showing
15 changed files
with
402 additions
and
6 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
5 changes: 5 additions & 0 deletions
5
src/main/java/com/todaysgym/todaysgym/post/PostRepository.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 |
---|---|---|
@@ -1,9 +1,14 @@ | ||
package com.todaysgym.todaysgym.post; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface PostRepository extends JpaRepository<Post, Long> { | ||
Optional<Post> getByPostId(Long postId); | ||
|
||
@Query("select p from Post p where p.record.recordId = :recordId") | ||
List<Post> findPostByRecord(@Param("recordId") Long recordId); | ||
} |
25 changes: 25 additions & 0 deletions
25
src/main/java/com/todaysgym/todaysgym/post/PostService.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,25 @@ | ||
package com.todaysgym.todaysgym.post; | ||
|
||
import com.todaysgym.todaysgym.config.exception.BaseException; | ||
import com.todaysgym.todaysgym.post.PostRepository; | ||
import com.todaysgym.todaysgym.record.photo.RecordPhotoRepository; | ||
import com.todaysgym.todaysgym.record.photo.RecordPhotoService; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.List; | ||
|
||
import static com.todaysgym.todaysgym.config.exception.errorCode.RecordErrorCode.EMPTY_RECORD; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class PostService { | ||
private final PostRepository postRepository; | ||
|
||
/** | ||
* 기록과 관련된 게시글 조회 후 기록 null로 변경 | ||
*/ | ||
public List<Post> deleteRecord(Long recordId){ | ||
return postRepository.findPostByRecord(recordId); | ||
} | ||
} |
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
21 changes: 19 additions & 2 deletions
21
src/main/java/com/todaysgym/todaysgym/record/RecordRepository.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 |
---|---|---|
@@ -1,14 +1,31 @@ | ||
package com.todaysgym.todaysgym.record; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import org.springframework.data.domain.Page; | ||
import org.springframework.data.domain.PageRequest; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
import org.springframework.data.jpa.repository.Modifying; | ||
import org.springframework.data.jpa.repository.Query; | ||
import org.springframework.data.repository.query.Param; | ||
|
||
public interface RecordRepository extends JpaRepository<Record, Long> { | ||
Optional<Record> getByRecordId(Long recordId); | ||
|
||
@Query("select count(r) from Record r where FORMATDATETIME(r.createdAt, 'yyyy-MM-dd') = :date and r.member.memberId = :memberId") | ||
Integer findByRecordDate(@Param("date") String date, @Param("memberId") Long memberId); | ||
@Query("select count(r) from Record r where date_format(r.createdAt, '%Y-%m-%d') = :date and r.member.memberId = :memberId") | ||
Integer findByRecordCount(@Param("date") String date, @Param("memberId") Long memberId); | ||
|
||
@Query("select r from Record r where date_format(r.createdAt, '%Y-%m-%d') = :date and r.member.memberId = :memberId") | ||
Record findByRecordDate(@Param("date") String date, @Param("memberId") Long memberId); | ||
|
||
@Query("select r from Record r where date_format(r.createdAt, '%Y-%m') = :month and r.member.memberId = :memberId") | ||
List<Record> findByRecordMonth(@Param("month") String month, @Param("memberId") Long memberId); | ||
|
||
@Modifying | ||
@Query("delete from Record r where r.recordId = :recordId") | ||
Integer deleteAllByRecordId(@Param("recordId") Long recordId); | ||
|
||
@Query("select r from Record r where r.member.memberId = :memberId") | ||
Page<Record> findAllByUserId(@Param("memberId") Long memberId, PageRequest pageRequest); | ||
} |
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
26 changes: 26 additions & 0 deletions
26
src/main/java/com/todaysgym/todaysgym/record/dto/RecordGetRecentRes.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,26 @@ | ||
package com.todaysgym.todaysgym.record.dto; | ||
|
||
import com.todaysgym.todaysgym.record.photo.RecordPhoto; | ||
import com.todaysgym.todaysgym.utils.UtilService; | ||
import lombok.Data; | ||
|
||
import java.time.LocalDateTime; | ||
import java.util.List; | ||
|
||
@Data | ||
public class RecordGetRecentRes { | ||
private Long recordId; | ||
private String content; | ||
private String createdTime; | ||
private String imgUrl; | ||
public RecordGetRecentRes(Long recordId, String content, LocalDateTime createdAt, List<RecordPhoto> recordPhotos) { | ||
this.recordId = recordId; | ||
this.content = content; | ||
this.createdTime = UtilService.convertLocalDateTimeToLocalDate(createdAt); | ||
if (recordPhotos.isEmpty()) { | ||
this.imgUrl = ""; | ||
} else { | ||
this.imgUrl = recordPhotos.get(0).getImgUrl(); | ||
} | ||
} | ||
} |
Oops, something went wrong.