Skip to content

Commit

Permalink
Merge pull request #36 from tukcomCD2024/feat#33/save_meme
Browse files Browse the repository at this point in the history
Feat#33/save meme
  • Loading branch information
ggamD00 authored Mar 13, 2024
2 parents b6cb522 + 00f4eb2 commit b237a7f
Show file tree
Hide file tree
Showing 9 changed files with 143 additions and 2 deletions.
3 changes: 1 addition & 2 deletions backend/memetory/.gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,4 @@ out/
### VS Code ###
.vscode/

src/main/resources/application-jwt.yml
src/main/resources/application-oauth.yml
src/main/resources/application-*
5 changes: 5 additions & 0 deletions backend/memetory/Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
FROM openjdk:17-oracle

COPY build/libs/memetory-0.0.1-SNAPSHOT.jar app.jar

ENTRYPOINT ["java","-Dspring.profiles/active=dev", "-jar", "app.jar"]
Original file line number Diff line number Diff line change
Expand Up @@ -46,4 +46,9 @@ public Member getLoginMember() {

return member;
}

@Transactional(readOnly = true)
public Member findById(Long id) {
return memberRepository.findById(id).orElseThrow(NotFoundMemberException::new);
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.example.memetory.domain.meme.controller;

import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.PathVariable;
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;

import com.example.memetory.domain.member.entity.Member;
import com.example.memetory.domain.member.service.MemberService;
import com.example.memetory.domain.meme.dto.ShotStackCallBackRequest;
import com.example.memetory.domain.meme.entity.Meme;
import com.example.memetory.domain.meme.service.MemeService;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
@RequestMapping("/meme")
public class MemeController {
private final MemberService memberService;
private final MemeService memeService;

@PostMapping("/create/{id}")
public ResponseEntity<HttpStatus> callBackMeme(@PathVariable Long id,
@RequestBody ShotStackCallBackRequest shotStackCallBackRequest) {

Member member = memberService.findById(id);
Meme meme = shotStackCallBackRequest.toEntity(member);

memeService.save(meme);

return ResponseEntity.status(HttpStatus.OK).build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
package com.example.memetory.domain.meme.dto;

import com.example.memetory.domain.member.entity.Member;
import com.example.memetory.domain.meme.entity.Meme;

import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Getter
@NoArgsConstructor(access = AccessLevel.PRIVATE)
public class ShotStackCallBackRequest {
private String status;
private String url;
private String error;

public Meme toEntity(Member member) {
return Meme.builder()
.s3Url(this.url)
.member(member)
.build();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
package com.example.memetory.domain.meme.entity;

import com.example.memetory.domain.member.entity.Member;
import com.example.memetory.global.entity.BaseEntity;

import jakarta.persistence.Column;
import jakarta.persistence.Entity;
import jakarta.persistence.FetchType;
import jakarta.persistence.GeneratedValue;
import jakarta.persistence.GenerationType;
import jakarta.persistence.Id;
import jakarta.persistence.JoinColumn;
import jakarta.persistence.ManyToOne;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.NoArgsConstructor;

@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Meme extends BaseEntity {
@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "meme_id")
private Long id;

@ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "member_id")
private Member member;

private String s3Url;

@Builder
public Meme(Member member, String s3Url) {
this.member = member;
this.s3Url = s3Url;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
package com.example.memetory.domain.meme.repository;

import org.springframework.data.jpa.repository.JpaRepository;

import com.example.memetory.domain.meme.entity.Meme;

public interface MemeRepository extends JpaRepository<Meme, Long> {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package com.example.memetory.domain.meme.service;

import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.example.memetory.domain.meme.entity.Meme;
import com.example.memetory.domain.meme.repository.MemeRepository;

import lombok.RequiredArgsConstructor;

@Service
@RequiredArgsConstructor
public class MemeService {
private final MemeRepository memeRepository;

@Transactional
public void save(Meme meme) {
memeRepository.save(meme);
}
}
7 changes: 7 additions & 0 deletions backend/memetory/src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@ spring:
"local" : "local, jwt, oauth"
active : local # "local" 을 실행

---
spring:
profiles:
group:
"dev": "dev, jwt, oauth"
active: dev # "dev" 을 실행

---
spring:
config:
Expand Down

0 comments on commit b237a7f

Please sign in to comment.