backendS
This commit is contained in:
49
src/dbtable.txt
Normal file
49
src/dbtable.txt
Normal file
@ -0,0 +1,49 @@
|
|||||||
|
-- 사용자 계정 테이블
|
||||||
|
CREATE TABLE USERS (
|
||||||
|
USER_ID NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, -- 사용자 고유 ID
|
||||||
|
USERNAME VARCHAR2(50) UNIQUE NOT NULL, -- 사용자 이름(아이디)
|
||||||
|
PASSWORD VARCHAR2(255) NOT NULL, -- 암호(암호화 저장)
|
||||||
|
LAST_LOGIN TIMESTAMP, -- 마지막 로그인 시간
|
||||||
|
CREATED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP -- 계정 생성 시간
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 상태 관리 테이블
|
||||||
|
CREATE TABLE STATES (
|
||||||
|
STATE_ID NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, -- 상태 고유 ID
|
||||||
|
USER_ID NUMBER NOT NULL, -- 사용자 ID (foreign key)
|
||||||
|
STATE_VALUE CHAR(1) CHECK (STATE_VALUE IN ('A', 'B', 'C', 'D')), -- 상태값
|
||||||
|
GPS_LATITUDE NUMBER(10, 8), -- GPS 위도
|
||||||
|
GPS_LONGITUDE NUMBER(11, 8), -- GPS 경도
|
||||||
|
ADDRESS VARCHAR2(255), -- GPS 기준 주소
|
||||||
|
UPDATED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- 상태 갱신 시간
|
||||||
|
CONSTRAINT FK_STATE_USER FOREIGN KEY (USER_ID) REFERENCES USERS(USER_ID)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 이미지 업로드 테이블
|
||||||
|
CREATE TABLE IMAGES (
|
||||||
|
IMAGE_ID NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, -- 이미지 고유 ID
|
||||||
|
USER_ID NUMBER NOT NULL, -- 사용자 ID (foreign key)
|
||||||
|
ORIGINAL_IMAGE_PATH VARCHAR2(255) NOT NULL, -- 원본 이미지 경로
|
||||||
|
THUMBNAIL_IMAGE_PATH VARCHAR2(255) NOT NULL, -- 썸네일 이미지 경로
|
||||||
|
UPLOADED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- 업로드 시간
|
||||||
|
CONSTRAINT FK_IMAGE_USER FOREIGN KEY (USER_ID) REFERENCES USERS(USER_ID)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 권한 관리 테이블
|
||||||
|
CREATE TABLE PERMISSIONS (
|
||||||
|
PERMISSION_ID NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, -- 권한 고유 ID
|
||||||
|
USER_ID NUMBER NOT NULL, -- 사용자 ID (foreign key)
|
||||||
|
CAMERA_PERMISSION CHAR(1) DEFAULT 'N' CHECK (CAMERA_PERMISSION IN ('Y', 'N')), -- 카메라 권한 여부
|
||||||
|
GPS_PERMISSION CHAR(1) DEFAULT 'N' CHECK (GPS_PERMISSION IN ('Y', 'N')), -- GPS 권한 여부
|
||||||
|
UPDATED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- 권한 갱신 시간
|
||||||
|
CONSTRAINT FK_PERMISSION_USER FOREIGN KEY (USER_ID) REFERENCES USERS(USER_ID)
|
||||||
|
);
|
||||||
|
|
||||||
|
-- 로그 기록 테이블
|
||||||
|
CREATE TABLE LOGS (
|
||||||
|
LOG_ID NUMBER GENERATED BY DEFAULT AS IDENTITY PRIMARY KEY, -- 로그 고유 ID
|
||||||
|
USER_ID NUMBER NOT NULL, -- 사용자 ID (foreign key)
|
||||||
|
ACTION VARCHAR2(100) NOT NULL, -- 수행된 작업
|
||||||
|
CREATED_AT TIMESTAMP DEFAULT CURRENT_TIMESTAMP, -- 작업 시간
|
||||||
|
CONSTRAINT FK_LOG_USER FOREIGN KEY (USER_ID) REFERENCES USERS(USER_ID)
|
||||||
|
);
|
@ -1,4 +1,4 @@
|
|||||||
package com.example.backend.controller;
|
/* package com.example.backend.controller;
|
||||||
|
|
||||||
import com.example.backend.dto.LoginRequest;
|
import com.example.backend.dto.LoginRequest;
|
||||||
import com.example.backend.service.AuthService;
|
import com.example.backend.service.AuthService;
|
||||||
@ -16,4 +16,4 @@ public class AuthController {
|
|||||||
public String login(@RequestBody LoginRequest request) {
|
public String login(@RequestBody LoginRequest request) {
|
||||||
return authService.login(request.getUsername(), request.getPassword());
|
return authService.login(request.getUsername(), request.getPassword());
|
||||||
}
|
}
|
||||||
}
|
} */
|
@ -1,5 +1,32 @@
|
|||||||
package com.example.backend.controller;
|
package com.example.backend.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.example.backend.dto.ImageDto;
|
||||||
|
import com.example.backend.service.ImageService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/images")
|
||||||
public class ImageController {
|
public class ImageController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ImageService imageService;
|
||||||
|
|
||||||
|
@GetMapping("/{userId}")
|
||||||
|
public ResponseEntity<List<ImageDto>> getUserImages(@PathVariable Long userId) {
|
||||||
|
List<ImageDto> images = imageService.getImagesByUserId(userId);
|
||||||
|
return ResponseEntity.ok(images);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PostMapping("/upload")
|
||||||
|
public ResponseEntity<ImageDto> uploadImage(@RequestParam("userId") Long userId, @RequestParam("file") MultipartFile file) throws IOException {
|
||||||
|
ImageDto uploadedImage = imageService.uploadImage(userId, file);
|
||||||
|
return ResponseEntity.ok(uploadedImage);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,27 @@
|
|||||||
package com.example.backend.controller;
|
package com.example.backend.controller;
|
||||||
|
|
||||||
|
import com.example.backend.dto.PermissionDto;
|
||||||
|
import com.example.backend.service.PermissionService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.http.ResponseEntity;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/api/permissions")
|
||||||
public class PermissionController {
|
public class PermissionController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private PermissionService permissionService;
|
||||||
|
|
||||||
|
@GetMapping("/{userId}")
|
||||||
|
public ResponseEntity<PermissionDto> getPermissions(@PathVariable Long userId) {
|
||||||
|
PermissionDto permissions = permissionService.getPermissionsByUserId(userId);
|
||||||
|
return ResponseEntity.ok(permissions);
|
||||||
|
}
|
||||||
|
|
||||||
|
@PutMapping("/{userId}")
|
||||||
|
public ResponseEntity<Void> updatePermissions(@PathVariable Long userId, @RequestBody PermissionDto permissionDto) {
|
||||||
|
permissionService.updatePermissions(userId, permissionDto);
|
||||||
|
return ResponseEntity.noContent().build();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,19 @@
|
|||||||
package com.example.backend.controller;
|
package com.example.backend.controller;
|
||||||
|
|
||||||
|
import com.example.backend.entity.State;
|
||||||
|
import com.example.backend.service.StateService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/states")
|
||||||
public class StateController {
|
public class StateController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private StateService stateService;
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public State createState(@RequestBody State state) {
|
||||||
|
return stateService.createState(state);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -0,0 +1,25 @@
|
|||||||
|
package com.example.backend.controller;
|
||||||
|
|
||||||
|
|
||||||
|
import com.example.backend.entity.User;
|
||||||
|
import com.example.backend.service.UserService;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.web.bind.annotation.*;
|
||||||
|
|
||||||
|
@RestController
|
||||||
|
@RequestMapping("/users")
|
||||||
|
public class UserController {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserService userService;
|
||||||
|
|
||||||
|
@PostMapping
|
||||||
|
public User createUser(@RequestBody User user) {
|
||||||
|
return userService.createUser(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
@GetMapping("/{username}")
|
||||||
|
public User getUserByUsername(@PathVariable String username) {
|
||||||
|
return userService.findByUsername(username);
|
||||||
|
}
|
||||||
|
}
|
50
src/main/java/com/example/backend/dto/ImageDto.java
Normal file
50
src/main/java/com/example/backend/dto/ImageDto.java
Normal file
@ -0,0 +1,50 @@
|
|||||||
|
package com.example.backend.dto;
|
||||||
|
|
||||||
|
public class ImageDto {
|
||||||
|
private Long id;
|
||||||
|
private Long userId;
|
||||||
|
private String originalImagePath;
|
||||||
|
private String thumbnailImagePath;
|
||||||
|
private String uploadedAt;
|
||||||
|
|
||||||
|
// Getters and Setters
|
||||||
|
public Long getId() {
|
||||||
|
return id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setId(Long id) {
|
||||||
|
this.id = id;
|
||||||
|
}
|
||||||
|
|
||||||
|
public Long getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(Long userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getOriginalImagePath() {
|
||||||
|
return originalImagePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setOriginalImagePath(String originalImagePath) {
|
||||||
|
this.originalImagePath = originalImagePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getThumbnailImagePath() {
|
||||||
|
return thumbnailImagePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setThumbnailImagePath(String thumbnailImagePath) {
|
||||||
|
this.thumbnailImagePath = thumbnailImagePath;
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getUploadedAt() {
|
||||||
|
return uploadedAt;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUploadedAt(String uploadedAt) {
|
||||||
|
this.uploadedAt = uploadedAt;
|
||||||
|
}
|
||||||
|
}
|
33
src/main/java/com/example/backend/dto/PermissionDto.java
Normal file
33
src/main/java/com/example/backend/dto/PermissionDto.java
Normal file
@ -0,0 +1,33 @@
|
|||||||
|
package com.example.backend.dto;
|
||||||
|
|
||||||
|
|
||||||
|
public class PermissionDto {
|
||||||
|
private Long userId;
|
||||||
|
private boolean cameraPermission;
|
||||||
|
private boolean gpsPermission;
|
||||||
|
|
||||||
|
// Getters and Setters
|
||||||
|
public Long getUserId() {
|
||||||
|
return userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setUserId(Long userId) {
|
||||||
|
this.userId = userId;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isCameraPermission() {
|
||||||
|
return cameraPermission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setCameraPermission(boolean cameraPermission) {
|
||||||
|
this.cameraPermission = cameraPermission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isGpsPermission() {
|
||||||
|
return gpsPermission;
|
||||||
|
}
|
||||||
|
|
||||||
|
public void setGpsPermission(boolean gpsPermission) {
|
||||||
|
this.gpsPermission = gpsPermission;
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,30 @@
|
|||||||
package com.example.backend.entity;
|
package com.example.backend.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Table(name = "images")
|
||||||
public class Image {
|
public class Image {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id; // 이미지 고유 ID
|
||||||
|
|
||||||
|
@Column(name = "user_id", nullable = false)
|
||||||
|
private Long userId; // 사용자 ID
|
||||||
|
|
||||||
|
@Column(name = "original_image_path", nullable = false)
|
||||||
|
private String originalImagePath; // 원본 이미지 경로
|
||||||
|
|
||||||
|
@Column(name = "thumbnail_image_path", nullable = false)
|
||||||
|
private String thumbnailImagePath; // 썸네일 이미지 경로
|
||||||
|
|
||||||
|
@Column(name = "uploaded_at", nullable = false)
|
||||||
|
private LocalDateTime uploadedAt; // 업로드 시간
|
||||||
}
|
}
|
||||||
|
36
src/main/java/com/example/backend/entity/Permission.java
Normal file
36
src/main/java/com/example/backend/entity/Permission.java
Normal file
@ -0,0 +1,36 @@
|
|||||||
|
package com.example.backend.entity;
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.Getter;
|
||||||
|
import lombok.Setter;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Getter
|
||||||
|
@Setter
|
||||||
|
@Table(name = "permissions")
|
||||||
|
public class Permission {
|
||||||
|
|
||||||
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id; // 권한 고유 ID
|
||||||
|
|
||||||
|
@Column(name = "user_id", nullable = false)
|
||||||
|
private Long userId; // 사용자 ID
|
||||||
|
|
||||||
|
@Column(name = "camera_permission", nullable = false)
|
||||||
|
private Boolean cameraPermission; // 카메라 권한 여부
|
||||||
|
|
||||||
|
@Column(name = "gps_permission", nullable = false)
|
||||||
|
private Boolean gpsPermission; // GPS 권한 여부
|
||||||
|
|
||||||
|
public boolean isCameraPermission() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'isCameraPermission'");
|
||||||
|
}
|
||||||
|
|
||||||
|
public boolean isGpsPermission() {
|
||||||
|
// TODO Auto-generated method stub
|
||||||
|
throw new UnsupportedOperationException("Unimplemented method 'isGpsPermission'");
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
@ -1,5 +0,0 @@
|
|||||||
package com.example.backend.entity;
|
|
||||||
|
|
||||||
public class Permissions {
|
|
||||||
|
|
||||||
}
|
|
@ -1,5 +1,29 @@
|
|||||||
package com.example.backend.entity;
|
package com.example.backend.entity;
|
||||||
|
|
||||||
|
|
||||||
|
import jakarta.persistence.*;
|
||||||
|
import lombok.*;
|
||||||
|
|
||||||
|
@Entity
|
||||||
|
@Table(name = "states")
|
||||||
|
@Data
|
||||||
|
@NoArgsConstructor
|
||||||
|
@AllArgsConstructor
|
||||||
|
@Builder
|
||||||
public class State {
|
public class State {
|
||||||
|
|
||||||
}
|
@Id
|
||||||
|
@GeneratedValue(strategy = GenerationType.IDENTITY)
|
||||||
|
private Long id;
|
||||||
|
|
||||||
|
@ManyToOne
|
||||||
|
@JoinColumn(name = "user_id", nullable = false)
|
||||||
|
private User user;
|
||||||
|
|
||||||
|
@Column(nullable = false)
|
||||||
|
private String stateValue;
|
||||||
|
|
||||||
|
private Double gpsLatitude;
|
||||||
|
private Double gpsLongitude;
|
||||||
|
private String address;
|
||||||
|
}
|
@ -21,5 +21,5 @@ public class User {
|
|||||||
@Column(nullable = false)
|
@Column(nullable = false)
|
||||||
private String password;
|
private String password;
|
||||||
|
|
||||||
private Date lastLogin;
|
private Date lastLogin;
|
||||||
}
|
}
|
@ -1,5 +1,11 @@
|
|||||||
package com.example.backend.repository;
|
package com.example.backend.repository;
|
||||||
|
|
||||||
public class ImageRepository {
|
import com.example.backend.entity.Image;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
|
||||||
|
import java.util.List;
|
||||||
|
|
||||||
|
public interface ImageRepository extends JpaRepository<Image, Long> {
|
||||||
|
// 사용자 ID를 기반으로 이미지 목록 조회
|
||||||
|
List<Image> findByUserId(Long userId);
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,9 @@
|
|||||||
package com.example.backend.repository;
|
package com.example.backend.repository;
|
||||||
|
|
||||||
public class PermissionRepository {
|
import com.example.backend.entity.Permission;
|
||||||
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
}
|
|
||||||
|
public interface PermissionRepository extends JpaRepository<Permission, Long> {
|
||||||
|
// 사용자 ID를 기반으로 권한 조회
|
||||||
|
Permission findByUserId(Long userId);
|
||||||
|
}
|
@ -1,5 +1,8 @@
|
|||||||
package com.example.backend.repository;
|
package com.example.backend.repository;
|
||||||
|
|
||||||
public class StateRepository {
|
import org.springframework.data.jpa.repository.JpaRepository;
|
||||||
|
import com.example.backend.entity.State;
|
||||||
|
|
||||||
|
|
||||||
|
public interface StateRepository extends JpaRepository<State, Long> {
|
||||||
}
|
}
|
||||||
|
@ -5,5 +5,5 @@ import org.springframework.data.jpa.repository.JpaRepository;
|
|||||||
import java.util.Optional;
|
import java.util.Optional;
|
||||||
|
|
||||||
public interface UserRepository extends JpaRepository<User, Long> {
|
public interface UserRepository extends JpaRepository<User, Long> {
|
||||||
Optional<User> findByUsername(String username);
|
User findByUsername(String username);
|
||||||
}
|
}
|
@ -1,4 +1,4 @@
|
|||||||
package com.example.backend.service;
|
/* package com.example.backend.service;
|
||||||
|
|
||||||
import com.example.backend.config.JwtTokenProvider;
|
import com.example.backend.config.JwtTokenProvider;
|
||||||
import com.example.backend.entity.User;
|
import com.example.backend.entity.User;
|
||||||
@ -22,4 +22,4 @@ public class AuthService {
|
|||||||
}
|
}
|
||||||
return jwtTokenProvider.createToken(user.getUsername(), user.getId());
|
return jwtTokenProvider.createToken(user.getUsername(), user.getId());
|
||||||
}
|
}
|
||||||
}
|
} */
|
@ -1,5 +1,77 @@
|
|||||||
package com.example.backend.service;
|
package com.example.backend.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.example.backend.dto.ImageDto;
|
||||||
|
import com.example.backend.entity.Image;
|
||||||
|
import com.example.backend.repository.ImageRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
|
import java.io.File;
|
||||||
|
import java.io.IOException;
|
||||||
|
import java.time.LocalDateTime;
|
||||||
|
import java.time.format.DateTimeFormatter;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.stream.Collectors;
|
||||||
|
|
||||||
|
@Service
|
||||||
public class ImageService {
|
public class ImageService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private ImageRepository imageRepository;
|
||||||
|
|
||||||
|
private final String uploadDir = "uploads/";
|
||||||
|
|
||||||
|
// 사용자 ID로 이미지 목록 조회
|
||||||
|
public List<ImageDto> getImagesByUserId(Long userId) {
|
||||||
|
List<Image> images = imageRepository.findByUserId(userId);
|
||||||
|
return images.stream().map(image -> {
|
||||||
|
ImageDto dto = new ImageDto();
|
||||||
|
dto.setId(image.getId());
|
||||||
|
dto.setUserId(image.getUserId());
|
||||||
|
dto.setOriginalImagePath(image.getOriginalImagePath());
|
||||||
|
dto.setThumbnailImagePath(image.getThumbnailImagePath());
|
||||||
|
dto.setUploadedAt(image.getUploadedAt().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||||
|
return dto;
|
||||||
|
}).collect(Collectors.toList());
|
||||||
|
}
|
||||||
|
|
||||||
|
// 이미지 업로드 처리
|
||||||
|
public ImageDto uploadImage(Long userId, MultipartFile file) throws IOException {
|
||||||
|
// 업로드 디렉토리 생성 (존재하지 않을 경우)
|
||||||
|
File uploadDirFile = new File(uploadDir);
|
||||||
|
if (!uploadDirFile.exists()) {
|
||||||
|
uploadDirFile.mkdirs();
|
||||||
|
}
|
||||||
|
|
||||||
|
// 원본 파일 저장
|
||||||
|
String originalFilename = file.getOriginalFilename();
|
||||||
|
String originalFilePath = uploadDir + LocalDateTime.now().toString() + "_" + originalFilename;
|
||||||
|
File originalFile = new File(originalFilePath);
|
||||||
|
file.transferTo(originalFile);
|
||||||
|
|
||||||
|
// 썸네일 파일 생성 (임시 로직)
|
||||||
|
String thumbnailFilePath = originalFilePath.replace(".jpg", "_thumb.jpg");
|
||||||
|
File thumbnailFile = new File(thumbnailFilePath);
|
||||||
|
// 실제 썸네일 생성 로직이 필요
|
||||||
|
thumbnailFile.createNewFile();
|
||||||
|
|
||||||
|
// DB에 저장
|
||||||
|
Image image = new Image();
|
||||||
|
image.setUserId(userId);
|
||||||
|
image.setOriginalImagePath(originalFilePath);
|
||||||
|
image.setThumbnailImagePath(thumbnailFilePath);
|
||||||
|
image.setUploadedAt(LocalDateTime.now());
|
||||||
|
image = imageRepository.save(image);
|
||||||
|
|
||||||
|
// DTO 반환
|
||||||
|
ImageDto dto = new ImageDto();
|
||||||
|
dto.setId(image.getId());
|
||||||
|
dto.setUserId(image.getUserId());
|
||||||
|
dto.setOriginalImagePath(image.getOriginalImagePath());
|
||||||
|
dto.setThumbnailImagePath(image.getThumbnailImagePath());
|
||||||
|
dto.setUploadedAt(image.getUploadedAt().format(DateTimeFormatter.ofPattern("yyyy-MM-dd HH:mm:ss")));
|
||||||
|
return dto;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -1,5 +1,40 @@
|
|||||||
package com.example.backend.service;
|
package com.example.backend.service;
|
||||||
|
|
||||||
|
|
||||||
|
import com.example.backend.dto.PermissionDto;
|
||||||
|
import com.example.backend.entity.Permission;
|
||||||
|
import com.example.backend.repository.PermissionRepository;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
|
||||||
|
@Service
|
||||||
public class PermissionService {
|
public class PermissionService {
|
||||||
|
|
||||||
}
|
@Autowired
|
||||||
|
private PermissionRepository permissionRepository;
|
||||||
|
|
||||||
|
// 사용자 ID로 권한 정보 조회
|
||||||
|
public PermissionDto getPermissionsByUserId(Long userId) {
|
||||||
|
Permission permission = permissionRepository.findByUserId(userId);
|
||||||
|
if (permission == null) {
|
||||||
|
throw new IllegalArgumentException("해당 사용자 ID에 대한 권한 정보가 없습니다: " + userId);
|
||||||
|
}
|
||||||
|
PermissionDto permissionDto = new PermissionDto();
|
||||||
|
permissionDto.setUserId(permission.getUserId());
|
||||||
|
permissionDto.setCameraPermission(permission.isCameraPermission());
|
||||||
|
permissionDto.setGpsPermission(permission.isGpsPermission());
|
||||||
|
return permissionDto;
|
||||||
|
}
|
||||||
|
|
||||||
|
// 사용자 권한 정보 업데이트
|
||||||
|
public void updatePermissions(Long userId, PermissionDto permissionDto) {
|
||||||
|
Permission permission = permissionRepository.findByUserId(userId);
|
||||||
|
if (permission == null) {
|
||||||
|
permission = new Permission();
|
||||||
|
permission.setUserId(userId);
|
||||||
|
}
|
||||||
|
permission.setCameraPermission(permissionDto.isCameraPermission());
|
||||||
|
permission.setGpsPermission(permissionDto.isGpsPermission());
|
||||||
|
permissionRepository.save(permission);
|
||||||
|
}
|
||||||
|
}
|
@ -1,5 +1,17 @@
|
|||||||
package com.example.backend.service;
|
package com.example.backend.service;
|
||||||
|
|
||||||
|
import com.example.backend.entity.State;
|
||||||
|
import com.example.backend.repository.StateRepository;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
@Service
|
||||||
public class StateService {
|
public class StateService {
|
||||||
|
|
||||||
}
|
@Autowired
|
||||||
|
private StateRepository stateRepository;
|
||||||
|
|
||||||
|
public State createState(State state) {
|
||||||
|
return stateRepository.save(state);
|
||||||
|
}
|
||||||
|
}
|
21
src/main/java/com/example/backend/service/UserService.java
Normal file
21
src/main/java/com/example/backend/service/UserService.java
Normal file
@ -0,0 +1,21 @@
|
|||||||
|
package com.example.backend.service;
|
||||||
|
|
||||||
|
import com.example.backend.entity.User;
|
||||||
|
import com.example.backend.repository.UserRepository;
|
||||||
|
import org.springframework.stereotype.Service;
|
||||||
|
import org.springframework.beans.factory.annotation.Autowired;
|
||||||
|
|
||||||
|
@Service
|
||||||
|
public class UserService {
|
||||||
|
|
||||||
|
@Autowired
|
||||||
|
private UserRepository userRepository;
|
||||||
|
|
||||||
|
public User createUser(User user) {
|
||||||
|
return userRepository.save(user);
|
||||||
|
}
|
||||||
|
|
||||||
|
public User findByUsername(String username) {
|
||||||
|
return userRepository.findByUsername(username);
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user