public HabitResponse Find(Guid userId, Guid id) { string query = "select * from habits where user_id = @user_id AND id = @id"; HabitResponse data; using (var cmd = new NpgsqlCommand(query, _connection, _transaction)) { cmd.Parameters.AddWithValue("user_id", userId); cmd.Parameters.AddWithValue("id", id); using NpgsqlDataReader reader = cmd.ExecuteReader(); if (!reader.Read()) { return(null); } data = new HabitResponse( new Habit.Habit( reader.GetGuid(0), reader.GetString(1), (String[])reader.GetValue(2), reader.GetInt16(3), reader.GetInt16(4), reader.GetInt16(5), (DateTime[])reader.GetValue(6), reader.GetGuid(7), reader.GetDateTime(8) ) ); } return(data); }
public List <HabitResponse> GetHabitByUserId(Guid userID) { List <Habit> habitList = habitRepository.GetHabitByUserId(userID); List <HabitResponse> habitResponseList = new List <HabitResponse>(); foreach (Habit habit in habitList) { HabitResponse habitResponse = ConvertFromHabitToHabitResponse(habit); habitResponseList.Add(habitResponse); } return(habitResponseList); }
private HabitResponse ConvertFromHabitToHabitResponseByRemovingDayOff(Habit habit, List <String> dayOffList) { HabitResponse logs = GetRequiredDataFromLogs(habit.ID); return(new HabitResponse() { ID = habit.ID, Name = habit.Name, DayOffList = dayOffList, CurrentStreak = logs.CurrentStreak, LongestStreak = logs.LongestStreak, LogCount = logs.LogCount, Logs = logs.Logs, UserID = habit.UserID, CreatedAt = habit.CreatedAt }); }
private HabitResponse ConvertFromHabitToHabitResponse(Habit habit) { HabitResponse logs = GetRequiredDataFromLogs(habit.ID); List <String> list = dayOffRepository.GetDayOffByHabitId(habit.ID); return(new HabitResponse() { ID = habit.ID, Name = habit.Name, DayOffList = list, CurrentStreak = logs.CurrentStreak, LongestStreak = logs.LongestStreak, LogCount = logs.LogCount, Logs = logs.Logs, UserID = habit.UserID, CreatedAt = habit.CreatedAt }); }
public static void Notify(HabitResponse response) { Dominating dominating = new Dominating(repository); EpicComeback epicComeback = new EpicComeback(repository); Workaholic workaholic = new Workaholic(repository); LoggerPublisher publisher = new LoggerPublisher(); publisher.Attach(dominating); publisher.Attach(epicComeback); publisher.Attach(workaholic); publisher.NotifyAll(response); publisher.Detach(dominating); publisher.Detach(epicComeback); publisher.Detach(workaholic); }