Skip to content

Commit

Permalink
Merge pull request #47 from tukcomCD2024/SNOW-49-feat#45/memes-generate
Browse files Browse the repository at this point in the history
Snow 49 feat#45/memes generate
  • Loading branch information
JunRain2 authored Mar 25, 2024
2 parents be2f8ae + 259d374 commit f88ff8d
Show file tree
Hide file tree
Showing 8 changed files with 184 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,9 @@ public String getAIServerSendJson(MemeServiceDto memeServiceDto) {
Member member = memberService.findByEmail(memeServiceDto.getEmail());

AIServerSendDto aiServerSendDto = AIServerSendDto.builder()
.memberId(member.getId())
.scene(memeServiceDto.getScene())
.build();
.memberId(member.getId())
.scene(memeServiceDto.getScene())
.build();

return gson.toJson(aiServerSendDto);
}
Expand All @@ -66,12 +66,19 @@ public MemeListResponse getAllMeme(MemeServiceDto memeServiceDto) {
Member member = memberService.findByEmail(memeServiceDto.getEmail());

List<MemeResponse> memeList = memeRepository.findAllByMember(member)
.stream()
.map(MemeResponse::of)
.toList();
.stream()
.map(MemeResponse::of)
.toList();

return MemeListResponse.builder()
.memeList(memeList)
.build();
}

// Service 계층 끼리의 밈 조회
@Transactional(readOnly = true)
public Meme getMemeBetweenService(Long memeId) {
Meme foundMeme = memeRepository.findById(memeId).orElseThrow(NotFoundMemeException::new);
return foundMeme;
}
}
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();
}


}
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();
}
}
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 {
}
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();
}
}
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;
}
}
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> {
}
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);
}
}

0 comments on commit f88ff8d

Please sign in to comment.