-
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.
Merge pull request #47 from tukcomCD2024/SNOW-49-feat#45/memes-generate
Snow 49 feat#45/memes generate
- Loading branch information
Showing
8 changed files
with
184 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
30 changes: 30 additions & 0 deletions
30
.../memetory/src/main/java/com/example/memetory/domain/memes/controller/MemesController.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,30 @@ | ||
package com.example.memetory.domain.memes.controller; | ||
|
||
import com.example.memetory.domain.memes.dto.MemesServiceDto; | ||
import com.example.memetory.domain.memes.dto.request.GenerateMemesRequest; | ||
import com.example.memetory.domain.memes.service.MemesService; | ||
import com.example.memetory.global.annotation.LoginMemberEmail; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.http.HttpStatus; | ||
import org.springframework.http.ResponseEntity; | ||
import org.springframework.web.bind.annotation.PostMapping; | ||
import org.springframework.web.bind.annotation.RequestBody; | ||
import org.springframework.web.bind.annotation.RequestMapping; | ||
import org.springframework.web.bind.annotation.RestController; | ||
|
||
|
||
@RestController | ||
@RequiredArgsConstructor | ||
@RequestMapping("/memes") | ||
public class MemesController { | ||
private final MemesService memesService; | ||
|
||
@PostMapping | ||
public ResponseEntity<HttpStatus> register(@LoginMemberEmail String email, @RequestBody GenerateMemesRequest generateMemesRequest) { | ||
MemesServiceDto memesServiceDto = generateMemesRequest.toServiceDto(email); | ||
memesService.register(memesServiceDto); | ||
return ResponseEntity.status(HttpStatus.CREATED).build(); | ||
} | ||
|
||
|
||
} |
30 changes: 30 additions & 0 deletions
30
backend/memetory/src/main/java/com/example/memetory/domain/memes/dto/MemesServiceDto.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,30 @@ | ||
package com.example.memetory.domain.memes.dto; | ||
|
||
import com.example.memetory.domain.member.entity.Member; | ||
import com.example.memetory.domain.meme.entity.Meme; | ||
import com.example.memetory.domain.memes.entity.Memes; | ||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Getter | ||
@Builder | ||
@AllArgsConstructor | ||
public class MemesServiceDto { | ||
private Long memberId; | ||
private Long memeId; | ||
private String email; | ||
private String title; | ||
private int likeCount; | ||
private int commentCount; | ||
|
||
public Memes toEntity(Member member, Meme meme) { | ||
return Memes.builder() | ||
.member(member) | ||
.meme(meme) | ||
.title(this.title) | ||
.likeCount(0) | ||
.commentCount(0) | ||
.build(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
backend/memetory/src/main/java/com/example/memetory/domain/memes/dto/mapper/MemesMapper.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,7 @@ | ||
package com.example.memetory.domain.memes.dto.mapper; | ||
|
||
import org.springframework.stereotype.Component; | ||
|
||
@Component | ||
public class MemesMapper { | ||
} |
22 changes: 22 additions & 0 deletions
22
...ory/src/main/java/com/example/memetory/domain/memes/dto/request/GenerateMemesRequest.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,22 @@ | ||
package com.example.memetory.domain.memes.dto.request; | ||
|
||
import com.example.memetory.domain.memes.dto.MemesServiceDto; | ||
import lombok.AccessLevel; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class GenerateMemesRequest { | ||
|
||
private Long memeId; | ||
private String title; | ||
|
||
public MemesServiceDto toServiceDto(String email) { | ||
return MemesServiceDto.builder() | ||
.email(email) | ||
.memeId(memeId) | ||
.title(title) | ||
.build(); | ||
} | ||
} |
44 changes: 44 additions & 0 deletions
44
backend/memetory/src/main/java/com/example/memetory/domain/memes/entity/Memes.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,44 @@ | ||
package com.example.memetory.domain.memes.entity; | ||
|
||
import com.example.memetory.domain.member.entity.Member; | ||
import com.example.memetory.domain.meme.entity.Meme; | ||
import com.example.memetory.global.entity.BaseEntity; | ||
import jakarta.persistence.*; | ||
import lombok.AccessLevel; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
import lombok.NoArgsConstructor; | ||
|
||
@Getter | ||
@Entity | ||
@NoArgsConstructor(access = AccessLevel.PROTECTED) | ||
public class Memes extends BaseEntity { | ||
|
||
@Id | ||
@GeneratedValue(strategy = GenerationType.IDENTITY) | ||
@Column(name = "memes_id") | ||
private Long Id; | ||
|
||
private String title; | ||
|
||
private int likeCount; | ||
|
||
private int commentCount; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "meme_id") | ||
private Meme meme; | ||
|
||
@ManyToOne(fetch = FetchType.LAZY) | ||
@JoinColumn(name = "member_id") | ||
private Member member; | ||
|
||
@Builder | ||
public Memes(String title, int likeCount, int commentCount, Meme meme, Member member) { | ||
this.title = title; | ||
this.likeCount = likeCount; | ||
this.commentCount = commentCount; | ||
this.meme = meme; | ||
this.member = member; | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
.../memetory/src/main/java/com/example/memetory/domain/memes/repository/MemesRepository.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,7 @@ | ||
package com.example.memetory.domain.memes.repository; | ||
|
||
import com.example.memetory.domain.memes.entity.Memes; | ||
import org.springframework.data.jpa.repository.JpaRepository; | ||
|
||
public interface MemesRepository extends JpaRepository<Memes, Long> { | ||
} |
31 changes: 31 additions & 0 deletions
31
backend/memetory/src/main/java/com/example/memetory/domain/memes/service/MemesService.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,31 @@ | ||
package com.example.memetory.domain.memes.service; | ||
|
||
import com.example.memetory.domain.member.entity.Member; | ||
import com.example.memetory.domain.member.service.MemberService; | ||
import com.example.memetory.domain.meme.entity.Meme; | ||
import com.example.memetory.domain.meme.service.MemeService; | ||
import com.example.memetory.domain.memes.dto.MemesServiceDto; | ||
import com.example.memetory.domain.memes.dto.mapper.MemesMapper; | ||
import com.example.memetory.domain.memes.entity.Memes; | ||
import com.example.memetory.domain.memes.repository.MemesRepository; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
import org.springframework.transaction.annotation.Transactional; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class MemesService { | ||
private final MemberService memberService; | ||
private final MemeService memeService; | ||
private final MemesMapper memesMapper; | ||
private final MemesRepository memesRepository; | ||
|
||
@Transactional | ||
public void register(MemesServiceDto memesServiceDto) { | ||
Member foundMember = memberService.findByEmail(memesServiceDto.getEmail()); | ||
Meme foundMeme = memeService.getMemeBetweenService(memesServiceDto.getMemeId()); | ||
|
||
Memes newMemes = memesServiceDto.toEntity(foundMember, foundMeme); | ||
memesRepository.save(newMemes); | ||
} | ||
} |