Skip to content

Commit

Permalink
Merge pull request #14 from GOSOPT-SOPKATHON-5/feat/#12-get-main
Browse files Browse the repository at this point in the history
#12 get main
  • Loading branch information
hyeonjeongs authored May 20, 2023
2 parents f35c5b0 + 2a127bc commit c33de89
Show file tree
Hide file tree
Showing 4 changed files with 14 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
import com.sopkathon.server.service.AnswerService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestHeader;
import org.springframework.web.bind.annotation.RestController;

Expand All @@ -18,7 +19,7 @@ public class AnswerController {
@DeleteMapping("/answer")
public ApiResponseDto deleteAnswer(
@RequestHeader("user-id") Long userId,
DeleteResultRequestDto requestDto
@RequestBody DeleteResultRequestDto requestDto
) {
answerService.deleteAnswer(userId, requestDto);
return ApiResponseDto.success(SuccessStatus.DELETE_RESULT);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,14 @@
package com.sopkathon.server.dto.request;

import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.Getter;
import lombok.NoArgsConstructor;

@Data
@NoArgsConstructor
@Getter
public class DeleteResultRequestDto {
private Long id;

}
8 changes: 5 additions & 3 deletions src/main/java/com/sopkathon/server/service/AnswerService.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import com.sopkathon.server.domain.User;
import com.sopkathon.server.dto.request.DeleteResultRequestDto;
import com.sopkathon.server.repository.AnswerRepository;
import com.sopkathon.server.repository.ResultRepository;
import com.sopkathon.server.repository.UserRepository;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;
Expand All @@ -14,15 +15,16 @@
public class AnswerService {
private final AnswerRepository answerRepository;
private final UserRepository userRepository;
private final ResultRepository resultRepository;

@Transactional
public void deleteAnswer(Long userId, DeleteResultRequestDto requestDto){

User user = userRepository.findById(userId).orElseThrow();

System.out.println("삭제 완료");
System.out.println(requestDto.getId());

answerRepository.deleteById(requestDto.getId());
System.out.println("삭제 !완료");
resultRepository.deleteById(requestDto.getId());

}
}
3 changes: 1 addition & 2 deletions src/main/java/com/sopkathon/server/service/MainService.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,9 @@ public class MainService {

public GetMainDto getMain(Long userId) {
User user = userRepository.findById(userId).orElseThrow();
System.out.println("11");

List<Result> byReceiver = resultRepository.findAllByReceiver(user);

System.out.println("11");
List<UserAnswers> userAnswers = byReceiver.stream()
.map(m -> new UserAnswers(
m.getId(),
Expand Down

0 comments on commit c33de89

Please sign in to comment.