Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/answer/#39 #60

Merged
merged 4 commits into from
May 13, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,14 +1,11 @@
package com.web.baebaeBE.presentation.answer;
package com.web.baebaeBE.domain.answer.controller;

import com.google.firebase.database.annotations.NotNull;
import com.web.baebaeBE.application.answer.AnswerApplication;
import com.web.baebaeBE.infra.answer.entity.Answer;
import com.web.baebaeBE.presentation.answer.api.AnswerApi;
import com.web.baebaeBE.presentation.answer.dto.AnswerCreateRequest;
import com.web.baebaeBE.presentation.answer.dto.AnswerDetailResponse;
import com.web.baebaeBE.presentation.answer.dto.AnswerResponse;
import com.web.baebaeBE.domain.answer.controller.api.AnswerApi;
import com.web.baebaeBE.domain.answer.dto.AnswerCreateRequest;
import com.web.baebaeBE.domain.answer.dto.AnswerDetailResponse;
import com.web.baebaeBE.domain.answer.dto.AnswerResponse;
import com.web.baebaeBE.domain.answer.service.AnswerService;
import io.swagger.v3.oas.annotations.Operation;
import jakarta.validation.Valid;
import lombok.AllArgsConstructor;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
Expand All @@ -24,52 +21,49 @@
@AllArgsConstructor
@RequestMapping("/api/answers")
public class AnswerController implements AnswerApi {
private final AnswerApplication answerApplication;
private final AnswerService answerService;

@PostMapping(value = "/{memberId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<AnswerDetailResponse> createAnswer(@PathVariable Long memberId,
@RequestPart(value = "imageFile") MultipartFile imageFile,
@RequestPart AnswerCreateRequest request) {
AnswerDetailResponse createdAnswer = answerApplication.createAnswer(request, memberId, imageFile);
AnswerDetailResponse createdAnswer = answerService.createAnswer(request, memberId, imageFile);
return ResponseEntity.status(HttpStatus.CREATED).body(createdAnswer);
}

@GetMapping("/member/{memberId}")
public ResponseEntity<List<AnswerResponse>> getAnswersByMemberId(@PathVariable Long memberId) {
List<AnswerResponse> answers = answerApplication.getAnswersByMemberId(memberId);
List<AnswerResponse> answers = answerService.getAnswersByMemberId(memberId);
return ResponseEntity.ok(answers);
}

@GetMapping(value = "/{answerId}")
@GetMapping()
public ResponseEntity<List<AnswerDetailResponse>> getAllAnswers(@RequestParam Long memberId, Pageable pageable) {
Page<AnswerDetailResponse> answers = answerApplication.getAllAnswers(memberId, pageable);
Page<AnswerDetailResponse> answers = answerService.getAllAnswers(memberId, pageable);
return ResponseEntity.ok(answers.getContent());
}

@PutMapping(value = "/{answerId}", consumes = MediaType.MULTIPART_FORM_DATA_VALUE)
public ResponseEntity<AnswerDetailResponse> updateAnswer(
@PathVariable Long answerId,
@RequestPart(value = "imageFile") MultipartFile imageFile,
@RequestPart AnswerCreateRequest request) {
AnswerDetailResponse updatedAnswer = answerApplication.updateAnswer(answerId, request, imageFile);
public ResponseEntity<AnswerDetailResponse> updateAnswer(@PathVariable Long answerId,
@RequestPart(value = "imageFile") MultipartFile imageFile,
@RequestPart AnswerCreateRequest request) {
AnswerDetailResponse updatedAnswer = answerService.updateAnswer(answerId, request, imageFile);
return ResponseEntity.ok(updatedAnswer);
}

@DeleteMapping("/{answerId}")
public ResponseEntity<Void> deleteAnswer( @PathVariable Long answerId) {
answerApplication.deleteAnswer(answerId);
public ResponseEntity<Void> deleteAnswer(@PathVariable Long answerId) {
answerService.deleteAnswer(answerId);
return ResponseEntity.status(HttpStatus.NO_CONTENT).body(null);
}

@Operation(summary = "반응 알림")
@PatchMapping("/{answerId}/react")
public ResponseEntity<Void> updateAnswerReactions(
@PathVariable Long answerId,
@RequestParam int heartCount,
@RequestParam int curiousCount,
@RequestParam int sadCount
) {
answerApplication.updateReactionCounts(answerId, heartCount, curiousCount, sadCount);
public ResponseEntity<Void> updateAnswerReactions(@PathVariable Long answerId,
@RequestParam int heartCount,
@RequestParam int curiousCount,
@RequestParam int sadCount) {
answerService.updateReactionCounts(answerId, heartCount, curiousCount, sadCount);
return ResponseEntity.ok().build();
}
}
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
package com.web.baebaeBE.presentation.answer.api;
package com.web.baebaeBE.domain.answer.controller.api;

import com.google.firebase.database.annotations.NotNull;
import com.web.baebaeBE.presentation.answer.dto.AnswerCreateRequest;
import com.web.baebaeBE.presentation.answer.dto.AnswerDetailResponse;
import com.web.baebaeBE.presentation.answer.dto.AnswerResponse;
import com.web.baebaeBE.domain.answer.dto.AnswerCreateRequest;
import com.web.baebaeBE.domain.answer.dto.AnswerDetailResponse;
import com.web.baebaeBE.domain.answer.dto.AnswerResponse;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.enums.ParameterIn;
Expand All @@ -12,7 +11,6 @@
import io.swagger.v3.oas.annotations.responses.ApiResponse;
import io.swagger.v3.oas.annotations.security.SecurityRequirement;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.Valid;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.http.MediaType;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
package com.web.baebaeBE.presentation.answer.dto;
package com.web.baebaeBE.domain.answer.dto;

import org.springframework.web.multipart.MultipartFile;
import lombok.*;

import java.util.List;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.web.baebaeBE.presentation.answer.dto;
package com.web.baebaeBE.domain.answer.dto;

import lombok.Getter;
import lombok.Setter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.web.baebaeBE.presentation.answer.dto;
package com.web.baebaeBE.domain.answer.dto;

import com.web.baebaeBE.infra.answer.entity.Answer;
import com.web.baebaeBE.domain.answer.entity.Answer;
import lombok.Getter;
import lombok.Setter;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package com.web.baebaeBE.infra.answer.entity;
package com.web.baebaeBE.domain.answer.entity;

import com.web.baebaeBE.domain.categorized.answer.entity.CategorizedAnswer;
import com.web.baebaeBE.domain.member.entity.Member;
import com.web.baebaeBE.infra.question.entity.Question;
import com.web.baebaeBE.domain.question.entity.Question;
import jakarta.persistence.*;
import lombok.*;
import org.hibernate.annotations.OnDelete;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package com.web.baebaeBE.domain23.answer.exception;
package com.web.baebaeBE.domain.answer.exception;

import com.web.baebaeBE.global.error.ErrorCode;
import lombok.Getter;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.web.baebaeBE.infra.answer.repository;
package com.web.baebaeBE.domain.answer.repository;

import com.web.baebaeBE.infra.answer.entity.Answer;
import com.web.baebaeBE.domain.answer.entity.Answer;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.data.jpa.repository.JpaRepository;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
package com.web.baebaeBE.infra.answer.repository;
package com.web.baebaeBE.domain.answer.repository;

import com.web.baebaeBE.infra.answer.entity.Answer;
import com.web.baebaeBE.domain.answer.dto.AnswerResponse;
import com.web.baebaeBE.domain.answer.entity.Answer;
import com.web.baebaeBE.domain.member.entity.Member;
import com.web.baebaeBE.infra.question.entity.Question;
import com.web.baebaeBE.presentation.answer.dto.AnswerCreateRequest;
import com.web.baebaeBE.presentation.answer.dto.AnswerDetailResponse;
import com.web.baebaeBE.domain.question.entity.Question;
import com.web.baebaeBE.domain.answer.dto.AnswerCreateRequest;
import com.web.baebaeBE.domain.answer.dto.AnswerDetailResponse;
import lombok.AllArgsConstructor;
import org.springframework.stereotype.Component;

Expand Down Expand Up @@ -48,4 +49,8 @@ public AnswerDetailResponse toDomain(Answer answer, String fcmtoken) {
fcmtoken
);
}

public AnswerResponse toResponse(Answer answer) {
return AnswerResponse.of(answer);
}
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.web.baebaeBE.infra.answer.repository;
package com.web.baebaeBE.domain.answer.repository;

import com.web.baebaeBE.infra.answer.entity.Answer;
import com.web.baebaeBE.domain.answer.entity.Answer;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package com.web.baebaeBE.infra.answer.repository;
package com.web.baebaeBE.domain.answer.repository;

import com.web.baebaeBE.infra.answer.entity.Answer;
import com.web.baebaeBE.domain.answer.entity.Answer;
import com.web.baebaeBE.domain.answer.repository.AnswerJpaRepository;
import com.web.baebaeBE.domain.answer.repository.AnswerRepository;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Primary;
import org.springframework.data.domain.Page;
Expand All @@ -12,7 +14,7 @@

@Repository
@Primary
public class AnswerRepositoryImpl implements AnswerRepository{
public class AnswerRepositoryImpl implements AnswerRepository {
private final AnswerJpaRepository jpaRepository;

@Autowired
Expand Down
Loading
Loading