Skip to content

Commit

Permalink
Merge pull request #57 from tukcomCD2024/SNOW-172-feat#51/Swagger
Browse files Browse the repository at this point in the history
Snow 172 feat#51/swagger
  • Loading branch information
JunRain2 authored Mar 30, 2024
2 parents 89b1b22 + deb4298 commit 82471f3
Show file tree
Hide file tree
Showing 18 changed files with 406 additions and 109 deletions.
3 changes: 3 additions & 0 deletions backend/memetory/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ dependencies {
implementation 'com.auth0:java-jwt:4.2.1'
implementation 'org.springframework.boot:spring-boot-starter-security'
implementation 'org.springframework.boot:spring-boot-starter-oauth2-client'

// Swagger 적용
implementation 'org.springdoc:springdoc-openapi-starter-webmvc-ui:2.2.0'
}

tasks.named('test') {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
package com.example.memetory.domain.like.controller;

import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.ResponseEntity;

@Tag(name = "Like")
public interface LikeApi {

@Operation(
summary = "meme`s 좋아요 등록",
description = "공유된 meme`s 게시물에 좋아요를 등록한다.",
security = {@SecurityRequirement(name = "access_token")}
)
@ApiResponses(value = {
@ApiResponse(
responseCode = "201",
description = "좋아요 등록!"
)
})
ResponseEntity<String> register(
@Parameter(hidden = true) String email,
@Parameter(in = ParameterIn.PATH, description = "밈스 아이디", required = true)
Long memesId
);

@Operation(
summary = "meme`s 좋아요 취소",
description = "공유된 meme`s 게시물에 등록된 좋아요를 취소한다.",
security = {@SecurityRequirement(name = "access_token")}
)
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "좋아요 취소!"
)
})
ResponseEntity<String> cancel(
@Parameter(hidden = true) String email,
@Parameter(in = ParameterIn.PATH, description = "밈스 아이디", required = true)
Long memesId
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,11 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/memes")
public class LikeController {
public class LikeController implements LikeApi {
private final LikeService likeService;

@PostMapping("/{memesId}/like")
@Override
public ResponseEntity<String> register(@LoginMemberEmail String email, @PathVariable Long memesId) {
LikeServiceDto likeServiceDto = LikeServiceDto.create(email, memesId);
likeService.register(likeServiceDto);
Expand All @@ -25,6 +26,7 @@ public ResponseEntity<String> register(@LoginMemberEmail String email, @PathVari
}

@DeleteMapping("/{memesId}/like")
@Override
public ResponseEntity<String> cancel(@LoginMemberEmail String email, @PathVariable Long memesId) {
LikeServiceDto likeServiceDto = LikeServiceDto.create(email, memesId);
likeService.cancel(likeServiceDto);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.example.memetory.domain.member.controller;

import com.example.memetory.domain.member.dto.MemberSignUpRequest;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

@Tag(name = "Member")
public interface MemberApi {

@Operation(
summary = "회원가입",
description = "첫 소셜로그인 후 추가 정보 기입",
security = {@SecurityRequirement(name = "access_token")}
)
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "회원가입 성공!"
)
})
ResponseEntity<HttpStatus> register(
MemberSignUpRequest memberSignUpRequest,
@Parameter(hidden = true) String email
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,25 +8,25 @@

import com.example.memetory.domain.member.dto.MemberServiceDto;
import com.example.memetory.domain.member.dto.MemberSignUpRequest;
import com.example.memetory.domain.member.entity.Member;
import com.example.memetory.domain.member.service.MemberService;
import com.example.memetory.global.annotation.LoginMemberEmail;

import lombok.RequiredArgsConstructor;

@RestController
@RequiredArgsConstructor
public class MemberController {
public class MemberController implements MemberApi {

private final MemberService memberService;
private final MemberService memberService;

@PostMapping("/sign-up")
public ResponseEntity<HttpStatus> register(@RequestBody MemberSignUpRequest memberSignUpRequest,
@LoginMemberEmail String email) {
MemberServiceDto memberServiceDto = memberSignUpRequest.toServiceDto(email);
@PostMapping("/sign-up")
@Override
public ResponseEntity<HttpStatus> register(@RequestBody MemberSignUpRequest memberSignUpRequest,
@LoginMemberEmail String email) {
MemberServiceDto memberServiceDto = memberSignUpRequest.toServiceDto(email);

memberService.register(memberServiceDto);
memberService.register(memberServiceDto);

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

import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AccessLevel;
import lombok.Getter;
import lombok.NoArgsConstructor;

@NoArgsConstructor(access = AccessLevel.PRIVATE)
@Getter
@Schema(description = "회원 가입 포맷")
public class MemberSignUpRequest {

@Schema(description = "닉네임")
private String nickName;

public MemberServiceDto toServiceDto(String email) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
package com.example.memetory.domain.meme.controller;

import com.example.memetory.domain.meme.dto.*;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.responses.ApiResponses;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;

@Tag(name = "Meme")
public interface MemeApi {

@Operation(
summary = "밈 생성 콜백",
description = "밈 최종 생성 후 웹 훅을 받을 api"
)
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "콜백 성공!"
)
})
ResponseEntity<HttpStatus> callBackMeme(
@Parameter(in = ParameterIn.PATH, description = "멤버 아이디", required = true) Long memberId,
ShotStackCallBackRequest shotStackCallBackRequest
);

@Operation(
summary = "밈 생성",
description = "템플릿, 이미지, 목소리, 대사를 입력 하고 밈을 생성한다.",
security = {@SecurityRequirement(name = "access_token")}
)
@ApiResponses(value = {
@ApiResponse(
responseCode = "201",
description = "밈 생성"
)
})
ResponseEntity<HttpStatus> register(
@Parameter(hidden = true) String email,
GenerateMemeListRequest generateMemeListRequest
);

@Operation(
summary = "밈 단일 조회",
description = "밈 아이디에 해당하는 밈을 조회한다.",
security = {@SecurityRequirement(name = "access_token")}
)
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "밈 단일 조회"
)
})
ResponseEntity<MemeResponse> findMeme(
@Parameter(hidden = true) String email,
@Parameter(in = ParameterIn.PATH, description = "밈 아이디", required = true) Long memeId
);

@Operation(
summary = "밈 전체 조회",
description = "회원이 생성한 밈을 전체 조회한다.",
security = {@SecurityRequirement(name = "access_token")}
)
@ApiResponses(value = {
@ApiResponse(
responseCode = "200",
description = "밈 전체 조회"
)
})
ResponseEntity<MemeListResponse> findMemeList(
@Parameter(hidden = true) String email
);
}
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@
import org.springframework.web.reactive.function.BodyInserters;
import org.springframework.web.reactive.function.client.WebClient;

import com.example.memetory.domain.member.service.MemberService;
import com.example.memetory.domain.meme.dto.GenerateMemeListRequest;
import com.example.memetory.domain.meme.dto.MemeListResponse;
import com.example.memetory.domain.meme.dto.MemeResponse;
Expand All @@ -27,63 +26,67 @@
@RestController
@RequiredArgsConstructor
@RequestMapping("/meme")
public class MemeController {
private final MemeService memeService;
public class MemeController implements MemeApi{
private final MemeService memeService;

@Value("${spring.ai-server.url}")
private String AI_SERVER_URL;
@Value("${spring.ai-server.url}")
private String AI_SERVER_URL;

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

MemeServiceDto memeServiceDto = shotStackCallBackRequest.toServiceDto(memberId);
MemeServiceDto memeServiceDto = shotStackCallBackRequest.toServiceDto(memberId);

memeService.register(memeServiceDto);
memeService.register(memeServiceDto);

return ResponseEntity.status(HttpStatus.OK).build();
}
return ResponseEntity.status(HttpStatus.OK).build();
}

@PostMapping
public ResponseEntity<HttpStatus> register(@LoginMemberEmail String email,
@RequestBody GenerateMemeListRequest generateMemeListRequest) {
@PostMapping
@Override
public ResponseEntity<HttpStatus> register(@LoginMemberEmail String email,
@RequestBody GenerateMemeListRequest generateMemeListRequest) {

MemeServiceDto memeServiceDto = generateMemeListRequest.toServiceDto(email);
String aiServerSendJson = memeService.getAIServerSendJson(memeServiceDto);
MemeServiceDto memeServiceDto = generateMemeListRequest.toServiceDto(email);
String aiServerSendJson = memeService.getAIServerSendJson(memeServiceDto);

WebClient
.create(AI_SERVER_URL)
.post()
.contentType(MediaType.APPLICATION_JSON)
.body(BodyInserters.fromValue(aiServerSendJson))
.retrieve()
.bodyToMono(Void.class)
.subscribe();
WebClient
.create(AI_SERVER_URL)
.post()
.contentType(MediaType.APPLICATION_JSON)
.body(BodyInserters.fromValue(aiServerSendJson))
.retrieve()
.bodyToMono(Void.class)
.subscribe();

return ResponseEntity.status(HttpStatus.OK).build();
}
return ResponseEntity.status(HttpStatus.CREATED).build();
}

@GetMapping("/{memeId}")
public ResponseEntity<MemeResponse> findMeme(@LoginMemberEmail String email, @PathVariable Long memeId) {
MemeServiceDto memeServiceDto = MemeServiceDto.create(email, memeId);
@GetMapping("/{memeId}")
@Override
public ResponseEntity<MemeResponse> findMeme(@LoginMemberEmail String email, @PathVariable Long memeId) {
MemeServiceDto memeServiceDto = MemeServiceDto.create(email, memeId);

if (memeService.checkMember(memeServiceDto)) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}
if (memeService.checkMember(memeServiceDto)) {
return ResponseEntity.status(HttpStatus.FORBIDDEN).build();
}

return ResponseEntity
.status(HttpStatus.OK)
.body(memeService.getMeme(memeServiceDto));
}
return ResponseEntity
.status(HttpStatus.OK)
.body(memeService.getMeme(memeServiceDto));
}

@GetMapping
public ResponseEntity<MemeListResponse> findMemeList(@LoginMemberEmail String email) {
MemeServiceDto memeServiceDto = MemeServiceDto.create(email);
@GetMapping
@Override
public ResponseEntity<MemeListResponse> findMemeList(@LoginMemberEmail String email) {
MemeServiceDto memeServiceDto = MemeServiceDto.create(email);

MemeListResponse memeListResponse = memeService.getAllMeme(memeServiceDto);
MemeListResponse memeListResponse = memeService.getAllMeme(memeServiceDto);

return ResponseEntity
.status(HttpStatus.OK)
.body(memeListResponse);
}
return ResponseEntity
.status(HttpStatus.OK)
.body(memeListResponse);
}
}
Loading

0 comments on commit 82471f3

Please sign in to comment.