-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
23 changed files
with
483 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
18 changes: 18 additions & 0 deletions
18
src/main/java/com/galendar/domain/contest/dto/response/ContestDeadlineResponse.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package com.galendar.domain.contest.dto.response; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Getter; | ||
import lombok.Setter; | ||
|
||
import java.time.LocalDate; | ||
|
||
@AllArgsConstructor | ||
@Getter | ||
@Setter | ||
public class ContestDeadlineResponse { | ||
private Long id; | ||
private String title; | ||
private String email; | ||
private LocalDate submitStartDate; | ||
private LocalDate submitEndDate; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
5 changes: 4 additions & 1 deletion
5
src/main/java/com/galendar/domain/contest/repository/querydsl/ContestQueryRepository.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,14 +1,17 @@ | ||
package com.galendar.domain.contest.repository.querydsl; | ||
|
||
import com.galendar.domain.contest.dto.request.ContestRequest; | ||
import com.galendar.domain.contest.dto.response.ContestDeadlineResponse; | ||
import com.galendar.domain.contest.dto.response.ContestDetailResponse; | ||
import com.galendar.domain.contest.dto.response.ContestResponse; | ||
|
||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
public interface ContestQueryRepository { | ||
List<ContestResponse> findWithBookmark(ContestRequest request, Long userId); | ||
|
||
List<ContestResponse> findWithBookmark(ContestRequest request, Long userId); | ||
Optional<ContestDetailResponse> findByIdWithBookmark(Long id, Long userId); | ||
List<ContestDeadlineResponse> findContestsBySubmitEndDates(List deadlineDates); | ||
|
||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.galendar.global.config; | ||
|
||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.data.redis.connection.RedisConnectionFactory; | ||
import org.springframework.data.redis.connection.lettuce.LettuceConnectionFactory; | ||
import org.springframework.data.redis.core.RedisTemplate; | ||
import org.springframework.data.redis.serializer.StringRedisSerializer; | ||
|
||
@Configuration | ||
public class RedisConfig { | ||
|
||
@Value("${spring.data.redis.host}") | ||
private String host; | ||
@Value("${spring.data.redis.port}") | ||
private int port; | ||
|
||
@Bean | ||
public RedisConnectionFactory redisConnectionFactory() { | ||
return new LettuceConnectionFactory(host, port); | ||
} | ||
|
||
@Bean | ||
public RedisTemplate<String, String> redisTemplate(RedisConnectionFactory redisConnectionFactory) { | ||
RedisTemplate<String, String> redisTemplate = new RedisTemplate<>(); | ||
redisTemplate.setConnectionFactory(redisConnectionFactory); | ||
redisTemplate.setKeySerializer(new StringRedisSerializer()); | ||
redisTemplate.setValueSerializer(new StringRedisSerializer()); | ||
return redisTemplate; | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/galendar/global/firebase/config/FcmMessageProperties.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.galendar.global.firebase.config; | ||
|
||
import lombok.Getter; | ||
import lombok.Setter; | ||
import org.springframework.boot.context.properties.ConfigurationProperties; | ||
import org.springframework.stereotype.Component; | ||
|
||
import java.util.HashMap; | ||
import java.util.Map; | ||
|
||
@Component | ||
@ConfigurationProperties(prefix = "firebase") | ||
public class FcmMessageProperties { | ||
private Map<String, MessageTemplate> messages = new HashMap<>(); | ||
|
||
public Map<String, MessageTemplate> getMessages() { | ||
return messages; | ||
} | ||
|
||
public void setMessages(Map<String, MessageTemplate> templates) { | ||
this.messages = templates; | ||
} | ||
|
||
@Getter | ||
@Setter | ||
public static class MessageTemplate { | ||
private String title; | ||
private String body; | ||
} | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/main/java/com/galendar/global/firebase/config/FirebaseConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.galendar.global.firebase.config; | ||
|
||
import com.google.auth.oauth2.GoogleCredentials; | ||
import com.google.firebase.FirebaseApp; | ||
import com.google.firebase.FirebaseOptions; | ||
import com.google.firebase.messaging.FirebaseMessaging; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.annotation.Bean; | ||
import org.springframework.context.annotation.Configuration; | ||
import org.springframework.core.io.ClassPathResource; | ||
import org.springframework.core.io.Resource; | ||
|
||
import javax.annotation.PostConstruct; | ||
import java.io.IOException; | ||
import java.io.InputStream; | ||
|
||
@Configuration | ||
public class FirebaseConfig { | ||
@Value("${firebase.sdk.path}") | ||
private String firebaseSdkPath; | ||
|
||
private FirebaseApp firebaseApp; | ||
|
||
@PostConstruct | ||
public FirebaseApp initialize() throws IOException { | ||
Resource resource = new ClassPathResource(firebaseSdkPath); | ||
try (InputStream serviceAccount = resource.getInputStream()) { | ||
FirebaseOptions options = new FirebaseOptions.Builder() | ||
.setCredentials(GoogleCredentials.fromStream(serviceAccount)) | ||
.build(); | ||
if (FirebaseApp.getApps().isEmpty()) { | ||
firebaseApp = FirebaseApp.initializeApp(options); | ||
} | ||
} | ||
return firebaseApp; | ||
} | ||
|
||
@Bean | ||
public FirebaseMessaging firebaseMessaging() { | ||
return FirebaseMessaging.getInstance(firebaseApp); | ||
} | ||
|
||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/galendar/global/firebase/dto/FcmMessage.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.galendar.global.firebase.dto; | ||
|
||
import lombok.AllArgsConstructor; | ||
import lombok.Builder; | ||
import lombok.Getter; | ||
|
||
@Builder | ||
@AllArgsConstructor | ||
@Getter | ||
public class FcmMessage { | ||
private boolean validateOnly; | ||
private Message message; | ||
|
||
@Builder | ||
@AllArgsConstructor | ||
@Getter | ||
public static class Message { | ||
private Notification notification; | ||
private String token; | ||
} | ||
|
||
@Builder | ||
@AllArgsConstructor | ||
@Getter | ||
public static class Notification { | ||
private String title; | ||
private String body; | ||
private String image; | ||
} | ||
|
||
} |
33 changes: 33 additions & 0 deletions
33
src/main/java/com/galendar/global/firebase/service/FcmMessageService.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package com.galendar.global.firebase.service; | ||
|
||
import com.galendar.global.firebase.config.FcmMessageProperties; | ||
import lombok.RequiredArgsConstructor; | ||
import org.springframework.stereotype.Service; | ||
|
||
import java.util.Map; | ||
|
||
@Service | ||
@RequiredArgsConstructor | ||
public class FcmMessageService { | ||
|
||
private final FcmMessageProperties fcmMessageProperties; | ||
|
||
public String getTitle(String type, Map<String, String> variables) { | ||
String template = fcmMessageProperties.getMessages().get(type).getTitle(); | ||
return replaceVariables(template, variables); | ||
} | ||
|
||
public String getBody(String type, Map<String, String> variables) { | ||
String template = fcmMessageProperties.getMessages().get(type).getBody(); | ||
return replaceVariables(template, variables); | ||
} | ||
|
||
private String replaceVariables(String template, Map<String, String> variables) { | ||
for (Map.Entry<String, String> entry : variables.entrySet()) { | ||
String placeholder = "${" + entry.getKey() + "}"; | ||
template = template.replace(placeholder, entry.getValue()); | ||
} | ||
return template; | ||
} | ||
|
||
} |
Oops, something went wrong.