Skip to content

Commit

Permalink
feat: 스팟 업로드하기
Browse files Browse the repository at this point in the history
  • Loading branch information
do-dop committed Jul 4, 2024
1 parent 8a9c7bc commit 82cd22c
Show file tree
Hide file tree
Showing 3 changed files with 40 additions and 12 deletions.
8 changes: 4 additions & 4 deletions src/main/java/com/umc/hackaton/snapspot/spot/entity/Spot.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@ public class Spot extends BaseEntity {
@Column(name = "img_url", nullable = false)
private String imgUrl;

@Column(name = "like_num", nullable = false)
private Long likeNum;
@Column(name = "like_num")
private Long likeNum = 0L;

@Column(name = "visit_num", nullable = false)
private Long visitNum;
@Column(name = "visit_num")
private Long visitNum =0L;

@Column(name = "title", nullable = false)
private String title;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
import java.util.Optional;

public interface UserRepository extends JpaRepository<User, Long> {
Optional<User> findByUserId(String userId);
Optional<User> findByUsername(String username);

User findUserById(Long id);
}
Original file line number Diff line number Diff line change
@@ -1,30 +1,58 @@
package com.umc.hackaton.snapspot.user.service;

import com.umc.hackaton.snapspot.user.dto.UserRequestDto;
import com.umc.hackaton.snapspot.user.dto.request.ImageUploadDto;
import com.umc.hackaton.snapspot.user.dto.request.LoginDto;
import com.umc.hackaton.snapspot.user.dto.request.UserRequestDto;
import com.umc.hackaton.snapspot.user.dto.response.UserResponseDto;
import com.umc.hackaton.snapspot.user.entity.User;
import com.umc.hackaton.snapspot.user.repository.UserRepository;
import jakarta.transaction.Transactional;
import lombok.RequiredArgsConstructor;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;
import lombok.extern.slf4j.Slf4j;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.stereotype.Service;

import java.util.Optional;

@Service
@RequiredArgsConstructor
@Slf4j
public class UserService {

private final UserRepository userRepository;
private final PasswordEncoder encoder;

@Transactional
public void signUp(UserRequestDto dto) {

// Optional<User> existingUser = userRepository.findByUserId(dto.getUserId());
// if (existingUser.isPresent()) {
// User user = existingUser.get();
// } else {
User user = dto.toEntity(encoder);
userRepository.save(user);
}

@Transactional
public UserResponseDto login(LoginDto dto) {
Optional<User> loginuser = userRepository.findByUsername(dto.getUsername());
if (loginuser.isEmpty()) {
throw new IllegalArgumentException("존재하지 않는 사용자입니다.");
}

if (!encoder.matches(dto.getPassword(), loginuser.get().getPassword())) {
throw new IllegalArgumentException("비밀번호가 일치하지 않습니다.");
}

return UserResponseDto.builder()
.id(loginuser.get().getId())
.username(loginuser.get().getUsername())
.build();
}

@Transactional
public void imageUploads(ImageUploadDto dto) {
Optional<User> user = userRepository.findById(dto.getId());
if (user.isEmpty()) {
throw new IllegalArgumentException("존재하지 않는 사용자입니다.");
}
user.get().updateProfileImg(dto.getImage());

}
}

0 comments on commit 82cd22c

Please sign in to comment.