Skip to content

Commit

Permalink
Merge pull request #145 from Link-MIND/test
Browse files Browse the repository at this point in the history
[Merge] Test merge
  • Loading branch information
mmihye authored Jan 17, 2024
2 parents 7d7ff7e + 187a4b8 commit e60d869
Show file tree
Hide file tree
Showing 10 changed files with 100 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,8 @@ public ApiResponse signOut(@UserId Long userId) {

@DeleteMapping("/withdraw")
@ResponseStatus(HttpStatus.OK)
public ApiResponse withdraw(@UserId Long userId, @RequestHeader("Authorization") String socialAccessToken) {
authService.withdraw(userId,socialAccessToken);
public ApiResponse withdraw(@UserId Long userId) {
authService.withdraw(userId);
return ApiResponse.success(Success.DELETE_USER_SUCCESS);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
import java.util.List;

import com.app.toaster.controller.response.toast.WeekSiteDto;
import com.app.toaster.infrastructure.LinkRepository;
import com.app.toaster.service.link.LinkService;
import org.checkerframework.checker.units.qual.A;
import org.springframework.http.HttpStatus;
import org.springframework.validation.annotation.Validated;
Expand Down Expand Up @@ -41,6 +43,7 @@
public class ToastController {
private final ToastService toastService;
private final ParsingService parsingService;
private final LinkService linkService;

@PostMapping("/og")
@ResponseStatus(HttpStatus.OK)
Expand Down Expand Up @@ -86,7 +89,7 @@ public ApiResponse deleteToast( //나중에 softDelete로 변경
public ApiResponse<List<WeekSiteDto>> getWeekLinks(
@UserId Long userId
) {
return ApiResponse.success(Success.GET_LINKS_SUCCESS, toastService.getWeekLinks());
return ApiResponse.success(Success.GET_LINKS_SUCCESS, linkService.getWeekLinks());
}


Expand Down
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package com.app.toaster.controller.response.toast;

import com.app.toaster.domain.Toast;
import com.app.toaster.domain.Link;

public record WeekSiteDto(Long toastId, String toastTitle, String toastImg, String toastLink) {
public static WeekSiteDto of(Toast toast){
return new WeekSiteDto(toast.getId(), toast.getTitle(), toast.getThumbnailUrl(), toast.getLinkUrl());
public record WeekSiteDto(Long linkId, String linkTitle, String toastImg, String toastLink) {
public static WeekSiteDto of(Link link){
return new WeekSiteDto(link.getId(), link.getTitle(), link.getThumbnailUrl(), link.getLinkUrl());
}
}
33 changes: 33 additions & 0 deletions linkmind/src/main/java/com/app/toaster/domain/Link.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.app.toaster.domain;

import com.fasterxml.jackson.annotation.JsonRootName;
import com.fasterxml.jackson.databind.annotation.JsonNaming;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
import lombok.NoArgsConstructor;
@Getter
@Entity
@NoArgsConstructor(access = AccessLevel.PROTECTED)
public class Link {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
private Long Id;

private String title;

@Column(columnDefinition = "TEXT")
private String linkUrl;

@Column(columnDefinition = "TEXT")
private String thumbnailUrl;

@Builder
public Link(String title, String linkUrl, String thumbnailUrl) {
this.title = title;
this.linkUrl = linkUrl;
this.thumbnailUrl = thumbnailUrl;
}
}
13 changes: 3 additions & 10 deletions linkmind/src/main/java/com/app/toaster/domain/Toast.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,7 @@
import java.util.ArrayList;
import java.util.List;

import jakarta.persistence.CascadeType;
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 jakarta.persistence.OneToMany;
import jakarta.persistence.OneToOne;
import jakarta.persistence.*;
import lombok.AccessLevel;
import lombok.Builder;
import lombok.Getter;
Expand All @@ -37,10 +28,12 @@ public class Toast {

private String title;

@Column(columnDefinition = "TEXT")
private String linkUrl;

private Boolean isRead;

@Column(columnDefinition = "TEXT")
private String thumbnailUrl;

@Builder
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package com.app.toaster.infrastructure;

import com.app.toaster.domain.Link;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.stereotype.Repository;

import java.util.List;

@Repository
public interface LinkRepository extends JpaRepository<Link, Long> {

@Query("SELECT e FROM Link e ORDER BY FUNCTION('RAND') FETCH FIRST 3 ROWS ONLY")
List<Link> findRandom3Links();

}
Original file line number Diff line number Diff line change
Expand Up @@ -131,12 +131,12 @@ else if (socialType.toString() == "KAKAO") {
}

@Transactional
public void withdraw(Long userId, String accessToken) {
public void withdraw(Long userId) {
User user = userRepository.findByUserId(userId).orElseThrow(
()->new NotFoundException(Error.NOT_FOUND_USER_EXCEPTION, Error.NOT_FOUND_USER_EXCEPTION.getMessage()));
if (user.getSocialType() == SocialType.KAKAO){
kakaoSignInService.withdrawKakao(accessToken);
}
// if (user.getSocialType() == SocialType.KAKAO){
// kakaoSignInService.withdrawKakao(accessToken);
// }
try {
toastService.deleteAllToast(user);
}catch (IOException e){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,13 +34,14 @@ public LoginResult getKaKaoId(String accessToken) {
return LoginResult.of(objectMapper.convertValue(responseData.getBody(), Map.class).get("id").toString(), profileResponse==null?null:profileResponse.get("profile_image").toString(),
profileResponse==null?null:profileResponse.get("nickname").toString()); //프로필 이미지 허용 x시 null로 넘기기.
}
// 인가코드 나중에 서버에서 한번에 처리 하는 방식으로 변경. ux 이슈

public String withdrawKakao(String accessToken){
ResponseEntity<Object> responseData = requestKakaoServer(accessToken, Strategy.WITHDRAWAL);
ObjectMapper objectMapper = new ObjectMapper();
HashMap profileResponse = (HashMap)objectMapper.convertValue( responseData.getBody(),Map.class);
return profileResponse.get("id").toString();
}
// public String withdrawKakao(String accessToken){
// ResponseEntity<Object> responseData = requestKakaoServer(accessToken, Strategy.WITHDRAWAL);
// ObjectMapper objectMapper = new ObjectMapper();
// HashMap profileResponse = (HashMap)objectMapper.convertValue( responseData.getBody(),Map.class);
// return profileResponse.get("id").toString();
// }

private ResponseEntity<Object> requestKakaoServer(String accessToken, Strategy strategy){
RestTemplate restTemplate = new RestTemplate();
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package com.app.toaster.service.link;

import com.app.toaster.controller.response.toast.WeekSiteDto;
import com.app.toaster.infrastructure.LinkRepository;
import jakarta.persistence.criteria.CriteriaBuilder;
import lombok.RequiredArgsConstructor;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Random;
import java.util.Set;

@Service
@RequiredArgsConstructor
public class LinkService {

private final LinkRepository linkRepository;
public List<WeekSiteDto> getWeekLinks(){

return linkRepository.findRandom3Links().stream().map(WeekSiteDto::of).toList();
}



}
Original file line number Diff line number Diff line change
Expand Up @@ -138,10 +138,7 @@ public void deleteAllToast(User user) throws IOException {
(Toast::getId)).collect(Collectors.toList()));
}

public List<WeekSiteDto> getWeekLinks(){
return toastRepository.findAll().subList(0,Math.min(3,toastRepository.findAll().size()))
.stream().map(WeekSiteDto::of).toList();
}


private void checkCategoryIsEmpty(Toast toast, Long categoryId){
if (categoryId == null) {
Expand Down

0 comments on commit e60d869

Please sign in to comment.