Skip to content

Commit

Permalink
Merge pull request #134 from KAKAO-TOUR-API-CONTEST/devyj
Browse files Browse the repository at this point in the history
Devyj
  • Loading branch information
yyujin1231 authored Oct 8, 2024
2 parents 6742511 + 28b88a5 commit e89d7a3
Show file tree
Hide file tree
Showing 16 changed files with 591 additions and 118 deletions.
71 changes: 71 additions & 0 deletions src/main/generated/com/example/ai_jeju/domain/QTest.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.example.ai_jeju.domain;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;


/**
* QTest is a Querydsl query type for Test
*/
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QTest extends EntityPathBase<Test> {

private static final long serialVersionUID = 743624506L;

public static final QTest test = new QTest("test");

public final StringPath address = createString("address");

public final BooleanPath babySpareChair = createBoolean("babySpareChair");

public final StringPath breakTime = createString("breakTime");

public final NumberPath<Integer> categoryId = createNumber("categoryId", Integer.class);

public final StringPath imgSrc = createString("imgSrc");

public final NumberPath<Double> mapX = createNumber("mapX", Double.class);

public final NumberPath<Double> mapY = createNumber("mapY", Double.class);

public final StringPath name = createString("name");

public final StringPath nokidsdetail = createString("nokidsdetail");

public final StringPath noKidsZone = createString("noKidsZone");

public final StringPath operationTime = createString("operationTime");

public final BooleanPath parking = createBoolean("parking");

public final BooleanPath pet = createBoolean("pet");

public final BooleanPath playground = createBoolean("playground");

public final NumberPath<Long> storeId = createNumber("storeId", Long.class);

public final BooleanPath stroller = createBoolean("stroller");

public final BooleanPath strollerVal = createBoolean("strollerVal");

public final StringPath tel = createString("tel");

public QTest(String variable) {
super(Test.class, forVariable(variable));
}

public QTest(Path<? extends Test> path) {
super(path.getType(), path.getMetadata());
}

public QTest(PathMetadata metadata) {
super(Test.class, metadata);
}

}

71 changes: 71 additions & 0 deletions src/main/generated/com/example/ai_jeju/domain/QTest2.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@
package com.example.ai_jeju.domain;

import static com.querydsl.core.types.PathMetadataFactory.*;

import com.querydsl.core.types.dsl.*;

import com.querydsl.core.types.PathMetadata;
import javax.annotation.processing.Generated;
import com.querydsl.core.types.Path;


/**
* QTest2 is a Querydsl query type for Test2
*/
@Generated("com.querydsl.codegen.DefaultEntitySerializer")
public class QTest2 extends EntityPathBase<Test2> {

private static final long serialVersionUID = 1577523256L;

public static final QTest2 test2 = new QTest2("test2");

public final StringPath address = createString("address");

public final BooleanPath babySpareChair = createBoolean("babySpareChair");

public final NumberPath<Integer> categoryId = createNumber("categoryId", Integer.class);

public final StringPath imgSrc = createString("imgSrc");

public final NumberPath<Double> mapX = createNumber("mapX", Double.class);

public final NumberPath<Double> mapY = createNumber("mapY", Double.class);

public final StringPath name = createString("name");

public final NumberPath<Long> nearbyStoreId = createNumber("nearbyStoreId", Long.class);

public final StringPath nokidsdetail = createString("nokidsdetail");

public final StringPath noKidsZone = createString("noKidsZone");

public final StringPath operationTime = createString("operationTime");

public final BooleanPath parking = createBoolean("parking");

public final BooleanPath pet = createBoolean("pet");

public final BooleanPath playground = createBoolean("playground");

public final NumberPath<Long> storeId = createNumber("storeId", Long.class);

public final BooleanPath stroller = createBoolean("stroller");

public final BooleanPath strollerVal = createBoolean("strollerVal");

public final StringPath tel = createString("tel");

public QTest2(String variable) {
super(Test2.class, forVariable(variable));
}

public QTest2(Path<? extends Test2> path) {
super(path.getType(), path.getMetadata());
}

public QTest2(PathMetadata metadata) {
super(Test2.class, metadata);
}

}

43 changes: 43 additions & 0 deletions src/main/java/com/example/ai_jeju/controller/ChatController.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,16 +8,19 @@
import com.example.ai_jeju.repository.ChatMessageRepository;
import com.example.ai_jeju.repository.ChatRoomRepository;
import com.example.ai_jeju.service.ChatService;
import com.example.ai_jeju.service.NotificationService;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.MediaType;
import org.springframework.messaging.handler.annotation.Header;
import org.springframework.messaging.handler.annotation.MessageMapping;
import org.springframework.messaging.handler.annotation.SendTo;
import org.springframework.messaging.simp.SimpMessageSendingOperations;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.mvc.method.annotation.SseEmitter;
import software.amazon.ion.Timestamp;

import java.time.LocalDateTime;
Expand All @@ -33,6 +36,7 @@ public class ChatController {
private final ChatMessageRepository chatMessageRepository;
private final TokenProvider tokenProvider;
private final StompHandler stompHandler;
private final NotificationService notificationService;

@Autowired
private ChatService chatService;
Expand Down Expand Up @@ -94,12 +98,51 @@ public void message(ChatMessageDto messageDto, @Header("simpSessionAttributes")

log.info("Sending message to /sub/chat/room/" + messageDto.getRoomId() + ": " + messageDto.toString());
messagingTemplate.convertAndSend("/sub/chat/room/" + messageDto.getRoomId(), messageDto);
notificationService.notifyAllSubscribers(messageDto);

} catch (Exception e) {
log.error("Error processing message", e);
}
}


@GetMapping(value = "/api/chat/{roomId}/subscribe", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public SseEmitter subscribeToRoom(@PathVariable("roomId") Long roomId, @RequestParam(value = "token", required = false) String token) {
if (token != null && !token.isEmpty()) {
log.info("Received token: " + token);

String accessToken = token.replace("Bearer ", "");
log.info("Processed access token: " + accessToken);

if (tokenProvider.validToken(accessToken)) {
Long userId = tokenProvider.getUserId(accessToken);
log.info("User ID extracted from token: " + userId);

return notificationService.subscribeToRoom(userId);
} else {
log.error("Invalid token: " + accessToken);
throw new IllegalArgumentException("유효하지 않은 토큰입니다.");
}
} else {
log.error("No token provided.");
throw new IllegalArgumentException("토큰이 존재하지 않습니다.");
}
}



@PostMapping("/send-data/{id}")
public void sendData(@PathVariable("roomId") Long id) {
notificationService.notify(id, "data");
}

@GetMapping(value = "/notifications/subscribe/{userId}", produces = MediaType.TEXT_EVENT_STREAM_VALUE)
public SseEmitter subscribe(@PathVariable("roomId") Long userId) {
return notificationService.subscribeToRoom(userId);
}



@GetMapping("/chatroom")
public String chat(@RequestParam("roomId") String roomId, Model model) {
model.addAttribute("roomId", roomId);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,4 @@ public Emergency getFacilityById(@PathVariable("emergencyid") Long emergencyid)



}
}
32 changes: 32 additions & 0 deletions src/main/java/com/example/ai_jeju/controller/TestController.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
package com.example.ai_jeju.controller;


import com.example.ai_jeju.domain.Emergency;
import com.example.ai_jeju.domain.Test;
import com.example.ai_jeju.domain.Test2;
import com.example.ai_jeju.service.TestService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;

import java.util.List;

@Controller
public class TestController {
@Autowired
TestService testService;

@GetMapping("/tests")
public String getAllTests(Model model) {
List<Test2> tests = testService.getAllTests();
model.addAttribute("tests", tests);
return "imgtest"; // This will map to testImages.html in the templates folder
}

@GetMapping("/sse-test")
public String sseTestPage() {
return "test"; // test.html 파일을 반환
}
}
3 changes: 1 addition & 2 deletions src/main/java/com/example/ai_jeju/domain/Child.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,5 +50,4 @@ public void postPersist() {

}

}

}
89 changes: 89 additions & 0 deletions src/main/java/com/example/ai_jeju/domain/Test.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
package com.example.ai_jeju.domain;


import jakarta.persistence.*;
import lombok.*;

@Table(name="test")
@NoArgsConstructor(access= AccessLevel.PROTECTED) //기본생성자
@Getter
@Entity
@AllArgsConstructor // 모든 필드를 초기화하는 생성자
@Builder // 빌더 패턴
public class Test {

@Id
@GeneratedValue(strategy = GenerationType.IDENTITY)
@Column(name = "storeId", updatable = false, unique = true)
private Long storeId;

@Column(name = "name",updatable = false)
String name;

//이미지 소스
@Column(name = "imgSrc",updatable = false,nullable = true, columnDefinition = "TEXT")
String imgSrc;

@Column(name = "address",updatable = false,nullable = true)
String address;


@Column(name = "mapX",updatable = false,nullable = true)
Double mapX;

@Column(name = "mapY",updatable = false,nullable = true)
Double mapY;




/**
카테고리 value
1 : 숙박
2 : 음식점
3 : 레져
*/

//유모차 대여여부
@Column(name = "stroller",updatable = false,nullable = true)
Boolean stroller;

//유모차 편의성
@Column(name = "strollerVal",updatable = false,nullable = true)
Boolean strollerVal;

//아이 스페어 체어
@Column(name = "babySpareChair",updatable = false,nullable = true)
Boolean babySpareChair;

//아이 놀이방
@Column(name = "playground",updatable = false,nullable = true)
Boolean playground;

@Column(name = "noKidsZone",updatable = false,nullable = true)
String noKidsZone;

@Column(name = "nokidsdetail",updatable = false,nullable = true)
String nokidsdetail;

@Column(name = "categoryId",updatable = false,nullable = true)
Integer categoryId;

@Column(name = "operationTime",updatable = false,nullable = true , length = 1024)
String operationTime;

@Column(name = "breakTime",updatable = false,nullable = true , length = 1024)
String breakTime;

@Column(name = "tel",updatable = false,nullable = true)
String tel;

@Column(name = "pet",updatable = false,nullable = true)
Boolean pet;

@Column(name = "parking",updatable = false,nullable = true)
Boolean parking;



}
Loading

0 comments on commit e89d7a3

Please sign in to comment.