diff --git a/backend/memetory/.gitignore b/backend/memetory/.gitignore index 7af35e80..22937949 100644 --- a/backend/memetory/.gitignore +++ b/backend/memetory/.gitignore @@ -36,5 +36,4 @@ out/ ### VS Code ### .vscode/ -src/main/resources/application-jwt.yml -src/main/resources/application-oauth.yml +src/main/resources/application-* diff --git a/backend/memetory/Dockerfile b/backend/memetory/Dockerfile new file mode 100644 index 00000000..7479d8c3 --- /dev/null +++ b/backend/memetory/Dockerfile @@ -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"] \ No newline at end of file diff --git a/backend/memetory/src/main/java/com/example/memetory/domain/member/service/MemberService.java b/backend/memetory/src/main/java/com/example/memetory/domain/member/service/MemberService.java index e04da850..cb695ea0 100644 --- a/backend/memetory/src/main/java/com/example/memetory/domain/member/service/MemberService.java +++ b/backend/memetory/src/main/java/com/example/memetory/domain/member/service/MemberService.java @@ -46,4 +46,9 @@ public Member getLoginMember() { return member; } + + @Transactional(readOnly = true) + public Member findById(Long id) { + return memberRepository.findById(id).orElseThrow(NotFoundMemberException::new); + } } diff --git a/backend/memetory/src/main/java/com/example/memetory/domain/meme/controller/MemeController.java b/backend/memetory/src/main/java/com/example/memetory/domain/meme/controller/MemeController.java new file mode 100644 index 00000000..bde20e2e --- /dev/null +++ b/backend/memetory/src/main/java/com/example/memetory/domain/meme/controller/MemeController.java @@ -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 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(); + } +} diff --git a/backend/memetory/src/main/java/com/example/memetory/domain/meme/dto/ShotStackCallBackRequest.java b/backend/memetory/src/main/java/com/example/memetory/domain/meme/dto/ShotStackCallBackRequest.java new file mode 100644 index 00000000..f96348f9 --- /dev/null +++ b/backend/memetory/src/main/java/com/example/memetory/domain/meme/dto/ShotStackCallBackRequest.java @@ -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(); + } +} diff --git a/backend/memetory/src/main/java/com/example/memetory/domain/meme/entity/Meme.java b/backend/memetory/src/main/java/com/example/memetory/domain/meme/entity/Meme.java new file mode 100644 index 00000000..d940e417 --- /dev/null +++ b/backend/memetory/src/main/java/com/example/memetory/domain/meme/entity/Meme.java @@ -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; + } +} diff --git a/backend/memetory/src/main/java/com/example/memetory/domain/meme/repository/MemeRepository.java b/backend/memetory/src/main/java/com/example/memetory/domain/meme/repository/MemeRepository.java new file mode 100644 index 00000000..429e1ffb --- /dev/null +++ b/backend/memetory/src/main/java/com/example/memetory/domain/meme/repository/MemeRepository.java @@ -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 { +} diff --git a/backend/memetory/src/main/java/com/example/memetory/domain/meme/service/MemeService.java b/backend/memetory/src/main/java/com/example/memetory/domain/meme/service/MemeService.java new file mode 100644 index 00000000..1244733f --- /dev/null +++ b/backend/memetory/src/main/java/com/example/memetory/domain/meme/service/MemeService.java @@ -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); + } +} diff --git a/backend/memetory/src/main/resources/application.yml b/backend/memetory/src/main/resources/application.yml index c8999899..9cb9a29a 100644 --- a/backend/memetory/src/main/resources/application.yml +++ b/backend/memetory/src/main/resources/application.yml @@ -4,6 +4,13 @@ spring: "local" : "local, jwt, oauth" active : local # "local" 을 실행 +--- +spring: + profiles: + group: + "dev": "dev, jwt, oauth" + active: dev # "dev" 을 실행 + --- spring: config: