Skip to content

Commit 9c1b7f7

Browse files
authored
Merge pull request #111 from CommitField/dev
dev merge to main
2 parents c39e243 + a6e2077 commit 9c1b7f7

File tree

101 files changed

+3243
-353
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

101 files changed

+3243
-353
lines changed

โ€Ž.gitignore

+3
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,9 @@ docker-compose.yaml
7575

7676
### dbํŒŒ์ผ
7777
db/
78+
.docker
79+
data/
80+
.dummy
7881

7982
### secret ํ”„๋กœํ•„
8083
application-secret.yml

โ€Žbuild.gradle.kts

+4-9
Original file line numberDiff line numberDiff line change
@@ -40,17 +40,16 @@ dependencies {
4040
compileOnly("org.projectlombok:lombok")
4141
annotationProcessor("org.projectlombok:lombok")
4242

43-
// DB
43+
//DB
4444
runtimeOnly("com.h2database:h2")
4545
runtimeOnly("com.mysql:mysql-connector-j")
4646
implementation("org.springframework.boot:spring-boot-starter-data-jpa")
4747

48-
// redis
48+
//redis
4949
implementation("org.springframework.boot:spring-boot-starter-data-redis")
50-
implementation("org.springframework.session:spring-session-data-redis")
50+
implementation ("org.redisson:redisson-spring-boot-starter:3.42.0") // redis message broker(lock)
51+
implementation ("org.springframework.session:spring-session-data-redis")
5152

52-
// actuator
53-
implementation("org.springframework.boot:spring-boot-starter-actuator")
5453

5554
// Security
5655
implementation("org.springframework.boot:spring-boot-starter-security")
@@ -59,10 +58,7 @@ dependencies {
5958

6059
//Swagger
6160
implementation("org.springdoc:springdoc-openapi-starter-webmvc-ui:2.7.0")
62-
63-
//Web Socket
6461
implementation("org.java-websocket:Java-WebSocket:1.5.2")
65-
implementation ("org.springframework:spring-messaging")
6662

6763
// JWT
6864
implementation("io.jsonwebtoken:jjwt-api:0.12.6")
@@ -80,7 +76,6 @@ dependencies {
8076
// Spring Security OAuth2
8177
implementation ("org.springframework.security:spring-security-oauth2-client:6.4.2") // Or the version you're using
8278
implementation ("org.springframework.security:spring-security-oauth2-core:6.4.2") // Or the version you're using
83-
8479
}
8580

8681
tasks.withType<Test> {

โ€Žsrc/main/java/cmf/commitField/CommitFieldApplication.java

+2-2
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
import org.springframework.boot.SpringApplication;
44
import org.springframework.boot.autoconfigure.SpringBootApplication;
55
import org.springframework.data.jpa.repository.config.EnableJpaAuditing;
6+
import org.springframework.scheduling.annotation.EnableScheduling;
67

78
@SpringBootApplication
89
@EnableJpaAuditing
10+
@EnableScheduling
911
public class CommitFieldApplication {
10-
1112
public static void main(String[] args) {
1213
SpringApplication.run(CommitFieldApplication.class, args);
1314
}
14-
1515
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package cmf.commitField.domain.File.service;
2+
3+
import org.springframework.boot.context.properties.ConfigurationProperties;
4+
import org.springframework.stereotype.Component;
5+
6+
//@Configuration
7+
@Component
8+
@ConfigurationProperties(prefix = "custom.file")
9+
public class FileProperties {
10+
private String uploadDir;
11+
12+
public String getUploadDir() {
13+
return uploadDir;
14+
}
15+
16+
public void setUploadDir(String uploadDir) {
17+
this.uploadDir = uploadDir;
18+
}
19+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
1+
package cmf.commitField.domain.File.service;
2+
3+
import org.springframework.stereotype.Service;
4+
import org.springframework.web.multipart.MultipartFile;
5+
6+
import java.io.IOException;
7+
import java.nio.file.Files;
8+
import java.nio.file.Path;
9+
import java.nio.file.Paths;
10+
import java.nio.file.StandardCopyOption;
11+
12+
@Service
13+
public class FileService {
14+
15+
// resources/static/uploads ํด๋” ๊ฒฝ๋กœ
16+
private final String UPLOAD_DIR = "src/main/resources/static/uploads"; // ์ƒ๋Œ€ ๊ฒฝ๋กœ
17+
18+
// ํŒŒ์ผ ์ €์žฅ ๋ฉ”์†Œ๋“œ
19+
public String saveFile(MultipartFile file) throws IOException {
20+
// ํŒŒ์ผ ์ด๋ฆ„์„ ์œ ๋‹ˆํฌํ•˜๊ฒŒ ์ƒ์„ฑ
21+
String filename = System.currentTimeMillis() + "_" + file.getOriginalFilename();
22+
23+
// ํŒŒ์ผ ๊ฒฝ๋กœ ์ƒ์„ฑ
24+
Path path = Paths.get(UPLOAD_DIR, filename); // static/uploads ํด๋”์— ์ €์žฅ
25+
26+
// ๋””๋ ‰ํ† ๋ฆฌ๊ฐ€ ์กด์žฌํ•˜์ง€ ์•Š์œผ๋ฉด ์ƒ์„ฑ
27+
Files.createDirectories(path.getParent());
28+
29+
// ํŒŒ์ผ ์ €์žฅ
30+
Files.copy(file.getInputStream(), path, StandardCopyOption.REPLACE_EXISTING);
31+
32+
// ์ €์žฅ๋œ ํŒŒ์ผ์˜ URL ๋ฐ˜ํ™˜ (์›น์—์„œ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” ๊ฒฝ๋กœ)
33+
return "/uploads/" + filename; // ํด๋ผ์ด์–ธํŠธ๊ฐ€ ์ ‘๊ทผํ•  ์ˆ˜ ์žˆ๋Š” URL ๋ฐ˜ํ™˜
34+
}
35+
}
36+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package cmf.commitField.domain.Timer.controller;
2+
3+
import org.springframework.web.bind.annotation.RestController;
4+
5+
@RestController
6+
public class TimerController {
7+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
package cmf.commitField.domain.Timer.dto;
2+
3+
import lombok.Getter;
4+
import lombok.Setter;
5+
6+
import java.time.LocalDateTime;
7+
8+
@Getter
9+
@Setter
10+
public class TimerDto {
11+
private LocalDateTime startTime;
12+
private LocalDateTime endTime;
13+
private String totalTime;
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
package cmf.commitField.domain.Timer.entity;
2+
3+
import cmf.commitField.domain.user.entity.User;
4+
import jakarta.persistence.GeneratedValue;
5+
import jakarta.persistence.GenerationType;
6+
import jakarta.persistence.Id;
7+
import lombok.AllArgsConstructor;
8+
import lombok.Getter;
9+
import lombok.NoArgsConstructor;
10+
import lombok.Setter;
11+
12+
import java.time.LocalDateTime;
13+
14+
@Getter
15+
@Setter
16+
@NoArgsConstructor
17+
@AllArgsConstructor
18+
public class Timer {
19+
@Id
20+
@GeneratedValue(strategy = GenerationType.IDENTITY)
21+
private Long id;
22+
23+
private User user;
24+
private LocalDateTime startTime;
25+
private LocalDateTime endTime;
26+
private String totalTime;
27+
28+
// ํƒ€์ด๋จธ ์ข…๋ฃŒ ๋ฉ”์„œ๋“œ
29+
public void stop(LocalDateTime endTime, String totalTime) {
30+
this.endTime = endTime;
31+
this.totalTime = totalTime;
32+
}
33+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
package cmf.commitField.domain.Timer.service;
2+
3+
import org.springframework.stereotype.Service;
4+
5+
@Service
6+
public class TimerService {
7+
8+
}

โ€Žsrc/main/java/cmf/commitField/domain/admin/controller/ApiV1PetImgController.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
import java.util.stream.Collectors;
1313

1414
@RestController
15-
@RequestMapping("/api/v1/admin/pet")
15+
@RequestMapping("/api/v1")
1616
@RequiredArgsConstructor
1717
public class ApiV1PetImgController {
1818
private final S3Client s3Client;

โ€Žsrc/main/java/cmf/commitField/domain/chat/chatMessage/controller/ChatController.java

-55
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package cmf.commitField.domain.chat.chatMessage.controller;
2+
3+
import cmf.commitField.domain.chat.chatMessage.controller.request.ChatMsgRequest;
4+
import cmf.commitField.domain.chat.chatMessage.controller.response.ChatMsgResponse;
5+
import cmf.commitField.domain.chat.chatMessage.dto.ChatMsgDto;
6+
import cmf.commitField.domain.chat.chatMessage.service.ChatMessageService;
7+
import cmf.commitField.domain.user.entity.CustomOAuth2User;
8+
import cmf.commitField.global.error.ErrorCode;
9+
import cmf.commitField.global.globalDto.GlobalResponse;
10+
import cmf.commitField.global.security.LoginCheck;
11+
import jakarta.validation.Valid;
12+
import lombok.RequiredArgsConstructor;
13+
import org.springframework.security.core.Authentication;
14+
import org.springframework.security.core.context.SecurityContextHolder;
15+
import org.springframework.security.oauth2.client.authentication.OAuth2AuthenticationToken;
16+
import org.springframework.web.bind.annotation.*;
17+
18+
import java.util.List;
19+
20+
@RestController
21+
@RequiredArgsConstructor
22+
@RequestMapping("/chat")
23+
public class ChatMessageController {
24+
25+
private final ChatMessageService chatMessageService;
26+
27+
@PostMapping("/msg/{roomId}")
28+
@LoginCheck
29+
public GlobalResponse<Object> sendChat(
30+
@PathVariable Long roomId,
31+
@RequestBody @Valid ChatMsgRequest message) {
32+
33+
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
34+
if (!(authentication instanceof OAuth2AuthenticationToken)) {
35+
return GlobalResponse.error(ErrorCode.NOT_AUTHENTICATED);
36+
}
37+
38+
CustomOAuth2User principal = (CustomOAuth2User) authentication.getPrincipal();
39+
Long userId = principal.getId(); // OAuth2 ๋กœ๊ทธ์ธํ•œ ์œ ์ €์˜ ID ๊ฐ€์ ธ์˜ค๊ธฐ
40+
41+
if (message == null || message.getMessage().trim().isEmpty()) {
42+
return GlobalResponse.error(ErrorCode.EMPTY_MESSAGE);
43+
}
44+
45+
ChatMsgResponse response = chatMessageService.sendMessage(message, userId, roomId);
46+
return GlobalResponse.success("์ฑ„ํŒ… ๋ฉ”์‹œ์ง€ ๋ณด๋‚ด๊ธฐ ์„ฑ๊ณต", response);
47+
}
48+
49+
@GetMapping("/msg/{roomId}")
50+
@LoginCheck
51+
public GlobalResponse<Object> getChatList(
52+
@PathVariable Long roomId,
53+
@RequestParam(required = false) Long lastId) {
54+
55+
Authentication authentication = SecurityContextHolder.getContext().getAuthentication();
56+
if (!(authentication instanceof OAuth2AuthenticationToken)) {
57+
return GlobalResponse.error(ErrorCode.NOT_AUTHENTICATED);
58+
}
59+
60+
CustomOAuth2User principal = (CustomOAuth2User) authentication.getPrincipal();
61+
Long userId = principal.getId(); // OAuth2 ๋กœ๊ทธ์ธํ•œ ์œ ์ €์˜ ID ๊ฐ€์ ธ์˜ค๊ธฐ
62+
63+
List<ChatMsgDto> roomChatMsgList = chatMessageService.getRoomChatMsgList(roomId, userId, lastId);
64+
if (roomChatMsgList == null || roomChatMsgList.isEmpty()) {
65+
return GlobalResponse.error(ErrorCode.CHAT_NOT_FOUND);
66+
}
67+
68+
return GlobalResponse.success("ํ•ด๋‹น ์ฑ„ํŒ…๋ฐฉ์˜ ๋ฉ”์‹œ์ง€๋“ค์„ ์กฐํšŒํ•˜์˜€์Šต๋‹ˆ๋‹ค.", roomChatMsgList);
69+
}
70+
}
71+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
package cmf.commitField.domain.chat.chatMessage.controller.request;
2+
3+
import jakarta.validation.constraints.NotEmpty;
4+
import lombok.AllArgsConstructor;
5+
import lombok.Getter;
6+
import lombok.NoArgsConstructor;
7+
import org.hibernate.validator.constraints.Length;
8+
9+
@Getter
10+
@AllArgsConstructor
11+
@NoArgsConstructor
12+
public class ChatMsgRequest {
13+
@NotEmpty
14+
@Length(max = 300)
15+
private String message;
16+
17+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package cmf.commitField.domain.chat.chatMessage.controller.response;
2+
3+
import lombok.*;
4+
5+
import java.time.LocalDateTime;
6+
7+
@Getter
8+
@Setter
9+
@NoArgsConstructor
10+
@AllArgsConstructor
11+
@Builder
12+
public class ChatMsgResponse {
13+
private Long roomId;
14+
//์‚ฌ์šฉ์ž(user)
15+
private String from;
16+
private String message;
17+
private LocalDateTime sendAt;
18+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
package cmf.commitField.domain.chat.chatMessage.dto;
2+
3+
import lombok.*;
4+
5+
import java.time.LocalDateTime;
6+
7+
@Getter
8+
@Setter
9+
@NoArgsConstructor
10+
@AllArgsConstructor
11+
@Builder
12+
public class ChatMsgDto {
13+
private Long chatMsgId;
14+
private Long userId;
15+
private String nickname;
16+
private String message;
17+
private LocalDateTime sendAt;
18+
}

โ€Žsrc/main/java/cmf/commitField/domain/chat/chatMessage/entity/ChatMessage.java renamed to โ€Žsrc/main/java/cmf/commitField/domain/chat/chatMessage/entity/ChatMsg.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
@Setter
1717
@NoArgsConstructor(access = AccessLevel.PROTECTED)
1818
@AllArgsConstructor(access = AccessLevel.PROTECTED)
19-
public class ChatMessage extends BaseEntity {
19+
public class ChatMsg extends BaseEntity {
2020

2121
private String message;
2222

0 commit comments

Comments
ย (0)